/** * 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()); } }
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; }
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()); }