Example #1
0
 /**
  * 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;
 }
 /**
  * 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'));
 }
 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);
         }
     }
 }
Example #4
0
 /**
  * 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;
 }
Example #5
0
 /** @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]);
 }
 /**
  * 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);
 }
Example #7
0
 /**
  * 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]);
 }
 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);
 }
Example #9
0
 /** @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('*****@*****.**', 'username', 'password');
     $this->assertInstanceOf('Cribbb\\Domain\\Model\\Identity\\User', $user);
 }
Example #10
0
 /** @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);
 }
Example #11
0
 /**
  * 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;
 }
 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;
     }
 }
Example #13
0
 /**
  * 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'] = '******';
                 // TODO localize
             }
         } else {
             $errors['username'] = '******';
             // TODO localize
         }
         if (Utils::post('password') != '') {
             $password = md5(addslashes(Utils::post('password')));
         } else {
             $errors['password'] = '******';
             // 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'] = '******';
             } 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;
     }
 }
Example #14
0
 /** @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('*****@*****.**', 'qwerty123', 'abc123');
     $this->assertInstanceOf('Cribbb\\Domain\\Model\\Identity\\User', $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('*****@*****.**', 'username', 'password');
     $this->assertInstanceOf('Cribbb\\Domain\\Model\\Identity\\User', $user);
 }
Example #16
0
 /** @test */
 public function should_create_new_post()
 {
     $user = m::mock('Cribbb\\Domain\\Model\\Identity\\User');
     $thread = m::mock('Cribbb\\Domain\\Model\\Discussion\\Thread');
     $post = m::mock('Cribbb\\Domain\\Model\\Discussion\\Post');
     $this->users->shouldReceive('userById')->once()->andReturn($user);
     $this->threads->shouldReceive('threadById')->once()->andReturn($thread);
     $thread->shouldReceive('createNewPost')->once()->andReturn($post);
     $this->posts->shouldReceive('add')->once();
     $post = $this->service->create('7c5e8127-3f77-496c-9bb4-5cb092969d89', 'a3d9e532-0ea8-4572-8e83-119fc49e4c6f', 'Hello World');
     $this->assertInstanceOf('Cribbb\\Domain\\Model\\Discussion\\Post', $post);
 }
Example #17
0
 /** @test */
 public function should_create_new_thread()
 {
     $user = m::mock('Cribbb\\Domain\\Model\\Identity\\User');
     $group = m::mock('Cribbb\\Domain\\Model\\Groups\\Group');
     $thread = m::mock('Cribbb\\Domain\\Model\\Discussion\\Thread');
     $this->users->shouldReceive('userById')->once()->andReturn($user);
     $this->groups->shouldReceive('groupById')->once()->andReturn($group);
     $group->shouldReceive('startNewThread')->once()->andReturn($thread);
     $this->threads->shouldReceive('add')->once();
     $thread = $this->service->create('7c5e8127-3f77-496c-9bb4-5cb092969d89', 'a3d9e532-0ea8-4572-8e83-119fc49e4c6f', 'Hello World');
     $this->assertInstanceOf('Cribbb\\Domain\\Model\\Discussion\\Thread', $thread);
 }
 protected function startup()
 {
     parent::startup();
     if ($this->key) {
         if (($user = $this->userRepository->findOneBy(array('userKey' => $this->key))) === NULL) {
             throw new BadRequestException();
         }
         $this->userRepository->delete($user);
         $this->flashMessage('Byl jste odhlášen z newsletteru.', 'success');
         $this->redirect('this', array('key' => NULL));
     }
 }
 /**
  * {@inheritdoc}
  */
 public function validate($review, Constraint $constraint)
 {
     $customer = $review->getAuthor();
     $token = $this->tokenStorage->getToken();
     if ($this->checkIfUserIsAuthenticated($token)) {
         if (null !== $customer && $token->getUser()->getCustomer()->getEmail() === $customer->getEmail()) {
             return;
         }
     }
     if (null !== $customer && null !== $this->userRepository->findOneByEmail($customer->getEmail())) {
         $this->context->addViolationAt('author', $constraint->message, [], null);
     }
 }
Example #20
0
 /** @test */
 public function should_reset_password_and_return_user()
 {
     $reminder = m::mock('Cribbb\\Domain\\Model\\Identity\\Reminder');
     $reminder->shouldReceive('isValid')->andReturn(true);
     $this->reminders->shouldReceive('findReminderByEmailAndCode')->andReturn($reminder);
     $user = m::mock('Cribbb\\Domain\\Model\\Identity\\User');
     $this->users->shouldReceive('userOfEmail')->once()->andReturn($user);
     $user->shouldReceive('resetPassword')->once();
     $this->users->shouldReceive('update')->once();
     $this->reminders->shouldReceive('deleteReminderByCode')->once();
     $user = $this->service->reset('*****@*****.**', 'password', 'abc123');
     $this->assertInstanceOf('Cribbb\\Domain\\Model\\Identity\\User', $user);
 }
Example #21
0
 /**
  * Bind data to the view.
  *
  * @param  View  $view
  * @return void
  */
 public function compose(View $view)
 {
     $locale = Session::get('locale');
     $header_id = $this->menu->getMenuID('header');
     $header = '';
     $header_items = $this->link->getLinks($header_id, $locale);
     //dd($header_items);
     if ($header_items->count()) {
         $menu = new MenuLink();
         $header_links = $this->link->getHTML($header_items, $locale);
     }
     //dd($header_links);
     $view->with('header_links', $header_links);
 }
