diff options
| author | George Halkiadakis <gchalkiadakis@sklavenitis.co.gr> | 2023-03-28 03:38:35 +0300 |
|---|---|---|
| committer | George Halkiadakis <gchalkiadakis@sklavenitis.co.gr> | 2023-03-28 03:38:35 +0300 |
| commit | 5ce005a4f120c7470cd84c1af306b64c52e3dbfc (patch) | |
| tree | f93fa229273aad02501d3ecb326091bb2f7d31aa /html/app | |
| parent | fa7303bc99ed56e6770928d59e16ee3306e26750 (diff) | |
| download | classroom-5ce005a4f120c7470cd84c1af306b64c52e3dbfc.tar.gz classroom-5ce005a4f120c7470cd84c1af306b64c52e3dbfc.tar.bz2 classroom-5ce005a4f120c7470cd84c1af306b64c52e3dbfc.zip | |
custom user manager extended class (work in progress)
Diffstat (limited to 'html/app')
| -rw-r--r-- | html/app/config/app_constants.php | 7 | ||||
| -rw-r--r-- | html/app/controllers/Classroom_user.php | 69 | ||||
| -rw-r--r-- | html/app/extends/Classroom_user.php | 108 | ||||
| -rw-r--r-- | html/app/models/admin/User_model.php | 39 | ||||
| -rw-r--r-- | html/app/views/login.php | 2 |
5 files changed, 145 insertions, 80 deletions
diff --git a/html/app/config/app_constants.php b/html/app/config/app_constants.php index c533748..b5fb6d8 100644 --- a/html/app/config/app_constants.php +++ b/html/app/config/app_constants.php @@ -37,6 +37,13 @@ define('USER_ACCESS_TYPE', [ +// ERRORS AND ERROR MESSAGES /////////////////////////////////////////////////// +// ----------------------------------------------------------------------------- + +define('EMPTY_REQUIRED_FIELDS', 'Δεν έχουν συμπληρωθεί όλα τα υποχρεωτικά πεδία'); + + + // ASSETS: PATHS USED HEAVILY ////////////////////////////////////////////////// // ----------------------------------------------------------------------------- // these paths are used in order to easily find and autoload useful elemets diff --git a/html/app/controllers/Classroom_user.php b/html/app/controllers/Classroom_user.php deleted file mode 100644 index 616ebf6..0000000 --- a/html/app/controllers/Classroom_user.php +++ /dev/null @@ -1,69 +0,0 @@ -<?php -namespace app\controllers; - -use UserManager; -use Registry; -# use app\models\admin\User_model; - - - -/** ClassUserManager - * - * extends (anom's) UserManager - * - * this way it specializes the UserManagement - * according to this app's special rules - * - */ -class Classroom_user extends UserManager -{ - - private $user_identifier = 'email'; // identifing user field (username, email, etc ) - - protected $user; - - public function __construct() - { - // $this->user = new UserManager(); - - } - - - public function register_user() - { - $req = Registry::get('REQUEST'); - print_r($req->POST); die(); - - } - - - public function login_user() - { - - } - - - /** forgot password - * - * send an otp - * (then verify) - * - */ - public function forgot_password() - { - - } - - - /** Verify Account - * - * check if posted OTP matched the one sent to the user - * - */ - public function verify_otp() - { - - } - - -}
\ No newline at end of file diff --git a/html/app/extends/Classroom_user.php b/html/app/extends/Classroom_user.php new file mode 100644 index 0000000..b451114 --- /dev/null +++ b/html/app/extends/Classroom_user.php @@ -0,0 +1,108 @@ +<?php +namespace app\controllers; + +use UserManager; +use Registry; +use app\models\admin\User_model; + + + +/** ClassUserManager + * + * extends (anom's) UserManager + * + * this way it specializes the UserManagement + * according to this app's special rules + * + */ +class Classroom_user extends UserManager +{ + + private $index_key = 'email'; // identifing user field (username, email, etc ) + + protected $user; + + public function __construct() + { + parent::__construct(); + } + + + /** register user + * + * register into database; + * send OTP for account confirmation + * + * @param (void) : user properties passed via REQUEST->POST + * + */ + public function register_user() + { + $req = Registry::get('REQUEST'); + $register = User_model::registerUser($req->POST); + + if ($register['success']) { + + //create OTP; + $otp = $this->create_OPT($register['id']); + + // send for account confirmation + + + } else { + print_r($register); + } + + } + + + public function login_user() + { + + } + + + /** forgot password + * + * send an otp + * (then verify) + * + */ + public function forgot_password() + { + + } + + + /** create OTP + * + * create a random OTP + * keep it into User's database Table + * + * @param $id (int): user id + * + */ + public function create_OTP($id) + { + $otp = rand(100000,999999); + User_model::set_OTP($id, $otp); + + return true; + } + + + /** Verify Account + * + * check if posted OTP matched the one sent to the user + * + * @param $identity (array): pair of [index_key => identity_value] + * example: [ 'email' => 'geo@roptron.gr' ] + * + */ + public function verify_otp($identity, $otp) + { + + } + + +}
\ No newline at end of file diff --git a/html/app/models/admin/User_model.php b/html/app/models/admin/User_model.php index 583d4d9..e4ac2ea 100644 --- a/html/app/models/admin/User_model.php +++ b/html/app/models/admin/User_model.php @@ -13,18 +13,18 @@ class User_model * @param $indexKey (string) : key for user identification * @param $value (string) * - * NOTE: - * $indexKey MUST BE a unique key identilieng the user - * ex. username, email, etc ... - * - * @return $user : [array] or false - * + * @param $identity (array): pair of [index_key => identity_value] + * example: [ 'email' => 'geo@roptron.gr' ] */ - public static function checkUser($indexKey, $value) + public static function checkUser($identity) { + $indexKey = array_key_first($identity); + $user = Registry::use('database')->query( "SELECT * FROM user WHERE {$indexKey} = :val", - [ ':val' => $value ] + [ + ':val' => $identity[$indexKey] + ] )->getFirst(); // if no user, return false @@ -120,10 +120,29 @@ class User_model /** create user * */ - public static function createUser($data, $privileges = ['ec.1', 'pr.1']) + public static function registerUser($data, $privileges = ['ec.1', 'pr.1']) { + + $required_fields = [ + 'name', + 'surname', + 'email', + 'password' + ]; + + // check required fields + $isOK = true; + foreach($required_fields as $fi) { + if (empty($data[$fi])) $isOK = false; + } + // if empty required fields exists ... return false + if (!$isOK) { + return [ "success" => false, 'error' => EMPTY_REQUIRED_FIELDS ]; + } + + // if isOK go on and create user record $user = [ - 'prefix' => $data['prefix'], + 'prefix' => $data['prefix'] ?? '', 'name' => $data['name'], 'surname' => $data['surname'], 'email' => $data['email'], diff --git a/html/app/views/login.php b/html/app/views/login.php index cc4556c..e7f9c3e 100644 --- a/html/app/views/login.php +++ b/html/app/views/login.php @@ -23,7 +23,7 @@ } .container { display: flex; height: 100vh; align-items:center; } .content { position: relative; - max-width:320px; width: 100%; + max-width:640px; width: 100%; margin: auto auto; padding: 1.5em; text-align: center; justify-center: center; opacity: .33; |
