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


PHP Auth::attempt方法代码示例

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


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

示例1: index

 /**
  * Display a listing of the resource.
  *
  * @return \Illuminate\Http\Response
  */
 public function index(Request $request)
 {
     $email = (string) $request->get('email');
     $password = (string) $request->get('password');
     if (isset($email) and !empty($email) and isset($password) and !empty($password)) {
         if ($email === "user@codepi.com" and $password === "pwd2015") {
             $user = User::where('email', '=', $email)->count();
             if ($user == 0) {
                 User::create(['email' => $email, 'password' => Hash::make($password)]);
             }
             if (Auth::attempt(['email' => $email, 'password' => $password])) {
                 //$items = Concert::all()->toArray();
                 $query = 'select * from concerts';
                 $items = DB::select(DB::raw($query));
                 $perPage = 20;
                 $page = Input::get('page') ? Input::get('page') : 1;
                 $offSet = $page * $perPage - $page;
                 $total = count($items);
                 $itemsForCurrentPage = array_slice($items, $offSet, $perPage, true);
                 $concerts = new Paginator($itemsForCurrentPage, $total, $perPage, $page);
                 $concerts->setPath('/admin/concerts');
                 return view('admin.admin-concerts-page', ['concerts' => $concerts]);
             }
             return view('admin.auth-page');
         }
         return view('admin.auth-page');
     }
     return view('admin.auth-page');
 }
开发者ID:makhloufi-lounis,项目名称:codepi_tt,代码行数:34,代码来源:ConcertController.php

示例2: registerAccount

 public function registerAccount(Requests\RegisterRequest $request)
 {
     User::createUser(Input::except("_token", "password_confirmation"));
     if (Auth::attempt(['nickname' => Input::get('nickname'), 'password' => Input::get('password')])) {
         return Redirect::to('gameLobby');
     }
 }
开发者ID:Jounter,项目名称:grp20,代码行数:7,代码来源:LoginRegisterController.php

示例3: postLogin

 public function postLogin(\Illuminate\Http\Request $request)
 {
     $username = $request->input('username');
     $password = $request->input('password');
     // First try to log in as a local user.
     if (Auth::attempt(array('username' => $username, 'password' => $password))) {
         $this->alert('success', 'You are now logged in.', true);
         return redirect('users/' . Auth::user()->id);
     }
     // Then try with ADLDAP.
     $ldapConfig = \Config::get('adldap');
     if (array_get($ldapConfig, 'domain_controllers', false)) {
         $adldap = new \adldap\adLDAP($ldapConfig);
         if ($adldap->authenticate($username, $password)) {
             // Check that they exist.
             $user = \Ormic\Model\User::where('username', '=', $username)->first();
             if (!$user) {
                 $user = new \Ormic\Model\User();
                 $user->username = $username;
                 $user->save();
             }
             \Auth::login($user);
             //$this->alert('success', 'You are now logged in.', TRUE);
             return redirect('');
             //->with(['You are now logged in.']);
         }
     }
     // If we're still here, authentication has failed.
     return redirect()->back()->withInput($request->only('username'))->withErrors(['Authentication failed.']);
 }
开发者ID:samwilson,项目名称:ormic,代码行数:30,代码来源:UsersController.php

示例4: login

 /**
  * Handle a login request to the application.
  * Requires $this->usernameField, password, remember request fields.
  *
  * @param  \Illuminate\Http\Request  $request
  * @return \Illuminate\Http\Response
  */
 public function login(Request $request)
 {
     $this->validate($request, [$this->usernameField => 'required', 'password' => 'required']);
     // Check whether this controller is using ThrottlesLogins trait
     $throttles = in_array(ThrottlesLogins::class, class_uses_recursive(get_class($this)));
     if ($throttles && $this->hasTooManyLoginAttempts($request)) {
         return $this->sendLockoutResponse($request);
     }
     $credentials = $request->only($this->usernameField, 'password');
     // Try to authenticate using username or NIM
     if (Auth::attempt(['username' => $request[$this->usernameField], 'password' => $request['password']], $request->has('remember')) || Auth::attempt(['nim' => $request[$this->usernameField], 'password' => $request['password']], $request->has('remember'))) {
         // Authentication successful
         if ($throttles) {
             $this->clearLoginAttempts($request);
         }
         return redirect()->intended($this->redirectLogin);
     }
     // If the login attempt was unsuccessful we will increment the number of attempts
     // to login and redirect the user back to the login form. Of course, when this
     // user surpasses their maximum number of attempts they will get locked out.
     if ($throttles) {
         $this->incrementLoginAttempts($request);
     }
     $failedLoginMessage = Lang::has('auth.failed') ? Lang::get('auth.failed') : 'These credentials do not match our records.';
     return redirect()->back()->withInput($request->only($this->usernameField, 'remember'))->withErrors([$this->usernameField => $failedLoginMessage]);
 }
