diff options
| author | George Halkiadakis <gchalkiadakis@sklavenitis.co.gr> | 2023-06-06 00:46:19 +0300 |
|---|---|---|
| committer | George Halkiadakis <gchalkiadakis@sklavenitis.co.gr> | 2023-06-06 00:46:19 +0300 |
| commit | 1388a64651f1c61a6aafc32f8e3e60f7a6ffd339 (patch) | |
| tree | dd5bcd7b438929ffec89d32011144831eebabb06 /public/app/controllers | |
| parent | d5475ce60729c3f743a6451b42072f1a13ffed59 (diff) | |
| download | gyraf1gov-1388a64651f1c61a6aafc32f8e3e60f7a6ffd339.tar.gz gyraf1gov-1388a64651f1c61a6aafc32f8e3e60f7a6ffd339.tar.bz2 gyraf1gov-1388a64651f1c61a6aafc32f8e3e60f7a6ffd339.zip | |
admin petition ready
Diffstat (limited to 'public/app/controllers')
| -rw-r--r-- | public/app/controllers/Auth.php | 77 | ||||
| -rw-r--r-- | public/app/controllers/Office.php | 26 |
2 files changed, 99 insertions, 4 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 ## ------------------------------------------------------------------------- diff --git a/public/app/controllers/Office.php b/public/app/controllers/Office.php index f57cf08..c67249a 100644 --- a/public/app/controllers/Office.php +++ b/public/app/controllers/Office.php @@ -327,9 +327,21 @@ class Office { + public static function all_petitions() + { + if (Auth::in_admin_group()) { + Render::json([ + 'success' => true, + 'data' => Content_model::all_petitions() + ]); + } + } + + + public static function petition_copy($sign) { - if (false) { //(Auth::in_admin_group()) { + if (Auth::in_admin_group()) { $petition = Content_model::get_petition(['signature' => $sign]); } else { @@ -407,7 +419,19 @@ class Office { ## ADMIN METHODS (insert, updated etc.) ## ------------------------------------------------------------------------- + /** set_protocol + * --- + */ + public static function set_protocol() + { + if (Auth::in_admin_group()) { + $post = Registry::get('REQUEST')->POST; + Content_model::set_protocol( $post['id'], $post['protocol'] ); + } + Render::json(['success' => true]); + } + /** files * echo all files * |
