Example #1
0
 public function action_unlock()
 {
     if (!\Access::can('unlock_any_user', $this->user)) {
         //user must either be editing their own account, or have special privileges to edit someone else's
         \Response::redirect('/welcome/404');
     }
     $post = \Input::post();
     if (empty($post) || empty($post['user_id'])) {
         //user_id of user to unlock must be posted
         \Response::redirect('/welcome/404');
     }
     $user_id = $post['user_id'];
     try {
         //load the user, assign the new roles and save
         $user = $user_id == $this->user->id ? $this->user : \Warden\Model_User::find($user_id);
         if (!$user->is_access_locked()) {
             throw new Exception('User is not locked.');
         }
         $user->unlock_access(true);
         Session::set_flash('success', 'User is unlocked.');
     } catch (\MongoOrm\ValidationFailed $ex) {
         Session::set_flash('error', $ex->getMessage());
     } catch (Exception $ex) {
         $msg = $ex->getMessage();
         Session::set_flash('error', $msg ? $msg : 'Oops, something went wrong.');
     }
     \Response::redirect('/member/view/' . $user_id);
 }
Example #2
0
 public static function unassign_role($role_id, $user = null)
 {
     if (empty($user)) {
         $user = \Warden::current_user();
     } else {
         if (!is_object($user)) {
             $user = \Warden\Model_User::find($user);
         }
     }
     if (!$user || !is_object($user)) {
         throw new \Exception("Cannot assign role to a user that doesn't exist");
     }
     try {
         if (isset($user->roles[$role_id])) {
             unset($user->roles[$role_id]);
             $user->save();
         }
     } catch (\Exception $e) {
         throw $e;
     }
 }