From e16e5df481c47b139544098d7545a4e8d4417eef Mon Sep 17 00:00:00 2001 From: Pellaeon Lin Date: Sun, 31 Aug 2014 19:20:26 +0200 Subject: [PATCH] Implemented controller verifyToken --- controller/registercontroller.php | 21 ++++++++++++++++++++- db/pendingregist.php | 5 +++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/controller/registercontroller.php b/controller/registercontroller.php index 05a07d1..7a05a62 100644 --- a/controller/registercontroller.php +++ b/controller/registercontroller.php @@ -82,11 +82,30 @@ class RegisterController extends Controller { $res = new TemplateResponse('registration', 'email', array('link' => $link)); $msg = $res->render(); try { - $this->mail->send($email, 'ownCloud User', $l->t('Verify your ownCloud registration request'), $msg, $from, 'ownCloud'); + $this->mail->send($email, 'ownCloud User', $this->l10n->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->askEmail('', true); } + + /** + * @NoAdminRequired + * @NoCSRFRequired + * @PublicPage + */ + public function verifyToken($token) { + $email = $this->pendingreg->findByToken($token); + if ( \OCP\DB::isError($email) ) { + return new TemplateResponse('', 'error', array( + 'errors' => array(array( + 'error' => $this->l10n->t('Invalid verification URL. No registration request with this verification URL is found.'), + 'hint' => '' + )) + ), 'error'); + } elseif ( $email ) { + return new TemplateResponse('registration', 'form', array(), 'guest'); + } + } } diff --git a/db/pendingregist.php b/db/pendingregist.php index 98f67fc..f39d14e 100644 --- a/db/pendingregist.php +++ b/db/pendingregist.php @@ -25,4 +25,9 @@ class PendingRegist { return $query->execute(array($email))->fetchAll(); } + public function findByToken($token) { + $query = $this->db->prepareQuery('SELECT `email` FROM `*PREFIX*registration` WHERE `token` = ? '); + return $query->execute(array($token))->fetchOne(); + } + }