diff options
Diffstat (limited to 'html/app/models/admin/User_model.php')
| -rw-r--r-- | html/app/models/admin/User_model.php | 52 |
1 files changed, 35 insertions, 17 deletions
diff --git a/html/app/models/admin/User_model.php b/html/app/models/admin/User_model.php index e4ac2ea..d0def1b 100644 --- a/html/app/models/admin/User_model.php +++ b/html/app/models/admin/User_model.php @@ -119,10 +119,18 @@ class User_model /** create user * + * creates user record; + * assigns privileged (usualy defaults); + * creates activation_code + * + * @param $data (array): Request->POST array + * @param $password (string): secure hashed password + * + * @return $activation_code + * */ - public static function registerUser($data, $privileges = ['ec.1', 'pr.1']) + public static function registerUser($data, $password, $privileges = ['ec.1', 'pr.1']) { - $required_fields = [ 'name', 'surname', @@ -140,33 +148,43 @@ class User_model return [ "success" => false, 'error' => EMPTY_REQUIRED_FIELDS ]; } - // if isOK go on and create user record - $user = [ - 'prefix' => $data['prefix'] ?? '', - 'name' => $data['name'], - 'surname' => $data['surname'], - 'email' => $data['email'], - 'password' => $data['password'], - 'active' => 0 // needs email confirmation - ]; - // insert new user record + // TODO: + // check if email exists + // ... + + // create an activation code + $activation_code = md5($data['email'].time().rand(0, 10000)); + + // if isOK go on and... + // create user record $new_user_id = Registry::use('database')->query( "INSERT INTO user - (`prefix`, `name`, `surname`, email, `password`, user_id) + (`first_name`, `last_name`, `email`, `password`, `active`, `activation`) VALUES - (:prefic, :name, :surname, :email, :password, :userid)" - [ $user ] + (:nam, :surname, :email, :pass, :act, :actcode)", + [ + ':nam' => $data['name'], + ':surname' => $data['surname'], + ':email' => $data['email'], + ':pass' => $password, + ':act' => 0, // needs email confirmation to be activated ... + ':actcode' => $activation_code // ... with the activation code + ] )->lastInsertID(); // set default privileges - self::set_user_privileges($privileges); + // self::set_user_privileges($privileges); // update history History::trackUserAccess($new_user_id, TRACK_ACCOUNT, 'Create User Account'); // return success and user id - return [ "success" => true, 'id' => $new_user_id ]; + return [ + "success" => true, + 'id' => $new_user_id , + 'activation' => $activation_code + ]; } |
