本文整理汇总了PHP中Illuminate\Auth\Guard::setUser方法的典型用法代码示例。如果您正苦于以下问题:PHP Guard::setUser方法的具体用法?PHP Guard::setUser怎么用?PHP Guard::setUser使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Illuminate\Auth\Guard
的用法示例。
在下文中一共展示了Guard::setUser方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: handle
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @return mixed
*/
public function handle($request, \Closure $next)
{
try {
$userAndKey = $this->key->extractKeyAndUser($request);
if ($userAndKey) {
/** @var User $user */
$user = $userAndKey['user'];
if ($user->isDisabled()) {
abort(403, 'User is disabled');
}
$this->manager->setUser($user);
}
return $next($request);
} catch (InvalidAuthException $e) {
abort(401, $e->getMessage());
}
abort(401, 'User could not be found.');
}
示例2: __construct
public function __construct(Request $request, Guard $auth)
{
// TODO: Add API keys and check here
// Check the session token and authenticate the user.
if ($sessionToken = $request->get('sessionToken')) {
$user = $this->validateSessionToken($sessionToken);
$auth->setUser($user);
}
parent::__construct($request, $auth);
}
示例3: setUser
/**
* Set the current user.
*
* @param \Illuminate\Contracts\Auth\Authenticatable $user
* @return void
* @static
*/
public static function setUser($user)
{
\Illuminate\Auth\Guard::setUser($user);
}
示例4: setUser
/**
* Set the current user of the application.
*
* @param \Illuminate\Contracts\Auth\Authenticatable $user
*/
public function setUser(UserContract $user)
{
parent::setUser($user);
$this->resetRolesAndPermissions();
$this->setRolesAndPermissions($user);
}
示例5: setCurrentUser
/**
* Set the current user.
*
* @param UserModel $user
*/
public function setCurrentUser(UserModel $user)
{
$this->auth->setUser($user);
}
示例6: __construct
public function __construct(Request $request, Guard $auth)
{
// TODO: Add API keys and check here
if ($sessionKey = $request->get('sessionKey')) {
/** @var UserSession $session */
$session = UserSession::find($sessionKey);
if (!$session) {
throw new NotFoundHttpException("The given sessionKey is invalid.");
}
if (!$session->user) {
throw new NotFoundHttpException("The user for that session could not be found.");
}
// Login the user just for this request.
$auth->setUser($session->user);
}
parent::__construct($request, $auth);
}