本文整理汇总了PHP中UserRepository类的典型用法代码示例。如果您正苦于以下问题:PHP UserRepository类的具体用法?PHP UserRepository怎么用?PHP UserRepository使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了UserRepository类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: viewAccountAction
/**
* GET /account(/:name).
*
* @param null|string $name
*/
public function viewAccountAction($name = null)
{
$redis = $this->app->container->get('redis.client');
$userRepository = new UserRepository($redis);
$user = $userRepository->find($name);
$jsonPath = $this->app->config('json_path') . 'users/github/' . $name . '.json';
$this->app->notFoundIf(file_exists($jsonPath) === false)->redirectUnless($name, '/profile')->render('account.html', ['account' => $user]);
}
示例2: ChangePassword
public static function ChangePassword($oldPassword, $newPassword)
{
$userRepository = new UserRepository();
$user = $userRepository->LoadWhere("Id = " . self::$userId)[0];
if ($user["Password"] == self::Encode($oldPassword)) {
$userRepository->UpdateWhere("Id = " . self::$userId, ["Password" => self::Encode($newPassword)]);
return true;
} else {
return false;
}
}
示例3: userLogin
/**
* log the user - if not exists register him/her and then log the user
*
* @return void
*/
public static function userLogin()
{
$errors = array();
$hash = addslashes(Utils::get('hash'));
if ($hash) {
$userRepository = new UserRepository();
$user = $userRepository->getOneByHash($hash);
} else {
if (Utils::post('username') != '') {
$username = addslashes(Utils::post('username'));
if (!ctype_alnum($username)) {
$errors['username'] = 'V používateľskom mene môžeš použiť len alfanumerické znaky';
// TODO localize
}
} else {
$errors['username'] = 'Musíš vyplniť používateľské meno';
// TODO localize
}
if (Utils::post('password') != '') {
$password = md5(addslashes(Utils::post('password')));
} else {
$errors['password'] = 'Musíš vyplniť heslo';
// TODO localize
}
if (empty($errors)) {
$userRepository = new UserRepository();
$userExist = $userRepository->getOneByUsername($username);
if ($userExist === NULL) {
$colorRepository = new ColorRepository();
$count = $colorRepository->getCountAll();
$rand = rand(1, $count);
$params = array('username' => $username, 'password' => $password, 'color' => $rand);
$user = new User($params);
$user = $user->save(TRUE);
} elseif ($userExist['password'] != $password) {
$errors['password'] = 'Nesprávne heslo';
} else {
$user = $userExist;
}
}
}
if ($user && empty($errors)) {
// TODO po prihlaseni treba nejako zmazat v memcachi query, ktora vybera usera podla cookie_value
// lebo teraz to stale vracia vysledok z memcache -> ked sa prihlasim v dvoch browsroch, v obidvoch to funguje
// neodhlasi ma z toho prveho
$cookieValue = md5(time() . $user['id'] . $user['username']);
DB::update(DB_PREFIX . 'user', array('cookie_value' => $cookieValue), 'id = ' . $user['id']);
$expire = Utils::post('remember') == 1 ? strtotime('+1 year') : 0;
setcookie(self::$cookieName, $cookieValue, $expire, '/');
return TRUE;
} else {
return $errors;
}
}
示例4: isSatisfiedBy
/**
* Check to see if the specification is satisfied
*
* @param Username $username
* @return bool
*/
public function isSatisfiedBy(Username $username)
{
if (!$this->repository->userOfUsername($username)) {
return true;
}
return false;
}
示例5: compose
/**
* Bind data to the view.
*
* @param View $view
* @return void
*/
public function compose(View $view)
{
if (!Cache::get('recent_posts')) {
Cache::put('recent_posts', $this->posts->getAll('published', null, 'published_at', 'desc', 5), 10);
}
$view->with('recent_posts', Cache::get('recent_posts'));
}
示例6: handleSave
public function handleSave(Form $form)
{
$values = $form->values;
if ($values['file']->isOk()) {
if ($values['cleanout']) {
foreach ($this->userRepository->findAll() as $user) {
$this->userRepository->delete($user);
}
}
/** @var FileUpload $file */
$file = $values['file'];
$data = file_get_contents($file->getTemporaryFile());
foreach (explode("\n", $data) as $row) {
if (!$row) {
continue;
}
$items = explode(',', $row);
if (!count($items)) {
continue;
}
try {
$user = new UserEntity(trim($items[0]));
} catch (InvalidArgumentException $e) {
$form->addError($e->getMessage());
}
$this->userRepository->save($user);
}
}
}
示例7: isSatisfiedBy
/**
* Check to see if the specification is satisfied
*
* @param Email $email
* @return bool
*/
public function isSatisfiedBy(Email $email)
{
if (!$this->repository->userOfEmail($email)) {
return true;
}
return false;
}
示例8: it_unfollows_another_user
/** @test */
public function it_unfollows_another_user()
{
$users = TestDummy::times(2)->create('Larabook\\Users\\User');
$this->repo->follow($users[1]->id, $users[0]);
$this->repo->unfollow($users[1]->id, $users[0]);
$this->tester->dontSeeRecord('follows', ['follower_id' => $users[0]->id, 'followed_id' => $users[1]->id]);
}
示例9: unFollowUser
/**
* UnFollow user
*
* @param $input
* @return mixed
*/
public function unFollowUser($input)
{
$user = $this->userRepo->findById($input['user_id']);
$userToUnFollow = $this->userRepo->findById($input['userIdToUnFollow']);
$this->albumRepo->unShareAllAlbums($user, $userToUnFollow);
return $this->userRepo->unFollow($input['userIdToUnFollow'], $user);
}
示例10: UpdateProfile
private function UpdateProfile(User $user)
{
$user->ChangeEmailPreference(new ReservationApprovedEvent(), $this->page->GetApproved());
$user->ChangeEmailPreference(new ReservationCreatedEvent(), $this->page->GetCreated());
$user->ChangeEmailPreference(new ReservationUpdatedEvent(), $this->page->GetUpdated());
$user->ChangeEmailPreference(new ReservationDeletedEvent(), $this->page->GetDeleted());
$this->userRepository->Update($user);
}
示例11: should_register_new_user
/** @test */
public function should_register_new_user()
{
$this->repository->shouldReceive('userOfEmail')->once()->andReturn(null);
$this->repository->shouldReceive('userOfUsername')->once()->andReturn(null);
$this->repository->shouldReceive('nextIdentity')->once()->andReturn(UserId::generate());
$this->repository->shouldReceive('add')->once();
$user = $this->service->register('name@domain.com', 'username', 'password');
$this->assertInstanceOf('Cribbb\\Domain\\Model\\Identity\\User', $user);
}
示例12: should_allow_user_to_join_the_group
/** @test */
public function should_allow_user_to_join_the_group()
{
$user = m::mock('Cribbb\\Domain\\Model\\Identity\\User');
$group = m::mock('Cribbb\\Domain\\Model\\Groups\\Group');
$group->shouldReceive('addMember')->once();
$this->users->shouldReceive('userById')->once()->andReturn($user);
$this->groups->shouldReceive('groupById')->once()->andReturn($group);
$group = $this->service->join('7c5e8127-3f77-496c-9bb4-5cb092969d89', 'a3d9e532-0ea8-4572-8e83-119fc49e4c6f');
$this->assertInstanceOf('Cribbb\\Domain\\Model\\Groups\\Group', $group);
}
示例13: authenticate
/**
* Using the given email finds the user and verifies it's password.
* If the user is not fund or if the password is wrong, it throws.
*
* @param array $credentials
* @throws AuthenticationException
* @return User|NULL
*/
public function authenticate(array $credentials)
{
list($username, $password) = $credentials;
if (!($user = $this->userRepository->findOneBy(['email' => $username]))) {
throw new AuthenticationException("User '{$username}' not found.", self::IDENTITY_NOT_FOUND);
} elseif (!$user->verifyPassword($password)) {
throw new AuthenticationException('Invalid password.', self::INVALID_CREDENTIAL);
}
return $user;
}
示例14: should_reset_password_and_return_user
/** @test */
public function should_reset_password_and_return_user()
{
$reminder = new Reminder($this->fixture['id'], $this->fixture['email'], $this->fixture['code']);
$this->reminders->shouldReceive('findReminderByEmailAndCode')->andReturn($reminder);
$this->users->shouldReceive('userOfEmail')->andReturn($this->user);
$this->hasher->shouldReceive('hash')->andReturn(new HashedPassword('qwerty123'));
$this->users->shouldReceive('update');
$this->reminders->shouldReceive('deleteReminderByCode');
$user = $this->service->reset('name@domain.com', 'qwerty123', 'abc123');
$this->assertInstanceOf('Cribbb\\Domain\\Model\\Identity\\User', $user);
}
示例15: should_register_new_user
/** @test */
public function should_register_new_user()
{
$this->repository->shouldReceive('userOfEmail')->andReturn(null);
$this->repository->shouldReceive('userOfUsername')->andReturn(null);
$this->repository->shouldReceive('nextIdentity')->andReturn($this->uuid);
$this->hashing->shouldReceive('hash')->andReturn($this->password);
$this->repository->shouldReceive('add');
$this->dispatcher->shouldReceive('dispatch');
$user = $this->service->registerUser('name@domain.com', 'username', 'password');
$this->assertInstanceOf('Cribbb\\Domain\\Model\\Identity\\User', $user);
}