From 635c40d718788738f8ea802a33b1c4494571c2b2 Mon Sep 17 00:00:00 2001 From: Banana Date: Thu, 7 Jan 2021 11:42:23 +0100 Subject: [PATCH] user profile for edit user settings. Not mutch yet --- webclient/lib/doomguy.class.php | 17 ++++++- webclient/lib/possessed.class.php | 7 +-- .../view/default/manageusers/manageusers.html | 2 +- webclient/view/default/profile/profile.html | 51 +++++++++++++++++++ webclient/view/default/profile/profile.php | 47 +++++++++++++++++ 5 files changed, 117 insertions(+), 7 deletions(-) create mode 100644 webclient/view/default/profile/profile.html create mode 100644 webclient/view/default/profile/profile.php diff --git a/webclient/lib/doomguy.class.php b/webclient/lib/doomguy.class.php index 3f8b98e..bc55e03 100644 --- a/webclient/lib/doomguy.class.php +++ b/webclient/lib/doomguy.class.php @@ -111,6 +111,15 @@ class Doomguy { return $ret; } + /** + * Get the currently loaded user data info from $this->userData + * + * @return array|bool + */ + public function getAllUserData() { + return $this->userData; + } + /** * return the isSignedIn status. * @@ -409,7 +418,8 @@ class Doomguy { */ protected function _loadUser() { if(!empty($this->userID)) { - $queryStr = "SELECT u.`id`, u.`baseGroupId`,u.`protected`,u.`password`,u.`login`, + $queryStr = "SELECT u.`id`, u.`baseGroupId`,u.`protected`,u.`password`,u.`login`,u.`name`, + u.`apiToken`,u.`apiTokenValidDate`, g.name AS groupName, g.description AS groupDescription, g.id AS groupId FROM `".DB_PREFIX."_user` AS u LEFT JOIN `".DB_PREFIX."_user2group` AS u2g ON u2g.fk_user_id = u.id @@ -426,6 +436,9 @@ class Doomguy { $this->userData['protected'] = $result['protected']; $this->userData['password'] = $result['password']; $this->userData['login'] = $result['login']; + $this->userData['name'] = $result['name']; + $this->userData['apiToken'] = $result['apiToken']; + $this->userData['apiTokenValidDate'] = $result['apiTokenValidDate']; $this->userData['groups'][$result['groupId']] = array( 'groupName' => $result['groupName'], @@ -433,6 +446,8 @@ class Doomguy { ); } + $this->userData['baseGroupName'] = $this->userData['groups'][$this->userData['baseGroupId']]['groupName']; + $this->userData['isRoot'] = false; $grIds = array_keys($this->userData['groups']); if(in_array(ADMIN_GROUP_ID,$grIds)) { diff --git a/webclient/lib/possessed.class.php b/webclient/lib/possessed.class.php index a3b1dea..6af1e9b 100644 --- a/webclient/lib/possessed.class.php +++ b/webclient/lib/possessed.class.php @@ -187,16 +187,13 @@ class Possessed { $active = "0"; } - $_password = password_hash($password, PASSWORD_DEFAULT); - - - $queryStr = "UPDATE `".DB_PREFIX . "_user` SET `name` = '".$this->_DB->real_escape_string($username)."', `login` = '".$this->_DB->real_escape_string($login)."', `active` = '".$this->_DB->real_escape_string($active)."', `baseGroupId` = '".$this->_DB->real_escape_string($group)."'"; - if(Summoner::validate($password,'text')) { + if(Summoner::validate($password)) { + $_password = password_hash($password, PASSWORD_DEFAULT); $queryStr .= ", `password` = '".$this->_DB->real_escape_string($_password)."'"; } if($refreshApiToken === true) { diff --git a/webclient/view/default/manageusers/manageusers.html b/webclient/view/default/manageusers/manageusers.html index fd7e98b..0e4315e 100644 --- a/webclient/view/default/manageusers/manageusers.html +++ b/webclient/view/default/manageusers/manageusers.html @@ -37,7 +37,7 @@
- +
+
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+
Create API Token
+
+ +
+
+
+ +
+ + + diff --git a/webclient/view/default/profile/profile.php b/webclient/view/default/profile/profile.php new file mode 100644 index 0000000..f061185 --- /dev/null +++ b/webclient/view/default/profile/profile.php @@ -0,0 +1,47 @@ +getAllUserData(); + +if(!empty($TemplateData['editData'])) { + if(isset($_POST['submitForm'])) { + $fdata = $_POST['fdata']; + if(!empty($fdata)) { + $_username = trim($fdata['username']); + $_password = trim($fdata['password']); + $refreshApi = false; + if(isset($fdata['refreshApiToken'])) { + $refreshApi = true; + } + $do = $Possessed->updateUser($Doomguy->param('id'), $_username, $Doomguy->param('login'), + $_password, $Doomguy->param('baseGroupId'), true, $refreshApi); + if ($do === true) { + $TemplateData['refresh'] = 'index.php?p=profile'; + } else { + $TemplateData['message']['content'] = "Your profile could not be updated."; + $TemplateData['message']['status'] = "error"; + } + } + } +} +else { + $TemplateData['message']['content'] = "Something went wrong. See logs for more details."; + $TemplateData['message']['status'] = "error"; +} -- 2.39.5