summaryrefslogtreecommitdiff
path: root/public/app/controllers/Auth.php
diff options
context:
space:
mode:
authorGeorge Halkiadakis <gchalkiadakis@sklavenitis.co.gr>2023-06-06 00:46:19 +0300
committerGeorge Halkiadakis <gchalkiadakis@sklavenitis.co.gr>2023-06-06 00:46:19 +0300
commit1388a64651f1c61a6aafc32f8e3e60f7a6ffd339 (patch)
treedd5bcd7b438929ffec89d32011144831eebabb06 /public/app/controllers/Auth.php
parentd5475ce60729c3f743a6451b42072f1a13ffed59 (diff)
downloadgyraf1gov-1388a64651f1c61a6aafc32f8e3e60f7a6ffd339.tar.gz
gyraf1gov-1388a64651f1c61a6aafc32f8e3e60f7a6ffd339.tar.bz2
gyraf1gov-1388a64651f1c61a6aafc32f8e3e60f7a6ffd339.zip
admin petition ready
Diffstat (limited to 'public/app/controllers/Auth.php')
-rw-r--r--public/app/controllers/Auth.php77
1 files changed, 74 insertions, 3 deletions
diff --git a/public/app/controllers/Auth.php b/public/app/controllers/Auth.php
index 02a059f..f356dfe 100644
--- a/public/app/controllers/Auth.php
+++ b/public/app/controllers/Auth.php
@@ -23,7 +23,7 @@ class Auth {
## handle user's record / token / session
## -------------------------------------------------------------------------
- /** user from record
+ /** User from Record
*
* create and return a user based on the record of properties
*
@@ -94,7 +94,12 @@ class Auth {
/** update session token
+ * ... for user by user-id
*
+ * This method perfomes
+ * a new READ User's data from DataBase
+ *
+ * @param int $uid: user-id
*/
private static function reset_user_token($uid)
{
@@ -178,10 +183,9 @@ class Auth {
}
-
/** AJAX POST: update_user
*
- * resolves call POST:/user/update_properties;
+ * resolves call POST:/user/update/properties;
* updates user's proiperties with POSTed data
*
* @param void : all parametres passed via request->POST
@@ -209,6 +213,46 @@ class Auth {
}
+ /** AJAX POST: update_password
+ *
+ * resolves call POST:/user/update/password;
+ * updates user's proiperties with POSTed data
+ *
+ * @param void : all parametres passed via request->POST
+ */
+ public static function update_password()
+ {
+ $req = Registry::get('REQUEST');
+ $manager = new App_manager();
+ $user = $manager->getUserToken()->getUser();
+
+ $record = Access_model::checkUser($user->get('email'));
+
+ // confirm old-password
+ if ($manager->isPasswordValid($user, $req->POST['oldpass'])) {
+
+ $check = Access_model::update_password( // then update pass
+ $user->getID(),
+ $manager->cryptPassword($req->POST['password'])
+ );
+
+ // user properties changed, so update user's session token
+ self::reset_user_token($user->getID());
+
+ Render::json([
+ 'title' => ACCOUNT_UPDATED_TITLE,
+ 'message' => ACCOUNT_UPDATED_MESSAGE . ' (msg code: '. $check .')'
+ ]);
+
+ } else {
+ Render::json([
+ 'title' => 'Error',
+ 'message' => 'Λάθος Password<br>(msg code: 2)<br><br>'. RETRY_SET_PASSWORD
+ ]);
+ }
+ }
+
+
## serve user management forms
## -------------------------------------------------------------------------
@@ -311,6 +355,33 @@ class Auth {
}
+ /** SERVE FORM: password_form
+ *
+ * renders a form for user to change password
+ *
+ * NOTE:
+ * after form is submited, client shall call Auth::update_user()
+ *
+ */
+ public static function password_form()
+ {
+ $user = json_decode(json_encode(self::user_data(), JSON_UNESCAPED_UNICODE));
+
+ // format form_setup to a json array
+ $form_setup = json_decode(json_encode(SET_PASSWORD_FORM, JSON_UNESCAPED_UNICODE));
+
+ // get Form's HTML and Jsvascript
+ $form = JsonToForm::json_form($form_setup, [
+ // pass invitation identity for security
+ ['name' => 'id', 'value' => $user->id]
+ ]); // print_r($form_setup); die();
+
+ Render::view('user/update_password', [
+ 'form' => $form
+ ]);
+ }
+
+
## suplamentary methods
## -------------------------------------------------------------------------