Exemplo n.º 1
0
 /**
  * Add user in database
  * @return string
  * @throws NativeException
  */
 public function actionAdduser()
 {
     echo "Login:"******"Email:";
     $email = Console::$Input->read();
     if (!Str::isEmail($email)) {
         throw new NativeException('Email is bad');
     }
     echo "Password:"******"RoleId (1 = onlyread, 2 = user, 3 = moderator, 4 = admin):";
     $role = (int) Console::$Input->read();
     if (!Arr::in($role, [1, 2, 3, 4])) {
         $role = 2;
     }
     if (User::isMailExist($email) || User::isLoginExist($login)) {
         throw new NativeException('User with this email or login is always exist');
     }
     $salt = Console::$Properties->get('passwordSalt');
     $user = new User();
     $user->login = $login;
     $user->email = $email;
     $user->password = Security::password_hash($pass, $salt);
     $user->role_id = $role;
     $user->save();
     $profile = new Profile();
     $profile->user_id = $user->id;
     $profile->save();
     return 'User was successful added to database!';
 }