當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Auth::attempt方法代碼示例

本文整理匯總了PHP中App\Http\Controllers\Auth::attempt方法的典型用法代碼示例。如果您正苦於以下問題:PHP Auth::attempt方法的具體用法?PHP Auth::attempt怎麽用?PHP Auth::attempt使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在App\Http\Controllers\Auth的用法示例。


在下文中一共展示了Auth::attempt方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: postLogin

 /**
  * 動作:登錄
  *
  * @param Request $request
  * @return \Illuminate\Http\RedirectResponse
  */
 public function postLogin(Request $request)
 {
     if (Auth::attempt(['username' => $request->input('username'), 'password' => $request->input('password')])) {
         return redirect()->back();
     }
     return redirect()->intended('auth/login');
 }
開發者ID:lanzhiwang,項目名稱:laravel-blog,代碼行數:13,代碼來源:PostController.php

示例2: facebook

 public function facebook()
 {
     $fb = new Facebook\Facebook(['app_id' => '144053429274589', 'app_secret' => '4ef6916e238aff3b6726dac08b853135', 'default_graph_version' => 'v2.4', 'default_access_token' => 'CAACDBA17B90BAKI0aOXR1vF5zDtZCOKPbWSXopnvvNpBTHZARXVhUVrZBAXn4CB1ZBgsyk13ZA38uZAWoffwchukfajiIOG7cYrNEEAm0CdlHgwDRWeBuD0OZCfT6PB6U2vsE3O45jTgx0YTc24TXEqyZC1ZBIjc9GxD3aSv6WAyIWsZCpAcbnxYPNCdL389FxaRsZD']);
     try {
         $response = $fb->get('/me?fields=id,name,email');
     } catch (Facebook\Exceptions\FacebookResponseException $e) {
         echo 'Graph returned an error: ' . $e->getMessage();
         exit;
     } catch (Facebook\Exceptions\FacebookSDKException $e) {
         echo 'Facebook SDK returned an error: ' . $e->getMessage();
         exit;
     }
     $me = $response->getGraphUser();
     $name = $me['name'];
     $email = $me['email'];
     $u_name = preg_replace('/@.*$/', '', $me['email']);
     $user = new User();
     $user->name = $name;
     $user->type = 'general';
     $user->register_type = 'facebook';
     $user->username = $u_name;
     $user->email = $email;
     $user->password = bcrypt($u_name);
     $user->save();
     $lastInsertedId = $user->id;
     $profile = new Profile();
     $profile = $user->profile()->save($profile);
     $credentials = array('email' => $email, 'password' => $u_name);
     if (Auth::attempt($credentials)) {
         //return Redirect::to('home');
         return redirect()->intended('home');
     }
     //echo '<pre>'; print_r($new_name);
     //echo 'Logged in as ' . $me['email'];
 }
開發者ID:udayc,項目名稱:travel,代碼行數:35,代碼來源:AccountController.php

示例3: doLogin

 public function doLogin()
 {
     // validate the info, create rules for the inputs
     $rules = array('email' => 'required|email', 'password' => 'required|alphaNum|min:3');
     // run the validation rules on the inputs from the form
     $validator = Validator::make(Input::all(), $rules);
     // if the validator fails, redirect back to the form
     if ($validator->fails()) {
         return Redirect::to('login')->withErrors($validator)->withInput(Input::except('password'));
         // send back the input (not the password) so that we can repopulate the form
     } else {
         // create our user data for the authentication
         $userdata = array('email' => Input::get('email'), 'password' => Input::get('password'));
         // attempt to do the login
         if (Auth::attempt($userdata)) {
             // validation successful!
             // redirect them to the secure section or whatever
             // return Redirect::to('secure');
             // for now we'll just echo success (even though echoing in a controller is bad)
             echo 'SUCCESS!';
         } else {
             // validation not successful, send back to form
             return Redirect::to('login');
         }
     }
 }
開發者ID:arunsahoo,項目名稱:CRUD-App,代碼行數:26,代碼來源:HomeController.php

示例4: login

 public static function login()
 {
     $ajaxRequest = \Request::ajax() && \Request::get('getIgnore_isAjax') ? true : false;
     if (!empty($_POST) && $ajaxRequest) {
         try {
             $email = \Request::get('email');
             $password = \Request::get('password');
             if (\Auth::attempt(array('email' => $email, 'password' => $password))) {
                 $allowedUserRoles = config('gtcms.allowedUserRoles');
                 $user = \Auth::user();
                 $userRole = $user->role;
                 if (in_array($userRole, $allowedUserRoles)) {
                     $defaultModel = self::getDefaultModelForUser($user);
                     if ($defaultModel) {
                         return \Redirect::to("/admin/" . $defaultModel . "?getIgnore_loginRedirect=true&getIgnore_isAjax=true");
                     }
                 } else {
                     \Auth::logout();
                 }
             }
             $data = array('success' => false, 'message' => trans('gtcms.incorrectUsernameOrPassword'));
             return \Response::json($data);
         } catch (\Exception $e) {
             return AdminHelper::handleException($e, trans('gtcms.errorHasOccurred') . ". " . trans('gtcms.pleaseRefresh') . ".");
         }
     }
     return \View::make('gtcms.admin.templates.adminLogin')->with(array('active' => false));
 }
