Ejemplo n.º 1
0
 /**
  * Promote user to root if no root in user table
  * `li3 usermanager root <username>`
  */
 protected function _root()
 {
     $root = Users::first(array('conditions' => array('UserGroups.slug' => 'root'), 'with' => 'UserGroups'));
     if ($root) {
         $output = array(array('ID', 'Username'), array('---', '----------'), array($root->id, $root->username));
         $this->error('Root user already exists!');
         $this->columns($output);
         return false;
     }
     $username = $this->request->args[0];
     $user = Users::first(array('conditions' => compact('username')));
     if (!$user) {
         $this->error("There is not user with username: {$username}");
     }
     $root = UserGroups::first(array('conditions' => array('slug' => 'root')));
     $user->user_group_id = $root->id;
     $user->save();
     return true;
 }
Ejemplo n.º 2
0
 /**
  * Request password reset
  */
 public function requestResetPassword()
 {
     $this->_rejectLogged();
     $emailSent = false;
     $message = null;
     if ($this->request->data) {
         $requestPasswordReset = Users::requestPasswordReset($this->request->data);
         if ($requestPasswordReset === PasswordResets::RESET_TOKEN_EXISTS) {
             $message = 'You already have reset token in your email inbox!';
         }
         if ($requestPasswordReset === PasswordResets::GENERATED_NEW_RESET_TOKEN) {
             $message = 'Check your email inbox for reset token.';
         }
         $emailSent = Mailer::send();
     }
     return compact('emailSent', 'message');
 }
 /**
  * Destroy user with all related data if not in `root` group
  */
 public function backend_destroy()
 {
     $destroyed = false;
     $user = null;
     if ($id = $this->request->params['id']) {
         $user = Users::first(array('conditions' => array('Users.id' => $id), 'with' => array('AboutUsers', 'PasswordResets', 'UserActivations')));
         if ($user) {
             if ($user->about_user->user_id) {
                 $user->about_user->delete();
             }
             if ($user->user_activation->user_id) {
                 $user->user_activation->delete();
             }
             foreach ($user->password_resets as $password_reset) {
                 if ($password_reset->user_id) {
                     $password_reset->delete();
                 }
             }
             $destroyed = $user->delete();
         }
     }
     return compact('destroyed', 'user');
 }