/** * 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; }
/** * Change password * @requestLogin */ public function changePassword() { $this->_rejectNotLogged(); $user = $this->_user; unset($user['user_group']); $user = Users::first(array('conditions' => $user)); if ($this->request->data) { if ($user->save(array('old_password' => $this->request->data['old_password'], 'password' => $this->request->data['password'], 'confirm_password' => $this->request->data['confirm_password']), array('events' => 'change_password'))) { return $this->redirect('li3_usermanager.Users::index'); } } return compact('user'); }
/** * 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'); }