Inheritance: extends Illuminate\Support\Facades\Facade
 /**
  * Redirect the user to the authentication page.
  *
  * @return Response
  */
 public function redirectToProvider($provider)
 {
     // Não permitir redirecionamento ao login da rede social caso
     // já tenha sido feito o login
     if (Sentinel::guest() && Auth::guest()) {
         return Socialite::driver($provider)->redirect();
     } else {
         return redirect()->route("home.index");
     }
 }
Exemple #2
4
 /**
  * Store a newly created resource in storage.
  *
  * @param  Request $request
  * @return Response
  */
 public function store(SaveTopicRequest $request)
 {
     $originalContent = trim($request->input('content'));
     $data = array('uid' => Sentinel::getUser()->id, 'title' => trim($request->input('title')), 'original_content' => $originalContent, 'content' => (new Parser())->makeHtml($originalContent), 'active_at' => time());
     $topic = Topic::create($data);
     if ($topic && isset($topic->id)) {
         return $this->response()->item($topic, new TopicTransformer());
     } else {
         throw new StoreResourceFailedException('保存失败,请重新尝试');
     }
 }
 public function logout()
 {
     App::setLocale(Config::get('app.locale'));
     $user = Sentinel::logout();
     Flash::success("You have been logged out from: " . $user->first_name);
     return redirect(action("HomeController@home"));
 }
 public function verify($username, $password)
 {
     $credentials = ['email' => $username, 'password' => $password];
     if ($user = Sentinel::authenticate($credentials)) {
         return $user->id;
     }
     return false;
 }
 /**
  * Handle an incoming request.
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  \Closure  $next
  * @return mixed
  */
 public function handle($request, Closure $next)
 {
     if (!Sentinel::check()) {
         //            dump('未登陆');
         //未登陆,跳转到登陆页面
         return redirect()->route('account_login_get');
     }
     //        dump('已登陆');
     return $next($request);
 }
 /**
  * Handle an incoming request.
  *
  * @param  \Illuminate\Http\Request $request
  * @param  \Closure                 $next
  * @param  array                    $role
  *
  * @return mixed
  */
 public function handle($request, Closure $next, $role)
 {
     if (Sentinel::inRole($role)) {
         if ($request->ajax()) {
             return response('Unauthorized.', 401);
         } else {
             Flash::error('You do not have te right permissions to go there.');
             return redirect()->route('/', Config::get('app.locale'));
         }
     }
     return $next($request);
 }
 /**
  * 返回上次访问页面
  *
  * 无法获取上次访问页面时,已登陆,返回数据首页;未登陆,返回登陆页;
  *
  * @return string
  */
 public function pre_web_page_url()
 {
     if (isset($_SERVER['HTTP_REFERER']) && $_SERVER['HTTP_REFERER'] != null) {
         $pre_url = $_SERVER['HTTP_REFERER'];
         return $pre_url;
     }
     if (Sentinel::check()) {
         $pre_url = route('data_index');
     } else {
         $pre_url = route('account_login_get');
     }
     return $pre_url;
 }
Exemple #8
2
 /**
  * Handle an incoming request.
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  \Closure  $next
  * @return mixed
  */
 public function handle($request, Closure $next)
 {
     if (!Sentinel::check()) {
         return redirect()->action('UserController@getSignin');
     }
     return $next($request);
 }
 /**
  * Display a listing of the resource.
  *
  * @return \Illuminate\Http\Response
  */
 public function index()
 {
     if (!Sentinel::check()) {
         abort(401);
     }
     return View::make('customer.welcome');
 }
 /**
  * 变更角色 - 页面
  *
  * @return \Illuminate\View\View
  */
 public function role_get()
 {
     $account_info = $this->account_info();
     $account_info['page_title'] = '变更角色';
     $account_info['page_description'] = '';
     if (!isset($_GET['user_id']) || $_GET['user_id'] <= 0) {
         //            dump('无法获取用户信息');
         return redirect($this->pre_web_page_url());
     }
     $user = Sentinel::findById($_GET['user_id']);
     if (!$user) {
         //            dump('无法获取用户信息');
         return redirect($this->pre_web_page_url());
     }
     $role = $this->role_by_user($user);
     $roles = Role::get();
     foreach ($roles as $k => $kValue) {
         $roles[$k]['value'] = 0;
         if ($kValue['id'] == $role['id']) {
             $roles[$k]['value'] = 1;
         }
     }
     $account_info['user'] = $user;
     $account_info['roles'] = $roles;
     return view('role.role', $account_info);
 }
 /**
  * @param $request
  * @param Closure $next
  *
  * @return mixed
  */
 public function handle($request, Closure $next)
 {
     if (Sentinel::guest()) {
         throw new AccessDeniedHttpException(trans('auth.errors.invalid_permission'));
     }
     return $next($request);
 }