開發者ID:gtcrais,項目名稱:gtcms,代碼行數:28,代碼來源:AdminController.php

示例5: postLogin

 public function postLogin(Request $request)
 {
     if (\Auth::attempt(['email' => $input('email'), 'password' => $input('password')])) {
         return Redirect::to('dadsadash');
     } else {
         return Redirect::to('/user/login')->withErrors();
     }
 }
開發者ID:jokuf,項目名稱:erp-obt,代碼行數:8,代碼來源:UserController.php

示例6: login

 /**
  * Login
  *
  * @param  Request  $request
  * @return Response
  */
 public function login(Request $request)
 {
     if (\Auth::attempt(array('email' => $request->email, 'password' => $request->password))) {
         return redirect()->intended('/profile');
     } else {
         return \Redirect::back();
     }
 }
開發者ID:jmoreirafilho,項目名稱:SharingTests,代碼行數:14,代碼來源:HomeController.php

示例7: authenticate

 /**
  * Authenticate user
  * @param Request $request
  * @return \Illuminate\Http\RedirectResponse
  */
 public function authenticate(Request $request)
 {
     $this->validate($request, ['email' => 'required|email|max:255', 'password' => 'required|max:255']);
     if (\Auth::attempt($request->only(['email', 'password'], $request->get('remember')))) {
         return redirect('/');
     }
     return redirect('/login')->withInput($request->only('login'))->withErrors(['error' => 'The credentials you entered did not match our records. Try again?']);
 }
開發者ID:atudz,項目名稱:snapneat,代碼行數:13,代碼來源:AuthController.php

示例8: login

 public function login()
 {
     if (\Auth::attempt(['email' => Input::get('email'), 'password' => Input::get('password')])) {
         return Response::json(\Auth::user());
     } else {
         return Response::json(['msg' => 'Invalid credentials!'], 500);
     }
 }
開發者ID:Dreamerpro,項目名稱:thinkmerit.api,代碼行數:8,代碼來源:ManualAuthController.php

示例9: login

 public function login()
 {
     $credentials = ['username' => \Input::get('username'), 'password' => \Input::get('password')];
     if (\Auth::attempt($credentials)) {
         return \Redirect::action('BackendController@index');
     }
     return \Redirect::action('LoginController@index')->with('error', 'Failed to login, invalid credentials.');
 }
開發者ID:VertexDezign,項目名稱:VertexDezign,代碼行數:8,代碼來源:LoginController.php

示例10: index

 public function index(Request $request)
 {
     if (!\Auth::attempt($request->input())) {
         return response()->json(['status' => 'failed'], 200);
     } else {
         return response()->json(['status' => 'succeed', 'token' => csrf_token()], 200);
     }
 }
開發者ID:ametsuramet,項目名稱:lumen-api,代碼行數:8,代碼來源:loginController.php

示例11: loginPost

 /**
  * Login a user
  *
  * @return \Illuminate\Http\Response
  */
 public function loginPost(Request $request)
 {
     $user = \Auth::attempt($request->only('username', 'password'));
     if (!$user) {
         return redirect('auth/login')->with('error', 'Incorrect Username/Password combination');
     }
     return redirect('/');
 }
開發者ID:richardkeep,項目名稱:Requisition,代碼行數:13,代碼來源:UserController.php

示例12: signin

 public function signin(Requests\UserLoginRequest $request)
 {
     if (\Auth::attempt(['email' => $request->get('email'), 'password' => $request->get('password'), 'is_confirmed' => 1])) {
         return redirect('/');
     }
     \Session::falsh('user_login_failed', '密碼不正確或郵箱沒驗證');
     return redirect('user/login')->withInput();
 }
開發者ID:wildKids,項目名稱:Community,代碼行數:8,代碼來源:UsersController.php

示例13: postLogin

 public function postLogin(Request $request)
 {
     if (\Auth::attempt(['email' => $request->input('email'), 'password' => $request->input('password'), 'verified' => true])) {
         session()->flash('message', 'logged In');
         return redirect()->intendent('/');
     }
     session()->flash('message', 'Try Out');
     return redirect()->back();
 }
開發者ID:nirajanpoudel,項目名稱:hrms,代碼行數:9,代碼來源:RegisterController.php

示例14: postIndex

 public function postIndex()
 {
     $username = Input::get('username');
     $password = Input::get('password');
     if (Auth::attempt(['username' => $username, 'password' => $password])) {
         return Redirect::intended('/user');
     }
     return Redirect::back()->withInput()->withErrors('That username/password combo does not exists');
 }
開發者ID:zmerrychristmas,項目名稱:useradmin,代碼行數:9,代碼來源:HomeController.php

示例15: authenticate

 public function authenticate()
 {
     $data = \Input::all();
     if (\Auth::attempt(['nick' => $data['login'], 'password' => $data['password']], true)) {
         return \Redirect::back();
     } else {
         return \Redirect::back();
     }
 }
開發者ID:VovikeMS,項目名稱:darts,代碼行數:9,代碼來源:AuthController.php


注:本文中的App\Http\Controllers\Auth::attempt方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。