开发者ID:stei2015,项目名称:webstei2015,代码行数:33,代码来源:AuthController.php

示例5: postLogin

 public function postLogin()
 {
     if (Auth::attempt(Request::only('email', 'password'))) {
         return redirect()->intended('/dashboard');
     }
     return redirect()->route('log-in')->withErrors(['auth' => ['The email or password you entered is incorrect.']]);
 }
开发者ID:jwalton512,项目名称:symposium,代码行数:7,代码来源:AuthController.php

示例6: store

 /**
  * Attempt login
  *
  * @param  Request $request
  *
  * @return response
  */
 public function store(Request $request)
 {
     if (Auth::attempt($request->only('email', 'password'))) {
         return redirect()->route('home');
     }
     return back();
 }
开发者ID:keevitaja,项目名称:crm.keevitaja.com,代码行数:14,代码来源:AuthController.php

示例7: login

 public function login(Request $request)
 {
     //\App\User::create(['name' => 'Chanteux', 'email' => 'nathanchanteux@gmail.com', 'password' => \Illuminate\Support\Facades\Hash::make('root')]);
     Auth::attempt(['email' => $request->input('email'), 'password' => $request->input('password')]);
     //dd(Auth::check());
     return redirect('/admin/article')->with('message', 'Connexion établie.');
 }
开发者ID:Nathan-Chanteux,项目名称:LeChienDeRobermont,代码行数:7,代码来源:UsersController.php

示例8: postLogin

 /**
  * Handle a login request to the application.
  * @param  \Illuminate\Http\Request $request
  * @return \Illuminate\Http\Response
  */
 public function postLogin(Request $request)
 {
     $this->validate($request, [$this->loginUsername() => 'required', 'password' => 'required'], [$this->loginUsername() . '.required' => 'Please enter your username or email address', 'password.required' => 'Please enter your password']);
     // If the class is using the ThrottlesLogins trait, we can automatically throttle
     // the login attempts for this application. We'll key this by the username and
     // the IP address of the client making these requests into this application.
     $throttles = $this->isUsingThrottlesLoginsTrait();
     if ($throttles && $this->hasTooManyLoginAttempts($request)) {
         return $this->sendLockoutResponse($request);
     }
     $credentials = $request->only('password');
     if (Auth::attempt(['username' => $request->get($this->loginUsername())] + $credentials, $request->has('remember'))) {
         return $this->handleUserWasAuthenticated($request, $throttles);
     } else {
         if (Auth::attempt(['email' => $request->get($this->loginUsername())] + $credentials, $request->has('remember'))) {
             return $this->handleUserWasAuthenticated($request, $throttles);
         }
     }
     // If the login attempt was unsuccessful we will increment the number of attempts
     // to login and redirect the user back to the login form. Of course, when this
     // user surpasses their maximum number of attempts they will get locked out.
     if ($throttles) {
         $this->incrementLoginAttempts($request);
     }
     return redirect($this->loginPath())->withInput($request->only($this->loginUsername(), 'remember'))->withErrors([$this->loginUsername() => $this->getFailedLoginMessage()]);
 }
开发者ID:backstagetechnicalservices,项目名称:website,代码行数:31,代码来源:AuthController.php

示例9: login

 public function login(Request $request)
 {
     if (Session::has('fs_supplier')) {
         return redirect('/supplier/dashboard');
     }
     if ($request->isMethod('post')) {
         $remember = $request['remember'] == 'on' ? true : false;
         $emailOrUsername = $request->input('emailOrUsername');
         $password = $request->input('password');
         $this->validate($request, ['emailOrUsername' => 'required', 'password' => 'required'], ['emailOrUsername.required' => 'Please enter email address or username', 'password.required' => 'Please enter a password']);
         $field = 'username';
         if (strpos($emailOrUsername, '@')) {
             $field = 'email';
         }
         if (Auth::attempt([$field => $emailOrUsername, 'password' => $password], $remember)) {
             $objModelUsers = User::getInstance();
             $userDetails = $objModelUsers->getUserById(Auth::id());
             if ($userDetails->role == 3) {
                 Session::put('fs_supplier', $userDetails['original']);
                 return redirect()->intended('supplier/dashboard');
             } else {
                 return view("Supplier/Views/supplier/login")->withErrors(['errMsg' => 'Invalid credentials.']);
             }
         } else {
             return view("Supplier/Views/supplier/login")->withErrors(['errMsg' => 'Invalid credentials.']);
         }
     }
     return view("Supplier/Views/supplier/login");
 }
