Example #1
0
 public function getEmptyUserAction()
 {
     $userGroup = $this->app->entityManager->getRepository(EntityNames::USER_GROUP)->findOneBy(array('name' => 'ROLE_USER'));
     $user = new User();
     $user->setUserGroup($userGroup);
     ResponseFactory::createJsonResponse($this->app, $user);
 }
 /**
  * Registers the given user and starts the registration process.
  * <b>Note that any entity associated with the user object
  * must be stored beforehand in the database.</b>
  *
  * @param User $user The user to store
  * @throws UserNotSavedException Thrown if a problem occurred during saving of the user
  */
 public function registerUser(User &$user)
 {
     $expirationDate = new DateTime();
     $expirationDate->add(new DateInterval('PT48H'));
     $token = hash('sha256', sprintf('%s%s%s', $user->getFirstName(), $user->getLastName(), $expirationDate->format('Y-m-d H:i:s')));
     $registration = new Registration();
     $registration->setUser($user);
     $registration->setExpirationDate($expirationDate);
     $registration->setToken($token);
     $settingsRepo = $this->entityManager->getRepository(EntityNames::SETTING);
     $websiteName = $settingsRepo->findOneBy(array('name' => 'website_name'));
     $websiteEmail = $settingsRepo->findOneBy(array('name' => 'website_email'));
     $websiteReplyToEmail = $settingsRepo->findOneBy(array('name' => 'website_reply_to_email'));
     $websiteUrl = $settingsRepo->findOneBy(array('name' => 'website_url'));
     $registrationLink = $this->getRegistrationLink($token, $websiteUrl->getValue());
     $this->entityManager->persist($registration);
     $mail = new RegistrationMail($user, $websiteName->getValue(), $websiteEmail->getValue(), $websiteUrl->getValue(), $websiteReplyToEmail->getValue(), $websiteName->getValue(), $registrationLink);
     try {
         $this->mailer->send($mail);
         $this->entityManager->flush();
     } catch (Exception $e) {
         throw new RegistrationMailNotSentException($e->getMessage());
     }
 }
Example #3
0
 protected function initSessionParams(User $user)
 {
     $_SESSION['user_id'] = $user->getId();
     $_SESSION['user_user_name'] = $user->getUserName();
     $_SESSION['user_first_name'] = $user->getFirstName();
     $_SESSION['user_last_name'] = $user->getLastName();
     $_SESSION['user_last_login_date'] = $user->getLastLoginDate();
     $_SESSION['user_is_logged_in'] = true;
 }
Example #4
0
 public function update(User $user)
 {
     $this->setUserGroup($user->getUserGroup());
     $this->setUserName($user->getUserName());
     $this->setFirstName($user->getFirstName());
     $this->setLastName($user->getLastName());
     $this->setEmail($user->getEmail());
     $this->setPhoneNumber($user->getPhoneNumber());
     $this->setMobileNumber($user->getMobileNumber());
     $this->setAddress($user->getAddress());
     $this->setZipCode($user->getZipCode());
     $this->setPlace($user->getPlace());
     $this->setPlainPassword($user->getPlainPassword());
     $this->setPasswordHash($user->getPasswordHash());
     $this->setLastLoginDate($user->getLastLoginDate());
     $this->setRegistrationDate($user->getRegistrationDate());
     $this->setIsLocked($user->getIsLocked());
     $this->setIsLockedBy($user->getIsLockedBy());
 }
Example #5
0
 /**
  * Creates the admin user based on the configuration data.<br>
  * Required keys in $config are
  * <ul>
  *   <li>[username]</li>
  *   <li>[password]</li>
  *   <li>[email]</li>
  * </ul>
  *
  * @param array $config The array holding the above keys
  */
 protected function createAdminUser(array $config)
 {
     $userGroup = $this->app->entityManager->getRepository(EntityNames::USER_GROUP)->findOneBy(array('name' => 'Admin'));
     $now = new DateTime();
     $user = new User();
     $user->setFirstName('');
     $user->setLastName('');
     $user->setUserName($config['username']);
     $user->setPasswordHash(PasswordHandler::hash($config['password']));
     $user->setEmail($config['email']);
     $user->setIsLocked(false);
     $user->setUserGroup($userGroup);
     $user->setRegistrationDate($now);
     $user->setLastLoginDate($now);
     $user->setHasEmailValidated(false);
     $this->app->registrationHandler->registerUser($user);
 }