本文整理汇总了PHP中Illuminate\Auth\Guard::login方法的典型用法代码示例。如果您正苦于以下问题:PHP Guard::login方法的具体用法?PHP Guard::login怎么用?PHP Guard::login使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Illuminate\Auth\Guard
的用法示例。
在下文中一共展示了Guard::login方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: confirm
/**
* Confirm account
*
* @param $email
* @param $token
* @return bool|User
*/
public function confirm($email, $token)
{
$user = $this->userRepo->findByEmailAndToken($email, $token);
if ($user && $token) {
$user = $this->userRepo->update($user, ['confirmation_code' => '', 'status' => 1]);
event(new UserWasConfirmed($user));
$this->auth->login($user);
return $user;
}
return false;
}
示例2: registration
/**
* @param Requests\RegistrationFormRequest $request
*
* @return $this|\Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
*/
public function registration(Requests\RegistrationFormRequest $request)
{
$data = $request->only('username', 'email', 'password');
$data['password'] = Hash::make($data['password']);
$user = new User($data);
if ($user->save()) {
$this->auth->login($user);
return redirect('chat');
} else {
return redirect('/')->withErrors(['username' => 'Oops... Something wrong is happened. Try again.'], $request->getErrorBag());
}
}
示例3: callback
/**
* Attempts to authenticate the user.
*
* @param \App\Models\User\User $user
* @param \Illuminate\Auth\Guard $auth
*
* @return \Illuminate\Http\RedirectResponse
*/
public function callback(User $user, Guard $auth)
{
try {
$payload = $this->socialite->user();
} catch (Exception $e) {
$this->flash('Failed to sign in via GitHub, did you decline?', Controller::FLASH_ERROR);
return redirect()->route('get::front.home');
}
try {
$response = app('GuzzleHttp\\Client')->get('https://api.github.com/user/emails?access_token=' . $payload->token, ['headers' => ['Accept' => 'application/vnd.github.v3+json']]);
$emails = $response->json();
} catch (Exception $e) {
$this->flash('Failed to sign in via GitHub, is your GitHub account verified?', Controller::FLASH_ERROR);
return redirect()->route('get::front.home');
}
$email = array_filter($emails, function ($email) {
return $email['primary'];
});
if (count($email) === 0) {
$this->flash('Failed to sign in via GitHub, is your GitHub account verified?', Controller::FLASH_ERROR);
return redirect()->route('get::front.home');
}
$email = array_get(array_values($email)[0], 'email');
$user = $user->firstOrCreate(['uid' => $payload->id]);
$user->update(['token' => $payload->token, 'email' => $email, 'nickname' => $payload->nickname, 'name' => $payload->nickname]);
$auth->login($user, true);
return redirect()->intended('/home');
}
示例4: execute
/**
* @param boolean $hasCode
* @param AuthenticateUserListener $listener
* @param $type
* @return \Symfony\Component\HttpFoundation\RedirectResponse
*/
public function execute($hasCode, AuthenticateUserListener $listener, $type)
{
if (!$hasCode) {
return $this->getAuthorizationFirst();
}
$linkedInData = $this->getLinkedinUser();
$user = $this->users->findOrCreate($linkedInData, $type);
$this->auth->login($user, true);
$user->authType = 'linkedin';
$user->save();
if (is_null($user->profile)) {
$name = explode(' ', $linkedInData->name);
$profile = new Profile(['first_name' => head($name), 'last_name' => last($name)]);
$user->profile()->save($profile);
}
return $listener->userHasLoggedIn($user);
}
示例5: store
/**
* Store a newly created resource in storage.
*
* @param Request $request
* @return Response
*/
public function store(Request\RegisterUserRequest $request, Guard $auth)
{
//
$input = $request->only('email', 'password', 'name');
$input['password'] = bcrypt($input['password']);
$user = User::create($input);
$auth->login($user);
return redirect('/');
}
示例6: loginViaOAuth
/**
* @param SocialiteUser $oauthUserData
* @param string $provider
*
* @return bool
*/
public function loginViaOAuth(SocialiteUser $oauthUserData, $provider)
{
/** @var UserOAuth $owningOAuthAccount */
if ($owningOAuthAccount = UserOAuth::whereRemoteProvider($provider)->whereRemoteId($oauthUserData->id)->first()) {
$ownerAccount = $owningOAuthAccount->owner;
$this->auth->login($ownerAccount, true);
\Event::fire(new LoggedIn($ownerAccount, $provider));
return true;
}
return !$this->registerViaOAuth($oauthUserData, $provider) ? false : true;
}
示例7: handleProviderCallback
/**
* Obtain the user information from GitHub.
*
* @param Guard $auth
* @return Response
*/
public function handleProviderCallback(Guard $auth)
{
$userData = Socialite::driver('vkontakte')->user();
$userData->provider = "vkontakte";
$userData->name = $userData->name ?: $userData->nickname;
$userData->email = $userData->email ?: '';
$userData->avatar = $userData->avatar ?: '';
$user = User::findByUserNameOrCreate($userData);
$auth->login($user, true);
Flash::success("Выполнен вход через ВКонтакте");
return redirect('/');
}
示例8: handleProviderCallback
/**
* Obtain the user information from GitHub.
*
* @param Guard $auth
* @return Response
*/
public function handleProviderCallback(Guard $auth)
{
$userData = Socialite::driver('yandex')->user();
$userData->provider = "yandex";
$userData->name = $userData->name ?: $userData->user['display_name'];
$userData->email = $userData->email ?: $userData->user['default_email'];
$userData->avatar = $userData->avatar ?: "http://avatars.mds.yandex.net/get-yapic/" . $userData->user['default_avatar_id'] . "/islands-50";
$user = User::findByUserNameOrCreate($userData);
$auth->login($user, true);
Flash::success("Выполнен вход через Яндекс");
return redirect('/');
}
示例9: handleProviderCallback
/**
* Obtain the user information from GitHub.
*
* @param Guard $auth
* @param Registrar $registrar
* @return Response
*/
public function handleProviderCallback(Guard $auth, Registrar $registrar)
{
$user = Socialite::driver('facebook')->user();
$details = array();
$found_user = User::findByEmailOrFail($user->getEmail());
if ($found_user) {
$auth->loginUsingId($found_user->id);
return redirect()->intended('/home');
} else {
$details['name'] = $user->getName();
$details['email'] = $user->getEmail();
$details['user_type'] = 'normal';
$details['mobile_no'] = '';
$details['password'] = bcrypt(str_random(8));
$auth->login($registrar->create($details));
Session::flash('status', 'You have successfully logged in via Facebook.');
return redirect()->intended('/home');
}
return 'Success';
}
示例10: login
/**
* Log a user into the application.
*
* @param \Illuminate\Contracts\Auth\Authenticatable $user
* @param bool $remember
* @return void
* @static
*/
public static function login($user, $remember = false)
{
\Illuminate\Auth\Guard::login($user, $remember);
}
示例11: getLoginWithGithub
/**
* Handle Github login.
*
* @param \App\Facades\Github $github
* @param \Illuminate\Auth\Guard $auth
*
* @return \Illuminate\Http\RedirectResponse
*/
public function getLoginWithGithub(Github $github, Guard $auth)
{
if (!$this->request->has('state')) {
session()->keep(['url']);
Config::set('services.github.redirect', URL::full());
return Socialite::driver('github')->redirect();
} else {
try {
$user = $github->register(Socialite::driver('github')->user());
$auth->login($user);
if (session()->get('password_required')) {
return $this->redirectRoute('user.settings', [], ['update_password' => true]);
}
return $this->redirectIntended(route('user.index'));
} catch (GithubEmailNotVerifiedException $e) {
return $this->redirectRoute('auth.register', ['github_email_not_verified' => true]);
}
}
}
示例12: switchToUser
public function switchToUser($user, $remember = false)
{
$this->auth->login($user, $remember);
}