示例#1
1
 public static function destroy($id)
 {
     $currentUser = Sentry::getUser();
     if (Auth::check() && $id == $currentUser->id) {
         throw new Exception("You can not delete yourself");
     }
     try {
         $user = Sentry::getUserProvider()->findById($id);
         $user->delete();
     } catch (UserNotFoundException $e) {
         throw new Exception("User was not found.");
     }
 }
 public function getDeactivate($id)
 {
     try {
         // Find the user using the user id
         $user = Sentry::getUserProvider()->findById($id);
         // Activate the user
         $user->activated = false;
         $user->save();
     } catch (Cartalyst\Sentry\Users\UserNotFoundException $e) {
         return 'User was not found.';
     }
     return Redirect::to('admin/users');
 }
示例#3
1
 /**
  * Remove the specified resource from storage.
  *
  * @param  int      $id
  * @return Response
  */
 public function destroy($id)
 {
     // TODO: cant delete the last superadmin only super admins can delete
     try {
         $user = Sentry::getUserProvider()->findById($id);
         // Only super users and can delete other super users
         if ($user->isSuperUser() && !Sentry::getUser()->isSuperUser()) {
             throw new Exception('You are not authorized to delete this user.');
         }
         $this->user->destroy($id);
     } catch (Exception $e) {
         Session::flash('error', $e->getMessage());
         return Redirect::to('admin/users');
     }
     $msg = View::make('admin.partials.flash_item_deleted', array('restore' => URL::action('Admin\\UserController@postRestore', $id), 'msg' => 'User deleted.'))->__toString();
     Session::flash('success', $msg);
     return Redirect::to('admin/users');
 }
示例#4
0
 public function retrieve($id)
 {
     try {
         return Sentry::getUserProvider()->findById($id);
     } catch (Cartalyst\Sentry\Users\UserNotFoundException $e) {
     }
     return false;
 }
示例#5
0
 /**
  * Log the given user ID into the application.
  *
  * @param  mixed  $id
  * @param  bool   $remember
  * @return \Illuminate\Auth\UserInterface
  */
 public function loginUsingId($id, $remember = false)
 {
     try {
         // Find the user using the user id
         $user = Sentry::getUserProvider()->findById($id);
         // Log the user in
         Sentry::login($user, $remember);
     } catch (Cartalyst\Sentry\Users\LoginRequiredException $e) {
     } catch (Cartalyst\Sentry\Users\UserNotActivatedException $e) {
     } catch (Cartalyst\Sentry\Users\UserNotFoundException $e) {
     }
     return false;
 }
示例#6
0
 public function run()
 {
     DB::table('users')->delete();
     DB::table('groups')->delete();
     DB::table('users_groups')->delete();
     Sentry::getUserProvider()->create(array('email' => '*****@*****.**', 'password' => "admin", 'first_name' => 'System', 'last_name' => 'Admin', 'activated' => 1));
     Sentry::getGroupProvider()->create(array('name' => 'Admin', 'permissions' => array('admin' => 1)));
     Sentry::getGroupProvider()->create(array('name' => 'User', 'permissions' => array('user' => 1)));
     // Assign user permissions
     $adminUser = Sentry::getUserProvider()->findByLogin('*****@*****.**');
     $adminGroup = Sentry::getGroupProvider()->findByName('Admin');
     $adminUser->addGroup($adminGroup);
 }
示例#7
-1
 /**
  * Handle fetch user list.
  *
  * @return Response
  */
 public function all()
 {
     $offset = (int) Input::get('offset');
     $limit = (int) Input::get('limit');
     if ($offset == 1) {
         $offset = 0;
     }
     // Query the data
     $userModel = Sentry::getUserProvider()->createModel();
     $query = $userModel->newQuery();
     $total = $query->count();
     if (!empty($offset)) {
         $query = $query->skip($offset);
     }
     if (!empty($limit)) {
         $query = $query->take($limit);
     }
     $result = $query->get();
     unset($userModel);
     unset($query);
     // Collect the result
     $response = array();
     if ($result->count() > 0) {
         foreach ($result as $item) {
             $response[] = new UserTemplate($item);
         }
     }
     // Build pagination header
     $pagination = $this->buildPagination($total, $offset, $limit);
     $headers = array();
     if (!empty($pagination)) {
         $headers = array('Link' => $pagination);
     }
     unset($pagination);
     unset($result);
     return API::collectionJson($response, 200, $headers);
 }