Exemple #12
2
 /**
  * Handle an incoming request.
  *
  * @param  \Illuminate\Http\Request $request
  * @param  \Closure $next
  * @return mixed
  */
 public function handle($request, Closure $next)
 {
     if (Sentinel::check()) {
         return redirect('/home');
     }
     return $next($request);
 }
 /**
  * Handle an incoming request.
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  \Closure  $next
  * @return mixed
  */
 public function handle($request, Closure $next)
 {
     if (Sentinel::guest() && Auth::guest()) {
         return redirect()->route("auth.getlogin");
     }
     return $next($request);
 }
 /**
  * @param $request
  * @param Closure $next
  * @param $role
  *
  * @return mixed
  */
 public function handle($request, Closure $next, $role)
 {
     $role = Sentinel::findRoleBySlug($role);
     if (!$request->user()->inRole($role)) {
         throw new AccessDeniedHttpException(trans('auth.errors.invalid_permission'));
     }
     return $next($request);
 }
Exemple #15
2
 /**
  * Display a listing of roles.
  *
  * @return \Illuminate\View\View
  */
 public function index()
 {
     $adminRoles = $this->roles->findById(1);
     $managerRoles = $this->roles->findById(2);
     $roles = $this->roles->paginate();
     $user = Sentinel::getUser();
     return view('admin.roles.index', compact('roles', 'user', 'adminRoles', 'managerRoles'));
 }
Exemple #16
2
 public function getLogout()
 {
     if (Sentinel::check()) {
         $this->authRepository->logout();
         Flash::success('Log out successfully!');
         return Redirect::route('getAuth');
     }
     return Redirect::route('getAuth');
 }
 /**
  * Redirects unauthenticated users to the login page.
  *
  * @param Request $request
  * @param Closure $next
  *
  * @return Request|\Illuminate\Http\RedirectResponse
  */
 public function handle(Request $request, Closure $next)
 {
     if (Sentinel::check()) {
         return $next($request);
     } else {
         $message = "You're not logged in.";
         return redirect()->route('maintenance.login')->withErrors($message);
     }
 }
Exemple #18
2
 /**
  * Handle an incoming request.
  *
  * @param \Illuminate\Http\Request $request
  * @param \Closure                 $next
  *
  * @return mixed
  */
 public function handle($request, Closure $next)
 {
     $user = Sentinel::getUser();
     $admin = Sentinel::findRoleByName('Administradores');
     if (!$user->inRole($admin)) {
         return redirect('login');
     }
     return $next($request);
 }
Exemple #19
2
 public function postRegister(Request $request)
 {
     $validator = $this->validator($request->all());
     if ($validator->fails()) {
         $this->throwValidationException($request, $validator);
     }
     Sentinel::login($this->create($request->all()));
     return redirect($this->redirectPath());
 }
Exemple #20
2
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     $trainer = ['first_name' => 'Michael', 'last_name' => 'Favila', 'email' => '*****@*****.**', 'password' => 'password'];
     try {
         $trainerUser = Sentinel::registerAndActivate($trainer);
         $trainerUser->roles()->attach(Sentinel::findRoleBySlug('customer_trainer'));
     } catch (\Exception $e) {
         // nothing to do
     }
 }
 /**
  * 变更角色权限 - 业务逻辑
  *
  * @return \Illuminate\Http\RedirectResponse
  */
 public function permission_post()
 {
     $data = $_POST;
     $permissions = '';
     if (!isset($data['permissions']) || $data['permissions'] == null) {
     } else {
         $permissions = $data['permissions'];
     }
     $role = Sentinel::findRoleById($data['role_id']);
     return $this->role_permission($role, $permissions, 'role_list_get', 'permission_permission_get', $data['role_id']);
 }
