Ejemplo n.º 1
0
 /**
  * Register a new user using their Github account.
  *
  * @param string $code
  *
  * @return \App\User
  */
 public function register($userDetails)
 {
     $userDetails->email = $userDetails->getEmail();
     $profile = $this->profiles->findByUid($userDetails->getId());
     if (is_null($profile)) {
         $user = $this->users->findByEmail($userDetails->email);
         if (is_null($user)) {
             $user = $this->users->createFromGithubData($userDetails);
         }
         $profile = $this->profiles->createFromGithubData($userDetails, $user, $userDetails->token);
     } else {
         $profile = $this->profiles->updateToken($profile, $userDetails->token);
         $user = $profile->user;
     }
     return $user;
 }
 /**
  * Store user to the session / Authenticate
  * 
  * @return Response
  */
 public function store(Request $request, UserRepositoryInterface $userRepository)
 {
     $input = $request->only(['email', 'password']);
     $user = $userRepository->findByEmail($input['email']);
     if ($user) {
         if (!$user->confirmed) {
             return $this->sendUnauthorized('Invalid credentials.');
         }
     }
     if (!Auth::attempt($input)) {
         return $this->sendUnauthorized('Invalid credentials.');
     }
     return $this->sendSuccess([], 'Successfully logged in.');
 }
 public function renew($email, $token, ResetPasswordRequest $resetPasswordRequest, UserRepositoryInterface $userRepository, TokenRepositoryInterface $tokenRepository)
 {
     $input = $resetPasswordRequest->all();
     $user = $userRepository->findByEmail($email);
     if (!$user) {
         return $this->sendUnauthorized('Email not found.');
     }
     if (!$tokenRepository->exists($user, $token)) {
         return $this->sendUnauthorized('Invalid token.');
     }
     $user = $userRepository->changePassword($user, $input['password']);
     $tokenRepository->delete($token);
     return $this->sendSuccess([], 'Successfully reset your password. Now try logging in.');
 }