当前位置: 首页>>代码示例>>PHP>>正文


PHP Guard::attempt方法代码示例

本文整理汇总了PHP中Illuminate\Auth\Guard::attempt方法的典型用法代码示例。如果您正苦于以下问题:PHP Guard::attempt方法的具体用法?PHP Guard::attempt怎么用?PHP Guard::attempt使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Illuminate\Auth\Guard的用法示例。


在下文中一共展示了Guard::attempt方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: login

 /**
  *  User should be authorised on cases:
  *      1. username is correct and email is empty
  *      2. email is correct and username is empty
  *      3. username is correct and email is correct
  *
  * Sing in is case sensitive
  *
  * @param Requests\LoginFormRequest $request
  *
  * @return $this
  */
 public function login(Requests\LoginFormRequest $request)
 {
     $data = $request->only('username', 'email', 'password');
     if (empty($data['username'])) {
         unset($data['username']);
     } elseif (empty($data['email'])) {
         unset($data['email']);
     }
     if ($this->auth->attempt($data)) {
         return redirect('chat');
     }
     return redirect('/')->withErrors(['username' => 'Incorrect username, email or password'], $request->getErrorBag());
 }
开发者ID:viktory,项目名称:chat,代码行数:25,代码来源:UsersController.php

示例2: postLogin

 /**
  * 执行登录操作
  * @return $this|\App\Http\Controllers\Controller|\Illuminate\Contracts\Routing\ResponseFactory
  */
 public function postLogin()
 {
     //验证表单
     $this->validate($this->request(), ['admin_name' => 'required', 'admin_pass' => 'required']);
     //获取表单数据
     $credentials = $this->request()->only(['admin_pass', 'admin_name']);
     $credentials['admin_status'] = AdminEnum::STATUS_NORMAL;
     //登录验证
     if ($user = $this->auth->attempt($credentials, $this->request()->has('remember'))) {
         //登录成功,跳转回登录前页面
         return $this->redirect('/admin');
     }
     //TODO 抛出异常代码
     return $this->redirect()->back()->withErrors('账号或密码错误');
 }
开发者ID:netxinyi,项目名称:meigui,代码行数:19,代码来源:AuthController.php

示例3: postLogin

 /**
  * @param PostLoginRequest $request
  * @param Guard            $guard
  *
  * @return \Illuminate\Http\RedirectResponse
  */
 public function postLogin(PostLoginRequest $request, Guard $guard)
 {
     $input = $request->get('login');
     if ($guard->viaRemember() || $guard->attempt(['email' => $input['email'], 'password' => $input['password']], isset($input['remember_me']) ? true : false)) {
         return redirect()->back();
     }
     return redirect()->route('general::guest::getLogin');
 }
开发者ID:JunkyPic,项目名称:Minecraft-Files,代码行数:14,代码来源:UserController.php

示例4: auth

 /**
  * Do password authentication
  *
  * @param CreateAuthRequest $request
  * @return JsonResponse
  */
 public function auth(CreateAuthRequest $request)
 {
     $credentials = $request->only(['email', 'password']);
     $isOk = $this->auth->attempt($credentials, true);
     if (!$isOk) {
         return $this->respondWithError(__('Invalid username or password!'), 404);
     }
     $user = $this->auth->user();
     if ($user->status == 0) {
         $this->auth->logout($user);
         return $this->respondWithError(__('Your account is not confirmed!'));
     }
     if ($user->blocked == 1) {
         $this->auth->logout($user);
         return $this->respondWithError(__('Your account is blocked!'));
     }
     return new JsonResponse();
 }
开发者ID:vjaykoogu,项目名称:smile-media-laravel,代码行数:24,代码来源:AuthController.php

示例5: postAuth

 public function postAuth(Request $request, Guard $guard, Repository $repository)
 {
     $user = app($repository->get('auth.model'))->where('loginPessoa', '=', $request->get('loginPessoa'))->where('senhaPessoa', '=', md5($request->get('senhaPessoa')))->first();
     if ($user) {
         return ['UserKey' => md5($user->codigoPessoa)];
     }
     if ($guard->attempt($request->all())) {
         return ['UserKey' => strtoupper(md5($guard->user()->codigoPessoa))];
     }
     throw new ApiAuthException('Invalid user or password!');
 }
开发者ID:andersonef,项目名称:api-implementation,代码行数:11,代码来源:ApiLayer.php

示例6: postLogin

 /**
  * Login user
  *
  * @param \Illuminate\Http\Request           $request
  * @param \Tajrish\Services\UserTokenHandler $tokenHandler
  * @param \Illuminate\Auth\Guard             $auth
  * @return \Illuminate\Http\JsonResponse
  */
 public function postLogin(Request $request, UserTokenHandler $tokenHandler, Guard $auth)
 {
     $this->validate($request, ['email' => 'required|email', 'password' => 'required|string']);
     // @FIXME Remove extra user call
     if ($auth->attempt($request->only(['email', 'password']))) {
         $user = User::where('email', $request['email'])->first();
         $token = $tokenHandler->createAndGetTokenForUser($user);
         return response()->json(['user' => $user, 'found' => true, 'token_entity' => $token, 'message' => trans('messages.successful_login')]);
     }
     return response()->json(['found' => false, 'message' => trans('messages.invalid_credentials')]);
 }
开发者ID:tajrish,项目名称:api,代码行数:19,代码来源:AuthController.php

