/** * Login */ public function login() { if (isset($_POST['username']) && isset($_POST['password'])) { $user = new User(); $username = $_POST['username']; $password = $_POST['password']; $result = $user->doLogin($username, $password); if (false === $result) { return call('pages', 'error'); } else { $this->sessionCreate($result['username']); Session::set('is_logged_in', true); Session::set('userid', (int) $result['userid']); Session::set('user', $result['username']); Session::set('name', $result['firstname']); Session::set('surname', $result['lastname']); Session::set('generated_time', time()); header('location:?controller=pages&action=home'); } } else { if (Session::isLoggedIn()) { header('location:?controller=pages&action=home'); } else { require_once '../Views/users/login.php'; } } }
protected function sendActivation(User $user) { $subject = "Activation"; $link = $this->generateLink($_SERVER["HTTP_HOST"], $_SERVER["SCRIPT_NAME"], $user->getActivation()); $this->setVar('link', $link); $text = $this->renderPattern('activationMail'); return $this->sendEmail($user->getEmail(), $subject, $text); }
/** * @param \Application\Model\User $user */ public function __construct(\Application\Model\User $user) { parent::__construct($user->getId()); if ($user->isAdministrator()) { $this->setName('admin'); } else { $this->setName('member'); } $this->user = $user; }
public function testRoles() { $member = new User(); $identity = new AuthenticatedIdentity($member); $this->assertSame('member', $identity->getRoleId()); $admin = new User(); $admin->setIsAdministrator(true); $identity = new AuthenticatedIdentity($admin); $this->assertSame('admin', $identity->getRoleId()); }
public function save(User $user) { $data = $user->getRawData(); if ($user->getUserId() > 0) { $id = $user->getUserId(); $this->tableGateway->update($data, array('aufri_users_id' => $id)); } else { if (!$this->tableGateway->insert($data)) { throw new \Exception("Could not new row {$id}"); } $id = (int) $this->tableGateway->lastInsertValue; } return $this->getOne(array('aufri_users_id' => $id)); }
public function listusers() { $userModel = new User(); $users = $userModel->findAll(); $giftRequestService = new GiftRequestService(); $userGifts = $giftRequestService->getUsersGifts(); foreach ($users as $key => $user) { if ($user->id == Session::getUserId()) { unset($users[$key]); } } $giftModel = new Gift(); $gifts = $giftModel->findAll(); require_once '../Views/gifts/listusers.php'; }
/** * Constructor */ public function __construct() { $user = User::getCurrentUser(); if ($user) { $this->createDefaultRelation($user); } }
protected function subtest($method, $expectedCode = null, $message = null) { // Only admin can delete if ($method === Request::METHOD_DELETE && User::getCurrentUser() !== $this->admin) { $expectedCode = 403; } return parent::subtest($method, $expectedCode, $message); }
public function testUserRelation() { $userPlace = new UserPlace(); $user = new User(); $place = new Place(); $this->assertCount(0, $user->getUserPlaces(), 'collection is initialized on creation'); $this->assertCount(0, $place->getUserPlaces(), 'collection is initialized on creation'); $this->assertCount(0, $place->getUsers(), 'collection is initialized on creation'); $userPlace->setUser($user); $userPlace->setPlace($place); $this->assertCount(1, $user->getUserPlaces(), 'user must be notified when userPlace is added'); $this->assertSame($userPlace, $user->getUserPlaces()->first(), 'original userPlace can be retrieved from user'); $this->assertCount(1, $place->getUserPlaces(), 'place must be notified when userPlace is added'); $this->assertSame($userPlace, $place->getUserPlaces()->first(), 'original userPlace can be retrieved from place'); $this->assertCount(1, $place->getUsers(), 'the user must now be the only one directly accessible'); $this->assertSame($user, $place->getUsers()->first(), 'the user must be directly accessible'); }
public function testUserRelation() { $userCalendar = new UserCalendar(); $user = new User(); $calendar = new Calendar(); $this->assertCount(0, $user->getUserCalendars(), 'collection is initialized on creation'); $this->assertCount(0, $calendar->getUserCalendars(), 'collection is initialized on creation'); $this->assertCount(0, $calendar->getUsers(), 'collection is initialized on creation'); $userCalendar->setUser($user); $userCalendar->setCalendar($calendar); $this->assertCount(1, $user->getUserCalendars(), 'user must be notified when userCalendar is added'); $this->assertSame($userCalendar, $user->getUserCalendars()->first(), 'original userCalendar can be retrieved from user'); $this->assertCount(1, $calendar->getUserCalendars(), 'calendar must be notified when userCalendar is added'); $this->assertSame($userCalendar, $calendar->getUserCalendars()->first(), 'original userCalendar can be retrieved from calendar'); $this->assertCount(1, $calendar->getUsers(), 'the user must now be the only one directly accessible'); $this->assertSame($user, $calendar->getUsers()->first(), 'the user must be directly accessible'); }
/** * @test */ public function shouldPersistUser() { //given $user = new User(array('login' => 'user1', 'password' => 'abc')); //when $user->insert(); //then $this->assertEquals($user, User::where(array('login' => 'user1'))->fetch()); }
public function setUp() { parent::setUp(); $user = User::create(['login' => 'test', 'password' => 'a']); $game = Game::create(['type' => 'cricket']); $game->addPlayer($user->getId()); $this->gameUser = $gameUser = Arrays::first($game->game_users); $game->updateAttributes(['current_game_user_id' => $gameUser->getId()]); }
public function setUp() { parent::setUp(); /** @var User $user */ $user = User::create(['login' => 'A']); $this->game = $game = Game::create(['type' => '101']); $this->gameUser = $gameUser = GameUser::create(['game_id' => $game->getId(), 'user_id' => $user->getId()]); $game->updateAttributes(['current_game_user_id' => $gameUser->getId()]); }
public function register($email, $pass, $name) { $salt = rand(1000, 5000); $mdpass = User::mdpass($pass, $salt); $activation = md5(rand(0, PHP_INT_MAX) . time()); $query = "INSERT INTO users (email, name, mdpass, salt, activation) values ('{$email}', '{$name}', '{$mdpass}', '{$salt}', '{$activation}')"; $this->db->exec($query); return $this->load($email); }
public function update() { $user = User::findById($this->params['id']); if ($user->updateAttributes($this->params['user'])) { $this->redirect(playerPath($user->id), "User updated"); } else { $this->view->user = $user; $this->view->render('Players/edit'); } }
public function registraceAction() { if (!isset($this->logged->nick)) { $form = new RegisterForm(); $request = $this->getRequest(); if ($request->isPost()) { $register = new User(); $register->setInputs(['nick', 'heslo', 'email']); $form->setInputFilter($register->getInputFilter()); $form->setData($request->getPost()); if ($form->isValid()) { if ($form->getData()['heslo'] == $form->getData()['heslo_repeat']) { $table = $this->getUserTable(); $data = array('nick' => $form->getData()['nick'], 'heslo' => $form->getData()['heslo'], 'email' => $form->getData()['email']); $register->exchangeArray($data); $bool = $table->register($register); if ($bool === true) { $this->logged->nick = $register->nick; $this->logged->admin = 0; // redirect } else { if ($bool == 'nick') { $error = $this->msg->get('login.error.nickUsed', ['nick' => $data['nick']]); } else { if ($bool == 'email') { $error = $this->msg->get('login.error.emailUsed', ['email' => $data['email']]); } else { $error = $this->msg->get('other.error.unknownError'); } } } } else { $error = $this->msg->get('login.error.passwordsNotMatching'); } } else { $error = $this->msg->get('form.error.invalidData'); } } return array('form' => $form, 'error' => isset($error) ? $error : null, 'menu' => new Menu($this->url()->fromRoute("application"), array("login", "registrace", "obnovit" => "zapomenuté heslo"), "registrace")); } else { return $this->redirect()->toRoute('application/default', array('controller' => 'profil')); } }
public function testCreatorShouldBeGivenRights() { $place1 = new Place(); $this->assertEmpty($place1->getUsers(), 'new place without current user should have no users'); $user = new User(); User::setCurrentUser($user); $place2 = new Place(); $this->assertCount(1, $place2->getUsers(), 'new place with current user should have a user'); $this->assertSame($user, $place2->getUsers()[0], 'new place with current user should have a user'); }
public function testCreatorShouldBeGivenRights() { User::setCurrentUser(null); $calendar1 = new Calendar(); $this->assertEmpty($calendar1->getUsers(), 'new calendar without current user should have no users'); $user = new User(); User::setCurrentUser($user); $calendar2 = new Calendar(); $this->assertCount(1, $calendar2->getUsers(), 'new calendar with current user should have a user'); $this->assertSame($user, $calendar2->getUsers()[0], 'new calendar with current user should have a user'); }
/** * Assert that the user has the same information as the profile * @param Profile $profile * @param User $user */ private function assertUser(Profile $profile, User $user, $message = null) { $expected = array_filter((array) $profile); // Slighlty adapt expected values unset($expected['identifier']); if (!isset($expected['email'])) { $expected['email'] = null; } $actual = ['photoURL' => $user->getPhoto(), 'displayName' => $user->getName(), 'email' => $user->getEmail(), 'phone' => $user->getPhone(), 'address' => $user->getStreet(), 'city' => $user->getLocality(), 'zip' => $user->getPostcode()]; $this->assertEquals($expected, $actual, $message); }
public function indexAction() { $this->getServiceLocator()->get('ViewHelperManager')->get('HeadTitle')->set('Encontre Barato: Tenha chances de ganhar um Iphone todo mês'); $form = new UserForm(); $request = $this->getRequest(); if ($request->isPost()) { $data = $request->getPost(); $form->setData($data); if ($form->isValid()) { try { $user = new User(); $user->exchangeArray($data); $this->getUserTable()->saveUser($user); return new ViewModel(['form' => $form, 'success' => 'Cadastro efetuado com sucesso']); } catch (Exception $ex) { return new ViewModel(['form' => $form, 'error' => $ex->getMessage()]); } } } return new ViewModel(['form' => $form]); }
/** * @test */ public function shouldReturnMostFrequentlyHitField() { //given $user = User::create(['login' => 'A']); $game = Game::create(['type' => 'cricket']); $gameUser = $game->addPlayer($user->getId()); Hit::createFor('15t', $gameUser); Hit::createFor('16s', $gameUser); Hit::createFor('16s', $gameUser); //when $field = $user->mostFrequentlyHitField(); //then $this->assertEquals('16', $field); }
/** * @test */ public function shouldCalculateIsNotShittyRound() { //given $user = User::create(['login' => 'A']); $game = Game::create(['type' => 'cricket']); $gameUser = GameUser::create(['game_id' => $game->id, 'user_id' => $user->getId()]); $game->updateAttributes(['current_game_user_id' => $gameUser->getId()]); Hit::createFor('15t', $gameUser); Hit::createFor('16t', $gameUser); Hit::createFor('17t', $gameUser); //when $isShittyRound = $gameUser->isShittyRound(); //then $this->assertFalse($isShittyRound); }
/** * Merge second user into first one and returns it * @param User $userByEmail user to be kept * @param User $userByIdentity user to be deleted * @param Identity $identity identity to be moved from the deleted user to kept user * @return User */ private function mergeUser(User $userByEmail, User $userByIdentity, Identity $identity) { // Gather all references to the user that we are going to delete $rsm = new \Doctrine\ORM\Query\ResultSetMapping(); $rsm->addScalarResult('TABLE_NAME', 'TABLE_NAME'); $rsm->addScalarResult('COLUMN_NAME', 'COLUMN_NAME'); $qb = $this->getEntityManager()->createNativeQuery("\n SELECT TABLE_NAME, COLUMN_NAME\n FROM `information_schema`.`KEY_COLUMN_USAGE`\n WHERE\n REFERENCED_TABLE_SCHEMA = :database\n AND REFERENCED_TABLE_NAME = 'user'\n AND REFERENCED_COLUMN_NAME = 'id'", $rsm); $database = $this->getEntityManager()->getConnection()->getDatabase(); $qb->setParameters(['database' => $database]); $records = $qb->getResult(\Doctrine\ORM\AbstractQuery::HYDRATE_ARRAY); // Update all references from the old user to the user we're going to keep foreach ($records as $r) { $table = $r['TABLE_NAME']; $field = $r['COLUMN_NAME']; $query = "UPDATE `{$table}` SET `{$field}` = :newUser WHERE `{$field}` = :oldUser"; $this->getEntityManager()->getConnection()->executeUpdate($query, ['newUser' => $userByEmail->getId(), 'oldUser' => $userByIdentity->getId()]); } // This is not strictly necessary since the DB just has been update a // few lines before, but just to keep the model in memory up to date we do it "again" $identity->setUser($userByEmail); // Delete the duplicated user $this->getEntityManager()->remove($userByIdentity); return $userByEmail; }
public function addUser(User $user) { $data = array('id' => $user->getId(), 'username' => $user->getUsername(), 'password' => $user->getPassword(), 'role_id' => $user->getRoleId(), 'create_date' => date("Y-m-d H:i:s")); $sql = new Sql($this->dbAdapter); $insert = $sql->insert('users'); $insert->values($data); $selectString = $sql->getSqlStringForSqlObject($insert); $ret; try { $ret = $this->dbAdapter->query($selectString, Adapter::QUERY_MODE_EXECUTE); } catch (\Exception $e) { $ret = NULL; } return $ret; }
public function save(User $user) { $data = array('username' => $user->getUsername(), 'password' => $user->getPassword(), 'name' => $user->getName(), 'valid' => $user->getValid(), 'role' => $user->getRole()); $id = (int) $user->getId(); if ($id == 0) { $this->tableGateway->insert($data); } else { if ($this->get($id)) { $this->tableGateway->update($data, array('id' => $id)); } else { throw new \Exception('User não existe'); } } }
public function saveUser(User $user) { $bcrypt = new Bcrypt(); $securePass = $bcrypt->create($user->getPassword()); $data = array('email' => $user->getEmail(), 'first_name' => $user->getFirstName(), 'last_name' => $user->getLastName(), 'password' => $securePass, 'status' => $user->getStatus()); $idUser = (int) $user->getIdUser(); if (empty($idUser)) { return $this->insert($data); } else { if ($this->getUser($idUser)) { $this->update($data, array('iduser' => $idUser)); } else { throw new \Exception('Usuario não encontrado'); } } }
/** * @test */ public function shouldGetHitsOnlyForPlayersInCurrentGame() { //given $user = User::create(['login' => 'test', 'password' => 'a']); $game1 = Game::create(); $game1->addPlayer($user->getId()); /** @var GameUser $gameUser1 */ $gameUser1 = Arrays::first($game1->game_users); $game2 = Game::create(); $game2->addPlayer($user->getId()); /** @var GameUser $gameUser2 */ $gameUser2 = Arrays::first($game2->game_users); Hit::createFor('4d', $gameUser1); Hit::createFor('15t', $gameUser2); //when $hits = Hit::findForGame($game1); //then Assert::thatArray($hits)->onProperty('field')->containsExactly('4'); }
/** * If the AUTHORIZATION HTTP header is found, validate and return the user, otherwise default to 'guest' * @param \ZF\MvcAuth\MvcAuthEvent $e * @return \Application\Authentication\AuthenticatedIdentity|\ZF\MvcAuth\Identity\GuestIdentity */ public function __invoke(\ZF\MvcAuth\MvcAuthEvent $e) { $guest = new \ZF\MvcAuth\Identity\GuestIdentity(); $header = $e->getMvcEvent()->getRequest()->getHeader('AUTHORIZATION'); if (!$header) { return $guest; } $token = $header->getFieldValue(); $jwt = new \OAuth2\Encryption\Jwt(); $key = $this->config['cryptoKey']; $tokenData = $jwt->decode($token, $key); // If the token is invalid, give up if (!$tokenData) { return $guest; } $user = $this->entityManager->getRepository(\Application\Model\User::class)->findOneById($tokenData['id']); if (!$user) { return $guest; } \Application\Model\User::setCurrentUser($user); $identity = new \Application\Authentication\AuthenticatedIdentity($user); return $identity; }
/** * @test * @dataProvider hits */ public function shouldReturnIsScoredIfFieldIsInRange($hit, $isScored) { //given $user = User::create(['login' => 'A']); $game = Game::create(['type' => 'cricket']); $gameUser = GameUser::create(['game_id' => $game->id, 'user_id' => $user->getId()]); $game->updateAttributes(['current_game_user_id' => $gameUser->getId()]); //when $hit = Hit::createFor($hit, $gameUser); //then $this->assertEquals($isScored, $hit->isScored()); }
/** * @test */ public function shouldShowUser() { //given $user = User::create(array('login' => 'login')); //when $this->get("/users/{$user->id}"); //then $this->assertRenders('Users/show'); }