Exemple #22
2
 /**
  * Handle an incoming request.
  *
  * @param  \Illuminate\Http\Request $request
  * @param  \Closure $next
  * @return mixed
  */
 public function handle($request, Closure $next)
 {
     if (Sentinel::guest()) {
         if ($request->ajax()) {
             return response('Unauthorized.', 401);
         } else {
             return redirect()->guest('auth/login');
         }
     }
     return $next($request);
 }
Exemple #23
2
 /**
  * Constructor.
  *
  * @return void
  */
 public function __construct()
 {
     $this->beforeFilter('csrf', ['on' => 'post', 'except' => $this->csrfWhitelist]);
     // Set the active theme area
     $this->setActiveThemeArea();
     // Set the fallback theme area
     $this->setFallbackThemeArea();
     $this->alerts = app('alerts');
     $this->currentUser = Sentinel::getUser();
     View::share(['currentUser' => $this->currentUser]);
 }
 /**
  * Throws 403 unauthorized error if the user is
  * not allowed to access the specified route.
  *
  * @param Request $request
  * @param Closure $next
  *
  * @return Request
  *
  * @throws \Symfony\Component\HttpKernel\Exception\HttpException
  * @throws \Symfony\Component\HttpKernel\Exception\NotFoundHttpException
  */
 public function handle(Request $request, Closure $next)
 {
     $user = Sentinel::getUser();
     if ($user && $user instanceof User) {
         if ($user->hasAccess($request->route()->getName())) {
             return $next($request);
         }
     }
     // Return forbidden error.
     abort(403);
 }
 /**
  * Handle an incoming request.
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  \Closure  $next
  * @return mixed
  */
 public function handle(Request $request, Closure $next)
 {
     if (Sentinel::guest()) {
         if ($request->ajax()) {
             return response('Unauthorized.', 401);
         } else {
             return view('auth/login', ['locale' => Config::get("app.locale")]);
         }
     }
     return $next($request);
 }
 /**
  * Redirects users to the main dashboard page if they're
  * already logged in and trying to access a login / register route.
  *
  * @param Request $request
  * @param Closure $next
  *
  * @return Request|\Illuminate\Http\RedirectResponse
  */
 public function handle(Request $request, Closure $next)
 {
     $user = Sentinel::getUser();
     if ($user) {
         $route = 'maintenance.work-requests.index';
         if (!$user->hasAccess($route)) {
             $route = 'maintenance.client.work-requests.index';
         }
         return redirect()->route($route);
     } else {
         return $next($request);
     }
 }
 protected function dashboard()
 {
     // Se Sentinel::guest() = true => usuário entrou com Auth (Autentic. Social)
     // Caso contrário => usuário entrou com Sentinel (Autentic. Local)
     if (Sentinel::guest()) {
         // USUÁRIO AUTENTICANDO COM REDE SOCIAL
         $user = ["name" => Auth::user()->name, "email" => Auth::user()->email];
     } else {
         // USUÁRIO AUTENTICANDO LOCALMENTE
         $user = ["name" => Sentinel::getUser()->first_name, "email" => Sentinel::getUser()->email];
     }
     return view("user.dashboard", ["user" => $user]);
 }
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     Model::unguard();
     // Create an admin user
     $user = Sentinel::create(['email' => '*****@*****.**', 'password' => 'test', 'first_name' => 'Nicolas', 'last_name' => 'Widart']);
     // Activate the admin directly
     $activation = Activation::create($user);
     Activation::complete($user, $activation->code);
     // Find the group using the group id
     $adminGroup = Sentinel::findRoleBySlug('admin');
     // Assign the group to the user
     $adminGroup->users()->attach($user);
 }
Exemple #29
2
 public function login(LoginRequest $request)
 {
     // 验证账号
     $credentials = ['email' => $request->input('email'), 'password' => $request->input('password')];
     $remember = $request->has('remember') ? true : false;
     $user = Sentinel::authenticate($credentials, $remember);
     if (!$user) {
         // 账号或密码错误
         abort(401);
     }
     // 返回 OAuth2 的 access_token
     return $this->getToken($credentials);
 }
Exemple #30
1
 /**
  * Handle an incoming request.
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  \Closure  $next
  * @return mixed
  */
 public function handle($request, Closure $next)
 {
     if (!Sentinel::check() && !Sentinel::hasAccess('admin')) {
         return Redirect::to('login')->withErrors(['Only admins can access this page.']);
     }
     return $next($request);
 }