Example #22
0
 /**
  * Fire the upload action
  *
  * @return Response
  */
 public function fire()
 {
     // Target path
     $tmpPath = Config::get('krustr::media.tmp_path');
     $tmpUrl = Config::get('krustr::media.tmp_url');
     // Custom location
     if ($custom = Input::get('custom')) {
         $tmpDir = 'tmp_' . str_replace("-", "_", $custom) . '_' . uniqid() . '/';
         $tmpPath .= $tmpDir;
         $tmpUrl .= $tmpDir;
     }
     // Run upload actions
     $reponse = $this->upload->fire(Input::file('file'), $tmpPath, array('tmp_url' => $tmpUrl));
     return Response::json($reponse);
 }
Example #23
0
 /**
  * @param boolean $hasCode
  * @param AuthenticateUserListener $listener
  * @return \Symfony\Component\HttpFoundation\RedirectResponse
  */
 public function execute($hasCode, $provider, AuthenticateUserListener $listener)
 {
     $this->provider = $provider;
     if (!$hasCode) {
         return $this->getAuthorizationFirst();
     }
     $result = $this->getSocialUser();
     if ($result['success']) {
         $user = $this->users->findByUsernameOrCreate($result['user'], $this->provider);
         $this->auth->login($user, true);
         return $listener->userHasLoggedIn($user);
     } else {
         return $listener->userLoggedInFailed($result);
     }
 }
Example #24
0
 /**
  * @param array $credentials
  * @return UserTable|Nette\Security\IIdentity
  * @throws \Nette\Security\AuthenticationException
  */
 public function authenticate(array $credentials)
 {
     list($username, $password) = $credentials;
     $query = $this->userRepository->createQuery();
     $query->where('@login', $username);
     try {
         $user = $this->userRepository->findOneBy($query);
     } catch (NotFoundException $e) {
         throw new Nette\Security\AuthenticationException('The username is incorrect.', self::IDENTITY_NOT_FOUND);
     }
     if (!$user->isPasswordValid($password)) {
         throw new Nette\Security\AuthenticationException('The password is incorrect.', self::INVALID_CREDENTIAL);
     }
     return $user;
 }
 public function handleExport()
 {
     $ret = array();
     foreach ($this->repository->findAll() as $user) {
         $ret[] = array($user->email, $user->userKey);
     }
     $out = "";
     foreach ($ret as $arr) {
         $out .= implode(',', $arr) . "\n";
     }
     header('Content-Type: application/csv, utf-8');
     header('Content-Disposition: attachment;filename="users.csv"');
     header('Cache-Control: max-age=0');
     $this->presenter->sendResponse(new TextResponse($out));
 }
 public function __construct()
 {
     parent::__construct();
     $this->create_guest_account = function () {
         return UserRepository::createWithRoles(['UserID' => 1, 'Name' => 'Anonymous', 'Password' => str_random(64), 'HashMethod' => 'random'], [RoleRepository::member()]);
     };
 }
 public function testGetsAllUsers()
 {
     $users = array(new UserDto(1, 'f', 'l', 'e'));
     $this->userRepo->expects($this->once())->method('GetAll')->will($this->returnValue($users));
     $this->page->expects($this->once())->method('SetJsonResponse')->with($this->equalTo($users));
     $this->presenter->ProcessDataRequest('all');
 }
 public function ShowUserAttributes()
 {
     // User attributes on Dashboard, Added by Burak C.
     $userId = ServiceLocator::GetServer()->GetUserSession()->UserId;
     $userRepository = new UserRepository();
     $this->user = $userRepository->LoadById($userId);
     $attributeService = new AttributeService(new AttributeRepository());
     $attributes = $attributeService->GetByCategory(CustomAttributeCategory::USER);
     $reservationViewRepository = new ReservationViewRepository();
     $startDate = Date::Now();
     $endDate = $startDate->AddDays(30);
     $reservations = $reservationViewRepository->GetReservationList($startDate, $endDate, $userId, ReservationUserLevel::INVITEE);
     $this->_page->Set("invitations", $reservations);
     $this->_page->Set("user", $this->user);
     $this->_page->Set("attributes", $attributes);
 }
Example #29
0
 public function SendRandomPassword()
 {
     $emailAddress = $this->_page->GetEmailAddress();
     Log::Debug('Password reset request for email address %s requested from REMOTE_ADDR: %s REMOTE_HOST: %s', $emailAddress, $_SERVER['REMOTE_ADDR'], $_SERVER['REMOTE_HOST']);
     $temporaryPassword = Password::GenerateRandom();
     $passwordEncryption = new PasswordEncryption();
     $salt = $passwordEncryption->Salt();
     $encrypted = $passwordEncryption->Encrypt($temporaryPassword, $salt);
     $userRepository = new UserRepository();
     $user = $userRepository->FindByEmail($emailAddress);
     if ($user != null) {
         $user->ChangePassword($encrypted, $salt);
         $userRepository->Update($user);
         $emailMessage = new ForgotPasswordEmail($user, $temporaryPassword);
         ServiceLocator::GetEmailService()->Send($emailMessage);
     }
 }
 /**
  * @param int $userId
  * @return User|void
  */
 public function LoadById($userId)
 {
     $user = parent::LoadById($userId);
     $me = parent::LoadById($this->userSession->UserId);
     if ($userId == $this->userSession->UserId || $me->IsAdminFor($user)) {
         return $user;
     }
     return User::Null();
 }