本文整理汇总了PHP中Illuminate\Contracts\Auth\Guard::once方法的典型用法代码示例。如果您正苦于以下问题:PHP Guard::once方法的具体用法?PHP Guard::once怎么用?PHP Guard::once使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Illuminate\Contracts\Auth\Guard
的用法示例。
在下文中一共展示了Guard::once方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: authorize
/**
* Authorize the user
*
* @param ResponseFactory $response
* @return array|\Illuminate\Http\Response
*/
public function authorize(ResponseFactory $response)
{
$credentials = array_merge($this->request->only(['username', 'password']), ['status' => 'active']);
if (!$this->auth->once($credentials)) {
return $response->make('Invalid credentials', 401);
}
/*
if (!$this->isAuthorized($userRoles)) {
return $response->make('Unauthorized user', 401);
}*/
return ['token' => $this->getUserToken($this->auth->user())];
}
示例2: verify
/**
* Check credentials for oauth password grant
* @param string $username
* @param sting $password
* @return boolean|int
*/
public function verify($username, $password)
{
$credentials = compact('password');
if (filter_var($username, FILTER_VALIDATE_EMAIL)) {
$credentials['email'] = $username;
} else {
$credentials['username'] = $username;
}
$credentials['active'] = 1;
if ($this->auth->once($credentials)) {
return $this->auth->id();
}
return false;
}
示例3: postLogin
/**
* Perform login attempt
* @param AuthRequestInterface $request
* @param Guard $auth
* @return Illuminate\Http\Response
*/
public function postLogin(AuthRequestInterface $request, Guard $auth)
{
if (($throttles = $this->throttlesLogins()) && $this->hasTooManyLoginAttempts($request)) {
return $this->sendLockoutResponse($request);
}
$credentials = $request->only('password');
$username = $request->get('username');
if (filter_var($username, FILTER_VALIDATE_EMAIL)) {
$credentials['email'] = $username;
} else {
$credentials['username'] = $username;
}
if ($auth->once($credentials)) {
$user = $auth->user();
if ($throttles) {
$this->clearLoginAttempts($request);
}
if (!$user->active) {
return $this->handleUserIsNotActive($request, $user);
}
$this->authenticateUser($auth, $user);
return $this->handleUserWasAuthenticated($request, $user);
}
if ($throttles) {
$this->incrementLoginAttempts($request);
}
return $this->handleUserWasNotAuthenticated($request);
}
示例4: handle
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @return mixed
* @throws \App\Exceptions\InvalidCredentialsException
* @throws \App\Exceptions\NoAuthenticationException
*/
public function handle($request, Closure $next)
{
if (empty($request->header('Authorization'))) {
throw new \App\Exceptions\NoAuthenticationException();
}
$header = $request->headers->get('Authorization');
if (starts_with(strtolower($header), 'bearer')) {
//If token is passed (to refresh)
/** @var User $user */
$user = \JWTAuth::setRequest($request)->parseToken()->authenticate();
\JWTAuth::invalidate();
//invalidate the old token
$this->auth->setUser($user);
} else {
//if credentials are passed
$credentials = ['email' => $request->getUser(), 'password' => $request->getPassword()];
$this->auth->once($credentials);
}
$isAuthenticated = $this->auth->check();
if (!$isAuthenticated) {
throw new \App\Exceptions\InvalidCredentialsException();
}
return $next($request);
}
示例5: postLogin
/**
* Handle a login request to the application.
*
* @param AuthRequest $request
* @return \Illuminate\Http\Response
*/
public function postLogin(AuthRequest $request)
{
$throttles = in_array(ThrottlesLogins::class, class_uses_recursive(get_class($this)));
if ($throttles && $this->hasTooManyLoginAttempts($request)) {
return $this->respondThrottled($request);
}
if (!$this->auth->once($request->only('email', 'password'))) {
if ($throttles) {
$this->incrementLoginAttempts($request);
}
return $this->respondLoginFail($request);
}
$user = $this->auth->getUser();
if (!$user->activated) {
$this->auth->logout();
return $this->respondNotActivated($request, $user->activation_code);
}
$this->auth->loginUsingId($user->id, $request->has('remember'));
if ($throttles) {
$this->clearLoginAttempts($request);
}
event('UserHasLoggedIn', [$this->auth->user()]);
return $this->respondLoginSuccess($request, $user);
}
示例6: byCredentials
/**
* Check a user's credentials.
*
* @param array $credentials
*
* @return bool
*/
public function byCredentials(array $credentials)
{
return $this->auth->once($credentials);
}