From a584bf73b6d64dad98f150caba0f25e790cde010 Mon Sep 17 00:00:00 2001 From: George Halkiadakis Date: Sun, 9 Apr 2023 04:50:17 +0300 Subject: user registration and login scenarios --- html/app/config/app_constants.php | 20 ++++++++++++++++++-- html/app/controllers/Auth.php | 25 ++++++++++++++++++++----- html/app/extends/Classroom_user.php | 1 + html/app/models/admin/User_model.php | 12 ++++++++++-- html/app/routes/frontend.php | 11 ++++++++++- html/app/views/error/general.php | 18 +++++++++++++++--- html/app/views/user/login.php | 28 ++++++++++++++++++++++++++++ 7 files changed, 102 insertions(+), 13 deletions(-) diff --git a/html/app/config/app_constants.php b/html/app/config/app_constants.php index 5a2c9b3..0d04dc2 100644 --- a/html/app/config/app_constants.php +++ b/html/app/config/app_constants.php @@ -134,17 +134,33 @@ define('FONT_FILES', array( // Mesagges //////////////////////////////////////////////////////////////////// // ----------------------------------------------------------------------------- +// 404 +// --- +define('PAGE_404_TITLE', '404: Not Found'); + +// registration +// --- define('REGISTRATION_SUCCESS', "

Επιτυχής Εγγραφή

Παρακαλώ ελέγξτε το email σας και ακολουθήστε το σύνδεσμο ενεργοποίησης που σας 'εχει αποσταλεί, ώστε να έχετε πρόσβαση σε επιπλέον περιεχόμενο του site

" ); - define ('REGISTRATION_USER_EXISTS', "

Αποτυχία Εγγραφής

Υπάρχει ήδη χρήστης με αυτό το email. Αν δεν θυμάστε το password μπορείτε να κάνετε επαναφορά του ακολουθώντας αυτό το σύνδεσμο.

" -); \ No newline at end of file +); + + +// activation +// --- +define('ACCOUNT_ACTIVATED_TITLE', 'Ο λογαριασμός σας έχει ενεργοποιηθεί'); +define('ACCOUNT_ACTIVATED_MESSAGE', 'Τώρα μπορείτε να κάνετε + Είσοδο στο σύστημα + για να δείτε περισσότερο περιεχόμενο'); +define('NOT_VALID_ACTIVATION_TITLE', 'Σφάλμα!'); +define('NOT_VALID_ACTIVATION_MESSAGE', 'Ο κωδικός ενεργοποίησης δεν είναι σωστός. + Μήπως τον έχετε ενεργοποιήσει στο παρελθόν;'); \ No newline at end of file diff --git a/html/app/controllers/Auth.php b/html/app/controllers/Auth.php index 50f8fe4..6555f1c 100644 --- a/html/app/controllers/Auth.php +++ b/html/app/controllers/Auth.php @@ -2,6 +2,7 @@ namespace app\controllers; use Registry; +use Render; // user classes and models use app\extends\Classroom_user; @@ -56,13 +57,29 @@ class Auth { } - + /** activate + * resolves a call like: /account/activate?ticket=ca42d68cfba5fbbafeacc010b8e3a551 + */ public static function activate() { $req = Registry::get('REQUEST'); // get the record of the target user - $record = User_model::activate($req->GET['ticket']); + $check = User_model::activate($req->GET['ticket']); + + if ($check == true) { + Render::view('/error/general', [ + 'title' => ACCOUNT_ACTIVATED_TITLE, + 'message' => ACCOUNT_ACTIVATED_MESSAGE + ]); + + } else { + Render::view('/error/general', [ + 'title' => NOT_VALID_ACTIVATION_TITLE, + 'message' => NOT_VALID_ACTIVATION_MESSAGE + ]); + } + } /** register @@ -118,9 +135,7 @@ class Auth { 'success' => false, 'message' => 'error on sending email' ]; - } - - + } } diff --git a/html/app/extends/Classroom_user.php b/html/app/extends/Classroom_user.php index fd1e573..c51c79b 100644 --- a/html/app/extends/Classroom_user.php +++ b/html/app/extends/Classroom_user.php @@ -37,6 +37,7 @@ class Classroom_user extends User return $this->privileges; } + /** setPrivileges() * * @param array $privileges diff --git a/html/app/models/admin/User_model.php b/html/app/models/admin/User_model.php index 187da2d..397f198 100644 --- a/html/app/models/admin/User_model.php +++ b/html/app/models/admin/User_model.php @@ -188,6 +188,14 @@ class User_model } + /** activate + * + * check if activation code is valid; + * if valid, set account active; + * + * @param $ticket (hex/MD5): activation code; + * + */ public static function activate($ticket) { $user = Registry::use('database')->query( @@ -201,13 +209,13 @@ class User_model // remove activation code from user record Registry::use('database')->runQuery( "UPDATE user - SET activated = 1, `activation` = NULL + SET active = 1, `activation` = NULL WHERE activation = :ticket", [ 'ticket' => $ticket ] ); // update history - History::trackUserAccess($new_user_id, TRACK_ACCOUNT, 'User Account Activated'); + History::trackUserAccess($user['id'], TRACK_ACCOUNT, 'User Account Activated'); return true; diff --git a/html/app/routes/frontend.php b/html/app/routes/frontend.php index e602e87..ba831d6 100644 --- a/html/app/routes/frontend.php +++ b/html/app/routes/frontend.php @@ -44,13 +44,22 @@ Route::add('/registration', function() { Render::view('user/registration'); }); +Route::add('/account/check-login', function() { Auth::login(); }); // user sends a registration form; -Route::add('/account/register', function() { $x = Auth::register(); print_r($x); }, 'post'); +Route::add('/account/register', function() { Auth::register(); }, 'post'); // user requests activation Route::add('/account/activate', function() { Auth::activate(); } ); +// user profile +Route::add('/account/profile', function() { + // check if user is activated and loged in + // then ... + }, + 'post' +); + Route::add('/account/reset_password', function() { Auth::reset_password(); } ); diff --git a/html/app/views/error/general.php b/html/app/views/error/general.php index 84cc4d9..257e68d 100644 --- a/html/app/views/error/general.php +++ b/html/app/views/error/general.php @@ -1,8 +1,20 @@ - + - 404: Not Found + + <?= isset($title) + ? (SITE_TITLE .": ". $title) + : PAGE_404_TITLE + ?> +