コード例 #1
0
ファイル: UserStub.php プロジェクト: Evyy/cffs-api
 public static function create()
 {
     //        return 'here';
     $faker = Factory::create();
     $identifier = UserId::generate();
     $email = Email::fromNative($faker->email);
     $first = FirstName::fromNative($faker->word);
     $last = LastName::fromNative($faker->word);
     $username = Username::fromNative($faker->word);
     $password = HashedPassword::fromNative(str_random(10));
     return User::create($identifier, $email, $first, $last, $username, $password);
 }
コード例 #2
0
ファイル: UserTest.php プロジェクト: Evyy/cffs-api
 /** @test */
 public function should_grant_and_revoke_roles()
 {
     $user = User::create($this->id, $this->email, $this->firstName, $this->lastName, $this->username, $this->password);
     $role1 = RoleStub::create();
     $role2 = RoleStub::create();
     $role3 = RoleStub::create();
     $user->grantRole($role1);
     $user->grantRole($role2);
     $user->grantRole($role3);
     $user->revokeRole($role2);
     $this->assertTrue($user->hasRole($role1));
     $this->assertTrue($role1->users()->contains($user));
     $this->assertFalse($user->hasRole($role2));
     $this->assertFalse($role2->users()->contains($user));
     $this->assertTrue($user->hasRole($role3));
     $this->assertTrue($role3->users()->contains($user));
 }
コード例 #3
0
ファイル: RegistrarService.php プロジェクト: Evyy/cffs-api
 /**
  * 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;
 }
コード例 #4
0
ファイル: UserTransformer.php プロジェクト: Evyy/cffs-api
 public function transform(User $user)
 {
     return ['id' => $user->id()->toString(), 'email' => $user->email()->toString(), 'firstName' => $user->firstName()->toString(), 'lastName' => $user->lastName()->toString(), 'username' => $user->username()->toString()];
 }
コード例 #5
0
ファイル: Token.php プロジェクト: Evyy/cffs-api
 /**
  * Create a new instance from a native form
  *
  * @param User $user
  * @return ValueObject
  */
 public static function fromUser(User $user)
 {
     return new Token($user->id());
 }