本文整理汇总了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());
}
示例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('账号或密码错误');
}
示例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');
}
示例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();
}
示例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!');
}
示例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')]);
}
示例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());
}
示例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]);
}
示例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;
}
示例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;
}
示例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.']);
}
}
示例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);
}
示例13: checkUserCredentials
public function checkUserCredentials($username, $password)
{
$creds = call_user_func($this->credentialsFormatter, $username, $password);
return $this->guard->attempt($creds, false, false);
}
示例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'));
}