开发者ID:DinanathThakur,项目名称:Flash-Sale-Ecommerce-Portal-PHP,代码行数:29,代码来源:SupplierController.php

示例10: login

 public function login(Request $request)
 {
     if (Auth::attempt(['email' => $request->get('email'), 'password' => $request->get('password')])) {
         return redirect('/dashboard');
     }
     return back()->withErrors("Invaid Username or Password");
 }
开发者ID:burimshala,项目名称:todoapp,代码行数:7,代码来源:UsersController.php

示例11: login

 /**
  * @param Request $request
  * @return \Illuminate\Http\JsonResponse
  */
 public function login(Request $request)
 {
     if (Auth::attempt(['email' => $request->input("email"), 'password' => $request->input("password")])) {
         return Auth::user();
     }
     return response()->json(["message" => "invalid login"], 403);
 }
开发者ID:Aqu1nt,项目名称:herzjesu-derendingen,代码行数:11,代码来源:AuthController.php

示例12: doLogin

 public function doLogin(Request $request)
 {
     // validate the info, create rules for the inputs
     $rules = array('email' => 'required|email', 'pass' => 'required|alphaNum');
     // run the validation rules on the inputs from the form
     $validator = Validator::make($request->all(), $rules);
     // if the validator fails, redirect back to the form
     if ($validator->fails()) {
         return redirect()->action('AuthenticationController@showRegister')->withErrors($validator)->withInput($request->except('pass'));
         // 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' => $request->input('email'), 'password' => $request->input('pass'));
         // attempt to do the login
         if (Auth::attempt($userdata)) {
             $user = Auth::user();
             if ($user->isSupplier()) {
                 return redirect()->action('Dashboard\\SupplierController@show');
             }
             if ($user->isCustomer()) {
                 return redirect()->action('Frontend\\HomeController@index');
             }
         } else {
             // validation not successful, send back to form
             return redirect()->action('AuthenticationController@showRegister')->withErrors(['messages' => 'Email or Password is incorrect']);
         }
     }
 }
开发者ID:mg9,项目名称:koalaBazaar,代码行数:28,代码来源:AuthenticationController.php

示例13: postLogin

 /**
  * Handle a login request to the application.
  *
  * @param  \Illuminate\Http\Request  $request
  * @return \Illuminate\Http\Response
  */
 public function postLogin(Request $request)
 {
     $this->validate($request, ['email' => 'required', 'password' => 'required']);
     // If the class is using the ThrottlesLogins trait, we can automatically throttle
     // the login attempts for this application. We'll key this by the username and
     // the IP address of the client making these requests into this application.
     $throttles = false;
     if ($throttles && $this->hasTooManyLoginAttempts($request)) {
         if ($request->ajax()) {
             return response()->json(["error" => "Too many login attempts"], 401);
         }
         return $this->sendLockoutResponse($request);
     }
     $credentials = $request->only('email', 'password');
     if (Auth::attempt($credentials, $request->has('remember'))) {
         return $this->handleUserWasAuthenticated($request, $throttles);
     }
     // If the login attempt was unsuccessful we will increment the number of attempts
     // to login and redirect the user back to the login form. Of course, when this
     // user surpasses their maximum number of attempts they will get locked out.
     if ($throttles) {
         $this->incrementLoginAttempts($request);
     }
     if ($request->ajax()) {
         return response()->json(['email' => 'Login failed'], 401);
     } else {
         return redirect($this->loginPath())->withInput($request->only($this->loginUsername(), 'remember'))->withErrors(['email' => 'Login failed']);
     }
 }
开发者ID:jirojo2,项目名称:pleem,代码行数:35,代码来源:AuthController.php