示例7: login

 /**
  * @return boolean
  *
  * @throws LoginNotValidException
  */
 public function login()
 {
     $validator = \Validator::make($this->request->all(), ['email' => 'required|email', 'password' => 'required']);
     if ($validator->fails()) {
         throw new ValidationException($validator);
     }
     $credentials = $this->request->only('email', 'password');
     if ($this->auth->attempt($credentials, $this->request->has('remember'))) {
         \Event::fire(new LoggedIn($this->auth->user()));
         return true;
     }
     throw new LoginNotValidException($this->getFailedLoginMessage());
 }
开发者ID:AudithSoftworks,项目名称:Basis-API,代码行数:18,代码来源:Registrar.php

示例8: postLogin

 /**
  * Post login form.
  *
  * @return \Illuminate\Http\RedirectResponse
  */
 public function postLogin(Request $request, Guard $auth)
 {
     $credentials = $request->only(['username', 'password']);
     $remember = $request->get('remember', false);
     if (str_contains($credentials['username'], '@')) {
         $credentials['email'] = $credentials['username'];
         unset($credentials['username']);
     }
     if ($auth->attempt($credentials, $remember)) {
         return $this->redirectIntended(route('user.index'));
     }
     return $this->redirectBack(['login_errors' => true]);
 }
开发者ID:qloog,项目名称:site,代码行数:18,代码来源:AuthController.php

示例9: login

 /**
  * Given correct credentials, log a user in.
  *
  * @param  array   $credentials
  * @param  boolean $remember
  *
  * @return bool
  * @throws AuthenticationException
  */
 public function login(array $credentials, $remember = false)
 {
     $credentials['is_active'] = 1;
     // if the "eloquent-exceptions" driver is being used, an exception will
     // be thrown if authentication failed. if one of the stock drivers are
     // being used, it will just return false, and we have to throw the
     // exception ourselves, with less information.
     if (!$this->auth->attempt($credentials, $remember)) {
         throw new AuthenticationException('Illuminate\\Auth\\Guard::attempt returned false');
     }
     $this->getCurrentUser()->rehashPassword($credentials['password']);
     return true;
 }
开发者ID:anlutro,项目名称:l4-core,代码行数:22,代码来源:UserManager.php

示例10: attempt

 public function attempt(array $credentials = array(), $remember = false, $login = true)
 {
     if ($username = $this->getValidUsernameField($credentials)) {
         switch ($username) {
             case 'customers_email_address':
                 $provider = new EloquentUserProvider(new OscHasher(), 'Johnnygreen\\LaravelApi\\Auth\\Customer');
                 break;
             case 'username':
                 $provider = new EloquentUserProvider(new Md5Hasher(), 'Johnnygreen\\LaravelApi\\Auth\\User');
                 break;
             case 'access_token':
                 $provider = new TokenUserProvider(new PassthruHasher(), 'Johnnygreen\\LaravelApi\\Auth\\Token');
                 break;
             default:
                 return false;
         }
         $this->setProvider($provider);
         return parent::attempt($credentials, $remember, $login);
     }
     return false;
 }
开发者ID:Anshdesire,项目名称:laravel-api,代码行数:21,代码来源:TokenGuard.php

示例11: show

 public function show(Request $request, Guard $auth, Carbon $carbon, Timesheet $timesheet)
 {
     $this->validate($request, ['username' => 'required', 'password' => 'required']);
     $credentials = $request->only('username', 'password');
     if ($auth->attempt($credentials)) {
         $employee = $auth->user();
         $sheet = $timesheet->where('employee_id', $employee->id)->where('sheet_date', $carbon->now()->toDateString())->first();
         $result = [];
         $result['employee_id'] = $employee->id;
         $result['username'] = $employee->username;
         $result['name'] = $employee->firstname . ' ' . $employee->lastname;
         $result['type'] = 'in';
         if ($sheet) {
             $result['type'] = 'out';
             $result['start'] = $sheet->entry->start_time;
             $result['entry_id'] = $sheet->entry->id;
             $result['sheet_id'] = $sheet->id;
         }
         return response()->json($result);
     } else {
         return response()->json(['error' => 'true', 'msg' => 'Akses login Anda tidak ditemukan.']);
     }
 }
开发者ID:Nitri0,项目名称:SnapClock,代码行数:23,代码来源:AttendanceController.php

示例12: attempt

 /**
  * Attempt to authenticate a user using the given credentials.
  *
  * @param array $credentials
  * @param bool $remember
  * @param bool $login
  * @return bool 
  * @static 
  */
 public static function attempt($credentials = array(), $remember = false, $login = true)
 {
     return \Illuminate\Auth\Guard::attempt($credentials, $remember, $login);
 }
开发者ID:satriashp,项目名称:tour,代码行数:13,代码来源:_ide_helper.php

示例13: checkUserCredentials

 public function checkUserCredentials($username, $password)
 {
     $creds = call_user_func($this->credentialsFormatter, $username, $password);
     return $this->guard->attempt($creds, false, false);
 }
开发者ID:tappleby,项目名称:laravel-oauth2-server,代码行数:5,代码来源:UserStorage.php

示例14: handle

 /**
  * Execute the command.
  *
  * @return bool
  */
 public function handle()
 {
     return $this->auth->attempt($this->request->except(['_token', 'remember', 'login_user']), $this->request->get('remember'));
 }
开发者ID:jbmadking,项目名称:bottlestore,代码行数:9,代码来源:LoginSiteUser.php


注:本文中的Illuminate\Auth\Guard::attempt方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。