]> 91.132.146.200 Git - bibliotheca-php.git/commitdiff
user profile for edit user settings. Not mutch yet
authorBanana <mail@bananas-playground.net>
Thu, 7 Jan 2021 10:42:23 +0000 (11:42 +0100)
committerBanana <mail@bananas-playground.net>
Thu, 7 Jan 2021 10:42:23 +0000 (11:42 +0100)
webclient/lib/doomguy.class.php
webclient/lib/possessed.class.php
webclient/view/default/manageusers/manageusers.html
webclient/view/default/profile/profile.html [new file with mode: 0644]
webclient/view/default/profile/profile.php [new file with mode: 0644]

index 3f8b98e30bd4b6740279f53fdc4e4c4bd15c5606..bc55e03c62bc3d7b70da4470bef5721615f158a3 100644 (file)
@@ -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)) {
index a3b1dea3cedff94e5e98346867b4b9b37e0b5351..6af1e9b4898b5a57ef3dfce0545f7fe1487f538a 100644 (file)
@@ -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) {
index fd7e98b7ba58007ec6fd9510a42c8c17b23b9569..0e4315e27d863b5590955e06d3dc2f1181f1248c 100644 (file)
@@ -37,7 +37,7 @@
                                </div>
                        </div>
                        <div class="uk-margin">
-                               <label class="uk-form-label" for="group">Additional groups</label>
+                               <label class="uk-form-label" for="additionalgroups">Additional groups</label>
                                <div class="uk-form-controls">
                                        <select class="uk-select" id="additionalgroups" name="fdata[additionalgroups]">
                                                <option value="">To be done</option>
diff --git a/webclient/view/default/profile/profile.html b/webclient/view/default/profile/profile.html
new file mode 100644 (file)
index 0000000..f20eb26
--- /dev/null
@@ -0,0 +1,51 @@
+<h3 class="uk-h3">Manage your profile</h3>
+<div class="uk-grid-small uk-grid-row-small uk-grid-row-small" uk-grid>
+       <div class="uk-width-1-2">
+               <form class="uk-form-horizontal uk-margin-small" method="post">
+                       <div class="uk-margin">
+                               <label class="uk-form-label" for="username">Username</label>
+                               <div class="uk-form-controls">
+                                       <input class="uk-input" id="username" type="text" autocomplete="off" name="fdata[username]"
+                                              value="<?php echo Summoner::ifset($TemplateData['editData'], 'name'); ?>">
+                               </div>
+                       </div>
+                       <div class="uk-margin">
+                               <label class="uk-form-label" for="password">Password</label>
+                               <div class="uk-form-controls">
+                                       <input class="uk-input" id="password" type="password" autocomplete="off" name="fdata[password]">
+                               </div>
+                       </div>
+                       <div class="uk-margin">
+                               <label class="uk-form-label" for="group">Main group</label>
+                               <div class="uk-form-controls">
+                                       <input class="uk-input" id="group" type="text" name="fdata[group]" disabled
+                                              value="<?php echo Summoner::ifset($TemplateData['editData'], 'baseGroupName'); ?>"
+                                       >
+                               </div>
+                       </div>
+                       <div class="uk-margin">
+                               <label class="uk-form-label" for="additionalGroups">Additional groups</label>
+                               <div class="uk-form-controls">
+                                       <input class="uk-input" id="additionalGroups" type="text" name="fdata[additionalGroups]" disabled
+                                              value="To be done"
+                                       >
+                               </div>
+                       </div>
+                       <div class="uk-margin">
+                               <div class="uk-form-label">Create API Token</div>
+                               <div class="uk-form-controls uk-form-controls-text">
+                                       <label>
+                                               <input class="uk-checkbox" type="checkbox" name="fdata[refreshApiToken]" value="1"><br />
+                                               Valid until: <?php echo Summoner::ifset($TemplateData['editData'], 'apiTokenValidDate'); ?><br />
+                                               Key: <?php echo Summoner::ifset($TemplateData['editData'], 'apiToken'); ?>
+                                       </label>
+                               </div>
+                       </div>
+                       <div class="uk-margin">
+                               <button class="uk-button uk-button-primary" type="submit" name="submitForm">
+                                       Save
+                               </button>
+                       </div>
+               </form>
+       </div>
+</div>
diff --git a/webclient/view/default/profile/profile.php b/webclient/view/default/profile/profile.php
new file mode 100644 (file)
index 0000000..f061185
--- /dev/null
@@ -0,0 +1,47 @@
+<?php
+/**
+ * Bibliotheca
+ *
+ * Copyright 2018-2021 Johannes Keßler
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+require_once 'lib/possessed.class.php';
+$Possessed = new Possessed($DB);
+
+$TemplateData['editData'] = $Doomguy->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";
+}