Update# refactor RegistrationService::validateEmail and
registercontroller
This commit is contained in:
parent
6dfe732882
commit
63837e7079
|
|
@ -148,7 +148,7 @@ class ApiController extends OCSController {
|
|||
try {
|
||||
$secret = null;
|
||||
$registration = $this->registrationService->validateEmail($email);
|
||||
if($registration === null) {
|
||||
if($registration === true) {
|
||||
$this->registrationService->validateDisplayname($displayname);
|
||||
$this->registrationService->validateUsername($username);
|
||||
$registration = $this->registrationService->createRegistration($email, $username, $password, $displayname);
|
||||
|
|
|
|||
|
|
@ -67,21 +67,30 @@ class RegisterController extends Controller {
|
|||
}
|
||||
|
||||
/**
|
||||
* User POST email, if email is valid and not duplicate, we send token by mail
|
||||
* @PublicPage
|
||||
*
|
||||
* @param string $email
|
||||
* @return TemplateResponse
|
||||
*/
|
||||
public function validateEmail($email) {
|
||||
if (!$this->registrationService->checkAllowedDomains($email)) {
|
||||
public function validateEmail($email) {//TODO rename to receiveUserEmail
|
||||
if (!$this->registrationService->checkAllowedDomains($email)) {//TODO Duplicate code with Service
|
||||
return new TemplateResponse('registration', 'domains', [
|
||||
'domains' => $this->registrationService->getAllowedDomains()
|
||||
], 'guest');
|
||||
}
|
||||
try {
|
||||
$this->registrationService->validateEmail($email);
|
||||
$registration = $this->registrationService->createRegistration($email);
|
||||
$this->mailService->sendTokenByMail($registration);
|
||||
$reg = $this->registrationService->validateEmail($email);
|
||||
if ( $reg === true ) {
|
||||
$registration = $this->registrationService->createRegistration($email);
|
||||
$this->mailService->sendTokenByMail($registration);
|
||||
} else {
|
||||
$this->registrationService->generateNewToken($reg);
|
||||
$this->mailService->sendTokenByMail($reg);
|
||||
return new TemplateResponse('registration', 'message', array('msg' =>
|
||||
$this->l10n->t('There is already a pending registration with this email, a new verification email has been sent to the address.')
|
||||
), 'guest');
|
||||
}
|
||||
} catch (RegistrationException $e) {
|
||||
return $this->renderError($e->getMessage(), $e->getHint());
|
||||
}
|
||||
|
|
|
|||
|
|
@ -147,7 +147,7 @@ class RegistrationService {
|
|||
|
||||
/**
|
||||
* @param string $email
|
||||
* @return Registration
|
||||
* @return Registration|true if there is a pending reg with this email, return the pending reg, if there are no problems with the email, return true.
|
||||
* @throws RegistrationException
|
||||
*/
|
||||
public function validateEmail($email) {
|
||||
|
|
@ -156,8 +156,8 @@ class RegistrationService {
|
|||
|
||||
// check for pending registrations
|
||||
try {
|
||||
return $this->registrationMapper->find($email);
|
||||
} catch (\Exception $e) {}
|
||||
return $this->registrationMapper->find($email);//if not found DB will throw a exception
|
||||
} catch (DoesNotExistException $e) {}
|
||||
|
||||
if ( $this->userManager->getByEmail($email) ) {
|
||||
throw new RegistrationException(
|
||||
|
|
@ -174,7 +174,7 @@ class RegistrationService {
|
|||
)
|
||||
);
|
||||
}
|
||||
return null;
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
Loading…
Reference in New Issue