From d912c99473cf6bb08f6219519987386836eee5c3 Mon Sep 17 00:00:00 2001 From: Pellaeon Lin Date: Fri, 29 Aug 2014 15:31:53 +0000 Subject: [PATCH] Copy over the old sendEmail controller --- controller/registrationcontroller.php | 43 ++++++++++++++++++++++++--- 1 file changed, 39 insertions(+), 4 deletions(-) diff --git a/controller/registrationcontroller.php b/controller/registrationcontroller.php index 2b2a525..f476044 100644 --- a/controller/registrationcontroller.php +++ b/controller/registrationcontroller.php @@ -27,11 +27,46 @@ class RegistrationController extends Controller { * @NoCSRFRequired * @PublicPage */ - public function displayRegisterPage() { + public function displayRegisterPage($errormsg, $entered) { $params = array( - 'errormsg' => $this->request->getParam('errormsg'), - 'entered' => $this->request->getParam('entered') + 'errormsg' => $errormsg ? $errormsg : $this->request->getParam('errormsg'), + 'entered' => $entered ? $entered : $this->request->getParam('entered') ); return new TemplateResponse('registration', 'register', $params); } -} + + /** + * @NoAdminRequired + * @NoCSRFRequired + * @PublicPage + */ + public function sendEmail() { + // TODO: Check if user with this email already exists + + if ( !filter_var($_POST['email'], FILTER_VALIDATE_EMAIL) ) { + $this->displayRegisterPage($l->t('Email address you entered is not valid'), true); + return; + } + + // FEATURE: allow only from specific email domain + + $token = self::savePendingRegistration($_POST['email']); + if ( $token === false ) { + $this->displayRegisterPage($l->t('There is already a pending registration with this email'), true); + } elseif ( strlen($token) === 64 ) { + $link = OC_Helper::linkToRoute('core_registration_register_form', + array('token' => $token)); + $link = OC_Helper::makeURLAbsolute($link); + $from = OCP\Util::getDefaultEmailAddress('register'); + $tmpl = new OC_Template('core/registration', 'email'); + $tmpl->assign('link', $link, false); + $msg = $tmpl->fetchPage(); + try { + OC_Mail::send($_POST['email'], 'ownCloud User', $l->t('Verify your ownCloud registration request'), $msg, $from, 'ownCloud'); + } catch (Exception $e) { + OC_Template::printErrorPage( 'A problem occurs during sending the e-mail please contact your administrator.'); + return; + } + $this->displayRegisterPage('', true); + } + }