コード例 #1
0
ファイル: UsersController.php プロジェクト: kawsuj/knock
 /**
  * Remove the specified resource from storage.
  *
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function destroy($user_id)
 {
     $user = User::findOrFail($user_id);
     if (!$user == null) {
         try {
             $user->actions()->delete();
             $user->delete();
         } catch (QueryException $e) {
             return redirect('/users/' . $user_id)->with('flash_message', 'user ' . $user->email . ' cannot be deleted because it is being used');
         }
         return redirect('/users')->with('flash_message', 'User ' . $user->email . ' has been removed');
     } else {
         return redirect('/users/' . $user_id)->with('flash_message', 'User was not found');
     }
 }
コード例 #2
0
ファイル: KnockServices.php プロジェクト: kawsuj/knock
 /**
  * 
  * @param String $tag Tag name 
  * @param String $role Role name
  * @param String $tagDesc Tag Description
  * @param String $roleDesc Role description
  * @param String $user_id ID of user to check (authenticated user is checked if not supplied)
  * @return boolean true if user has given permission
  */
 public function hasPermission($tag, $role, $action, $user_id = null)
 {
     if (Auth::guest()) {
         return false;
     }
     if ($tag === null || $role === null || $action === null) {
         return false;
     }
     $user;
     if ($user_id == null) {
         $user = Auth::user();
     } else {
         $user = User::findOrFail($user_id);
     }
     foreach ($user->actions as $userAction) {
         $myActions = Action::findOrFail($userAction->action_id)->peep();
         if ($tag === $myActions['tag'] && $role === $myActions['role'] && $action === $myActions['action']) {
             return true;
         }
     }
     return false;
 }