Fix registerController

This commit is contained in:
Pellaeon Lin 2014-08-31 12:14:24 +00:00
parent 7e172494d1
commit bf7df3827b
2 changed files with 13 additions and 12 deletions

View File

@ -15,6 +15,7 @@ namespace OCA\Registration\Controller;
use \OCP\IRequest; use \OCP\IRequest;
use \OCP\AppFramework\Http\TemplateResponse; use \OCP\AppFramework\Http\TemplateResponse;
use \OCP\AppFramework\Controller; use \OCP\AppFramework\Controller;
use \OCP\Util;
use \OCA\Registration\Wrapper; use \OCA\Registration\Wrapper;
class RegisterController extends Controller { class RegisterController extends Controller {
@ -54,30 +55,29 @@ class RegisterController extends Controller {
public function validateEmail() { public function validateEmail() {
$email = $this->request->getParam('email'); $email = $this->request->getParam('email');
if ( !filter_var($email, FILTER_VALIDATE_EMAIL) ) { if ( !filter_var($email, FILTER_VALIDATE_EMAIL) ) {
$this->displayRegisterPage($this->l10n->t('Email address you entered is not valid'), true); $this->askEmail($this->l10n->t('Email address you entered is not valid'), true);
return; return;
} }
if ( $this->pendingreg->find($email) ) { if ( $this->pendingreg->find($email) ) {
$this->displayRegisterPage($this->l10n->t('There is already a pending registration with this email'), true); $this->askEmail($this->l10n->t('There is already a pending registration with this email'), true);
return; return;
} }
// FEATURE: allow only from specific email domain // FEATURE: allow only from specific email domain
$token = $this->pendingreg->save($email); $token = $this->pendingreg->save($email);
$link = $this->urlgenerator->linkToRoute('registration.verify.token', array('token' => $token)); $link = $this->urlgenerator->linkToRoute('registration.register.verifytoken', array('token' => $token));
$link = OC_Helper::makeURLAbsolute($link); $link = $this->urlgenerator->getAbsoluteURL($link);
$from = OCP\Util::getDefaultEmailAddress('register'); $from = Util::getDefaultEmailAddress('register');
$tmpl = new OC_Template('core/registration', 'email'); $res = new TemplateResponse('registration', 'email', array('link' => $link));
$tmpl->assign('link', $link, false); $msg = $res->render();
$msg = $tmpl->fetchPage();
try { try {
OC_Mail::send($_POST['email'], 'ownCloud User', $l->t('Verify your ownCloud registration request'), $msg, $from, 'ownCloud'); $this->mail->send($email, 'ownCloud User', $l->t('Verify your ownCloud registration request'), $msg, $from, 'ownCloud');
} catch (Exception $e) { } catch (Exception $e) {
OC_Template::printErrorPage( 'A problem occurs during sending the e-mail please contact your administrator.'); \OC_Template::printErrorPage( 'A problem occurs during sending the e-mail please contact your administrator.');
return; return;
} }
$this->displayRegisterPage('', true); $this->askEmail('', true);
} }
} }

View File

@ -3,6 +3,7 @@ namespace OCA\Registration\Db;
use \OCP\IDb; use \OCP\IDb;
use \OCP\Util; use \OCP\Util;
use \OCP\Config;
class PendingRegist { class PendingRegist {
@ -15,7 +16,7 @@ class PendingRegist {
public function save($email) { public function save($email) {
$query = $this->db->prepareQuery( 'INSERT INTO `*PREFIX*registration`' $query = $this->db->prepareQuery( 'INSERT INTO `*PREFIX*registration`'
.' ( `email`, `token`, `requested` ) VALUES( ?, ?, ? )' ); .' ( `email`, `token`, `requested` ) VALUES( ?, ?, ? )' );
$token = hash('sha256', generateRandomBytes(30).OC_Config::getValue('passwordsalt', '')); $token = hash('sha256', Util::generateRandomBytes(30).Config::getSystemValue('passwordsalt', ''));
$query->execute(array( $email, $token, time() )); $query->execute(array( $email, $token, time() ));
return $token; return $token;
} }