public function userInit() { $user = null; $email = $this->userValues["contact"]["email"]; try { $user = $this->userService->getUserEmail($email); } catch (Exceptions\NoResultException $ex) { $this->logger->addDebug($ex); } if ($user === null) { $this->logger->addInfo("Users module initializer - User - no user with email {$email} found. New one is gonna be created."); $addrValues = $this->userValues["contact"]["address"]; $address = new Address((array) $addrValues); $address->applyAccountNumber($this->userValues["contact"]["address"]["accountNumber"]); $address->applyIdentificationNumber($this->userValues["contact"]["address"]["identificationNumber"]); $address->applyTaxIdentificationNumber($this->userValues["contact"]["address"]["taxIdentificationNumber"]); $contValues = $this->userValues["contact"]; $contact = new Contact((array) $contValues); $contact->setAddress($address); $userValues = $this->userValues; unset($userValues["contact"]); $user = new User((array) $userValues); $user->setActive(true); $user->setContact($contact); $user->setBirthNumber("0000000000"); $this->userService->createUser($user); } }
public function testAuthenticateSuccess() { $role = new Role('customer', null); $user = new User('*****@*****.**', 'john', 'John', 'Smith', 'password'); $user->activate(); $user->addRole($role); $identity = $this->authenticator->authenticate(['authenticator' => Authenticator::AUTH_EMAIL, 'user' => $user, 'password' => 'password']); $this->assertEquals(new Identity(null, ['customer']), $identity); }
/** * Hydrate User entity from UserForm * @param \Nette\ArrayHash $values * @return \App\Model\Entities\User */ public static function hydrateUserFromHash(ArrayHash $values) { $nu = new User(); $nu->fromArray((array) $values); $na = new Address(); $na->fromArray((array) $values); $nc = new Contact(); $nc->fromArray((array) $values); $nc->setAddress($na); $nu->setContact($nc); return $nu; }
/** * @param User|int $recipient */ private function setRecipient($recipient) { if ($recipient instanceof User and !$recipient->isDetached()) { $this->assignEntityToProperty($recipient, 'recipient'); } else { if (Validators::is($recipient, 'numericint')) { $this->row->recipient = $recipient; $this->row->cleanReferencedRowsCache('user', 'recipient'); } else { throw new InvalidArgumentException('Argument $recipient can by only instance of App\\Entities\\User or integer number.'); } } }
/** * @param \App\Model\Entities\User|int $user * @return int */ protected function getUserID($user) { $id = null; if ($user instanceof User and !$user->isDetached()) { $id = $user->userID; } else { if (Validators::is($user, 'numericint')) { $id = $user; } else { throw new InvalidArgumentException('Argument $user must be instance of ' . User::class . ' or integer number.'); } } return $id; }
public function processChangePassword(Form $form) { $values = $form->getValues(); if ($this->user->email != $values['email']) { $this->flashMessage('<strong>Chyba!</strong> Vámi zadaný E-mail nesouhlasí s E-mailem, na který byl zaslán požadavek o změnu hesla!', 'error'); $this->redirect('this'); } try { $this->user->resetToken(); $this->user->password = $values['password']; $this->userManager->saveUser($this->user); } catch (\DibiException $e) { $this->flashMessage('<strong>Chyba!</strong> Při pokusu o změnu hesla došlo k chybě. Na nápravě se pracuje. Zkuste to prosím později.', 'error'); $this->redirect('this'); } $this->flashMessage('<strong>Úspěch!</strong> Heslo bylo změněno. Nyní se můžete přihlásit.', 'success'); $this->redirect('Account:default'); }
public function getUserRoles(User $user, $useCache = true) { if ($user === null) { throw new NullPointerException("Argument User cannot be null"); } try { if (!$useCache) { return $this->positionDao->findBy(array("owner" => $user->getId())); } $id = User::getClassName() . "-" . $user->getId(); $cache = $this->getEntityCache(); $data = $cache->load($id); if ($data === null) { $coll = $this->positionDao->findBy(array("owner" => $user->getId())); foreach ($coll as $p) { $data[] = $p->getRole()->getName(); } $opts = [Cache::TAGS => [self::ENTITY_COLLECTION, $id], Cache::SLIDING => true]; $cache->save($id, $data, $opts); } return $data; } catch (\Exception $e) { $this->logError($e); throw new Exceptions\DataErrorException($e->getMessage(), $e->getCode(), $e->getPrevious()); } }
/** * @param User $user * @param Invitation $invitation * @return void * @throws Runtime\DuplicateUsernameException * @throws Runtime\DuplicateEmailException * @throws Runtime\InvitationNotFoundException * @throws Runtime\InvitationExpiredException * @throws Runtime\InvitationTokenMatchException * @throws \DibiException */ public function registerNewUser(User $user, Invitation $invitation) { if (!$user->isDetached()) { throw new InvalidArgumentException('Only detached instances of Entity ' . User::class . ' can pass.'); } $this->checkInvitation($user->email, $invitation->token); try { $this->transaction->begin(); $this->userRepository->persist($user); $this->removeInvitation($invitation); $this->transaction->commit(); } catch (\DibiException $e) { if ($e->getCode() == 1062) { try { $this->userRepository->checkUsername($user->username); } catch (Runtime\UserAlreadyExistsException $usernameException) { $this->transaction->rollback(); throw new Runtime\DuplicateUsernameException(); } try { $this->userRepository->checkEmail($user->email); } catch (Runtime\UserAlreadyExistsException $emailException) { $this->transaction->rollback(); throw new Runtime\DuplicateEmailException(); } } $this->transaction->rollback(); Debugger::log($e, Debugger::ERROR); throw $e; } }
public function getUsersApplication(User $u, Season $s) { try { $id = "{$this->getEntityClassName()}/{$u->getId()}-{$s->getId()}"; $cache = $this->getEntityCache(); $data = $cache->load($id); if ($data === null) { $data = $this->seasonApplicationDao->createQueryBuilder("a")->where("a.owner = :owner")->setParameter("owner", $u->getId())->andWhere("a.season = :season")->setParameter("season", $s->getId())->getQuery()->getSingleResult(); $opts = [Cache::TAGS => [self::ENTITY_COLLECTION, $id]]; $cache->save($id, $data, $opts); } return $data; } catch (\Exception $ex) { $this->logError($ex->getMessage()); throw new Exceptions\DataErrorException($ex->getMessage(), $ex->getCode(), $ex->getPrevious()); } }
public function changeWebProfile(User $u) { try { $wp = $u->getWebProfile(); $user = $this->userDao->find($u->getId()); if ($wp->getPicture() instanceof \Nette\Http\FileUpload && $wp->getPicture()->isOk()) { $oldImgId = $wp->provideOldImgId(); $this->imageService->removeResource($oldImgId); $identifier = $this->imageService->storeNetteFile($wp->getPicture()); $wp->setPicture($identifier); } $this->entityManager->flush(); } catch (\Exception $ex) { $this->logError($ex->getMessage()); throw new Exceptions\DataErrorException($ex->getMessage(), $ex->getCode(), $ex->getPrevious()); } }
public function getUserEventsDatasource(User $u) { $model = new Doctrine($this->participationDao->createQueryBuilder()->select("ep, ev.title AS title, ev.takePlaceSince as takePlaceSince, ev.takePlaceTill AS takePlaceTill, ev.eventType AS eventType")->add("from", EventParticipation::getClassName() . " ep LEFT JOIN ep.event ev")->where("ep.owner = :owner")->setParameter("owner", $u->getId())); return $model; }
public function testActivate() { $this->user->activate(); $this->assertEquals('*****@*****.**', $this->user->getEmail()); $this->assertEquals('john', $this->user->getUsername()); $this->assertEquals('John', $this->user->getName()); $this->assertEquals('Smith', $this->user->getSurname()); $this->assertNotEmpty($this->user->getPassword()); $this->assertEmpty($this->user->getCode()); $this->assertFalse($this->user->isFrozen()); $this->assertInstanceOf(DateTime::class, $this->user->getCreatedAt()); $this->assertInstanceOf(ReadOnlyCollectionWrapper::class, $this->user->getRoles()); }
public function notifyNewPassword(User $u) { $subjKey = "systemModule.notification.newPassword.subject"; $bodyKey = "systemModule.notification.newPassword.body"; $subject = $this->translator->translate($subjKey, null, ["host" => $this->getHostName()]); $body = $this->translator->translate($bodyKey, null, ["name" => $u->getName(), "surname" => $u->getSurname(), "pass" => $u->provideRawPassword()]); $mail = new Message(); $mail->setFrom($this->getSenderEmail())->setSubject($subject)->setBody($body)->addTo($u->getContact()->getEmail()); $this->send($mail); }
/** * @param User $user * @return array Vychozi hodnoty pro formular */ protected function getDefaults($user) { $result = []; $result['id'] = $user->getId(); $result['user']['login'] = $user->getLogin(); $result['user']['role'] = $user->getRole(); $person = $user->person; if ($person) { $result['person']['name'] = $person->name; $result['person']['surname'] = $person->surname; } return $result; }
public function getPositionsWithinGroup(SportGroup $g, $useCache = true) { try { $qb = $this->positionDao->createQueryBuilder(); $qb->select("p")->from("App\\Model\\Entities\\Position", "p")->where("p.group = :group")->setParameter("group", $g); $q = $qb->getQuery(); if (!$useCache) { return $q->getResult(); } $id = User::getClassName() . "in" . SportGroup::getClassName() . "-" . $g->getId(); $cache = $this->getEntityCache(); $data = $cache->load($id); if ($data == null) { $data = $q->getResult(); $opts = [Cache::TAGS => [self::ENTITY_COLLECTION, self::STRANGER_COLLECTION, $id], Cache::SLIDING => true]; $cache->save($id, $data, $opts); } return $data; } catch (\Exception $e) { $this->logError($e); throw new Exceptions\DataErrorException($e->getMessage(), $e->getCode(), $e->getPrevious()); } }
/** * Checks if specified email is free * * @param User $user * @param string $email * * @return boolean */ public function isEmailFree(User $user, $email) { return $this->createQuery('SELECT COUNT(u) FROM ' . User::class . ' u WHERE u.id != ?0 AND u.email = ?1')->setParameters([(string) $user->getId(), $email])->getSingleScalarResult() == 0; }
public function getPaymentsDatasource(User $u = null) { $model = $this->paymentDao->createQueryBuilder('pa'); if ($u !== null) { $model->where("pa.owner = :id")->setParameter("id", $u->getId()); } return new Doctrine($model); }