/** * Register a user. * * Will also send an email to the user. * * @param array $data Registration data * * @return NewUserModel New registered user. Null when the user could not be registered. */ public function register($data) { $form = $this->getRegisterForm(); $form->setData($data); if (!$form->isValid()) { return null; } // get the member $data = $form->getData(); $member = $this->getMemberMapper()->findByLidnr($data['lidnr']); if (null === $member) { $form->setError(RegisterForm::ERROR_MEMBER_NOT_EXISTS); return null; } // check if the email is the same if ($member->getEmail() != $data['email']) { $form->setError(RegisterForm::ERROR_WRONG_EMAIL); return null; } // check if the member already has a corresponding user. $user = $this->getUserMapper()->findByLidnr($member->getLidnr()); if (null !== $user) { $form->setError(RegisterForm::ERROR_USER_ALREADY_EXISTS); return null; } // save the data, and send email $newUser = new NewUserModel($member); $newUser->setCode($this->generateCode()); $this->getNewUserMapper()->persist($newUser); $this->getEmailService()->sendRegisterEmail($newUser, $member); return $newUser; }
/** * Request a password reset. * * Will also send an email to the user. * * @param array $data Reset data * * @return UserModel User. Null when the password could not be reset. */ public function reset($data) { $form = $this->getPasswordResetForm(); $form->setData($data); if (!$form->isValid()) { return null; } // get the member $data = $form->getData(); $member = $this->getMemberMapper()->findByLidnr($data['lidnr']); // check if the member has a corresponding user. $user = $this->getUserMapper()->findByLidnr($member->getLidnr()); if (null === $user) { $form->setError(RegisterForm::ERROR_MEMBER_NOT_EXISTS); return null; } // Invalidate all previous password reset codes // Makes sure that no double password reset codes are present in the database $this->getNewUserMapper()->deleteByMember($member); // create new activation $newUser = new NewUserModel($member); $newUser->setCode($this->generateCode()); $this->getNewUserMapper()->persist($newUser); $this->getEmailService()->sendPasswordLostMail($newUser, $member); return $user; }