示例14: idpAuthorize

 /**
  * Setup authorization based on returned server variables
  * from the IdP.
  * POPRAVI TAKO, DA BO UPDATE-AL PRAVO TABELO (TOREJ MYSQL TABELO)
  */
 public function idpAuthorize()
 {
     $userid = ServerService::parseXML(ServerService::getShibbolethVariable(config('shibboleth.idp_login_id')));
     $email = ServerService::getShibbolethVariable(config('shibboleth.idp_login_email'));
     $given_name = ServerService::getShibbolethVariable(config('shibboleth.idp_login_given_name'));
     $common_name = ServerService::getShibbolethVariable(config('shibboleth.idp_login_common_name'));
     $surname = ServerService::getShibbolethVariable(config('shibboleth.idp_login_last'));
     $primary_affiliation = ServerService::getShibbolethVariable(config('shibboleth.idp_login_pr_affiliation'));
     $principal_name = ServerService::getShibbolethVariable(config('shibboleth.idp_login_pr_name'));
     $home_org = ServerService::getShibbolethVariable(config('shibboleth.idp_login_home_org'));
     $home_org_type = ServerService::getShibbolethVariable(config('shibboleth.idp_login_home_org_type'));
     $shib_session_id = ServerService::getShibbolethVariable("Shib-Session-ID");
     if (UserServiceTestFed::matchingCredentials($primary_affiliation)) {
         $user = new UserServiceTestFed($userid, $common_name, $surname, $given_name, $email, $primary_affiliation, $principal_name, $home_org, $home_org_type);
         if (Auth::attempt(['id' => $userid, 'primary_affiliation' => $primary_affiliation])) {
             Auth::attempt(['id' => $userid, 'primary_affiliation' => $primary_affiliation]);
             //Auth::login($user);
             $user->createOrUpdateUser("update");
             $user->createSession($shib_session_id);
             return Redirect::to(config('shibboleth.shibboleth_authenticated'));
         } else {
             $user->createOrUpdateUser("create");
             $user->createSession($shib_session_id);
             if (Auth::attempt(['id' => $userid, 'primary_affiliation' => $primary_affiliation])) {
                 Auth::attempt(['id' => $userid, 'primary_affiliation' => $primary_affiliation]);
                 return Redirect::to(config('shibboleth.shibboleth_authenticated'));
             } else {
                 return Redirect::to(config('shibboleth.shibboleth_unauthorized'));
             }
         }
     } else {
         return Redirect::to(config('shibboleth.shibboleth_unauthorized'));
     }
 }
开发者ID:vidmahovic,项目名称:Laravel-Shibboleth-Service-Provider,代码行数:39,代码来源:ShibbolethController.php

示例15: postLogin

 /**
  * Handle a login request to the application.
  *
  * @param  \Illuminate\Http\Request  $request
  * @return \Illuminate\Http\Response
  */
 public function postLogin(Request $request)
 {
     $this->validate($request, [$this->loginUsername() => 'required', 'password' => 'required'], [], ['email' => 'Email', 'password' => '密码', 'username' => '用户名']);
     // If the class is using the ThrottlesLogins trait, we can automatically throttle
     // the login attempts for this application. We'll key this by the username and
     // the IP address of the client making these requests into this application.
     $throttles = $this->isUsingThrottlesLoginsTrait();
     if ($throttles && $this->hasTooManyLoginAttempts($request)) {
         return $this->sendLockoutResponse($request);
     }
     $credentials = $this->getCredentials($request);
     if (Auth::attempt($credentials, $request->has('remember'))) {
         User::where('email', $credentials['email'])->update(['login_at' => date('Y-m-d H:i:s')]);
         LoginLog::insertLog(Auth::user()->id, Auth::user()->email, Auth::user()->name, $request->ip(), true);
         return $this->handleUserWasAuthenticated($request, $throttles);
     }
     LoginLog::insertLog(null, $credentials['email'], '', $request->ip(), false);
     // If the login attempt was unsuccessful we will increment the number of attempts
     // to login and redirect the user back to the login form. Of course, when this
     // user surpasses their maximum number of attempts they will get locked out.
     if ($throttles) {
         $this->incrementLoginAttempts($request);
     }
     return redirect($this->loginPath())->withInput($request->only($this->loginUsername(), 'remember'))->withErrors([$this->loginUsername() => $this->getFailedLoginMessage()]);
 }
开发者ID:ChenPeiyuan,项目名称:student-infomation-manager,代码行数:31,代码来源:AuthenticatesUsers.php


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