Esempio n. 1
0
 public function loginWithCredentials($form)
 {
     $credentials = Credentials::fromNative($form['email'], $form['password']);
     $user = $this->findUserByEmail($credentials->email());
     if ($this->hashingService->check($credentials->password(), $user->password())) {
         return $user;
     }
     throw new UnauthorizedException('user_password_incorrect');
 }
Esempio n. 2
0
 /** @test */
 public function should_register_new_user()
 {
     $this->repository->shouldReceive('userOfEmail')->andReturn(null);
     $this->repository->shouldReceive('userOfUsername')->andReturn(null);
     $this->repository->shouldReceive('nextIdentity')->andReturn(UserId::generate());
     $this->hashing->shouldReceive('hash')->andReturn(new HashedPassword('password'));
     $this->repository->shouldReceive('add');
     $user = $this->registrar->register('*****@*****.**', 'First', 'Last', 'username', 'password');
     $this->assertInstanceOf(User::class, $user);
 }
Esempio n. 3
0
 /**
  * Reset a user's password
  *
  * @param string $email
  * @param string $password
  * @param string $code
  * @throws InvalidValueException
  * @return User;
  */
 public function reset($email, $password, $code)
 {
     if ($this->check($email, $code)) {
         $user = $this->findUserByEmail(Email::fromNative($email));
         $password = $this->hasher->hash(new Password($password));
         $user->resetPassword($password);
         $this->users->update($user);
         $this->reminders->deleteReminderByCode(ReminderCode::fromNative($code));
         return $user;
     }
     throw new InvalidValueException("{$code} is not a valid reminder code");
 }
Esempio n. 4
0
 /**
  * register
  * @param $email
  * @param $firstName
  * @param $lastName
  * @param $username
  * @param $password
  * @return User
  * @throws ValueIsNotUniqueException
  */
 public function register($email, $firstName, $lastName, $password)
 {
     $email = new Email($email);
     $firstName = new FirstName($firstName);
     $lastName = new LastName($lastName);
     $password = new Password($password);
     $id = $this->userRepository->nextIdentity();
     $password = $this->hashingService->hash($password);
     $username = $this->generateUsername($firstName, $lastName);
     $user = User::create($id, $email, $firstName, $lastName, $username, $password);
     $userRepo = $this->userRepository;
     $args = compact("user", "userRepo");
     //        $emailGuard = new UserEmailIsUniqueGuard($this->userRepository);
     //        $usernameGuard = new UsernameIsUniqueGuard($this->userRepository);
     //        $emailGuard->handle($args);
     //        $usernameGuard->handle($args);
     //          Not sure how to test with this
     //        Guard trait will inject from app container
     //        Maybe could try service provider gymnastics
     $this->guard([UserEmailIsUniqueGuard::class, UsernameIsUniqueGuard::class], $args);
     $this->userRepository->add($user);
     return $user;
 }