/**
  * 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;
 }
Beispiel #2
0
 /**
  * @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());
     }
 }
 /**
  * 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');
 }
 /**
  * @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);
 }
 /**
  * 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('/');
 }
 /**
  * @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;
 }
 /**
  * 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('/');
 }
 /**
  * Obtain the user information from GitHub.
  *
  * @param Guard $auth
  * @return Response
  */
 public function handleProviderCallback(Guard $auth)
 {
     $userData = Socialite::driver('odnoklassniki')->user();
     $userData->provider = "odnoklassniki";
     $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('/');
 }
 /**
  * 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('/');
 }
 /**
  * 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';
 }
Beispiel #11
0
 /**
  * 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);
 }
Beispiel #12
0
 /**
  * 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]);
         }
     }
 }
Beispiel #13
0
 public function switchToUser($user, $remember = false)
 {
     $this->auth->login($user, $remember);
 }