當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。