Fix registerController
This commit is contained in:
parent
7e172494d1
commit
bf7df3827b
|
|
@ -15,6 +15,7 @@ namespace OCA\Registration\Controller;
|
|||
use \OCP\IRequest;
|
||||
use \OCP\AppFramework\Http\TemplateResponse;
|
||||
use \OCP\AppFramework\Controller;
|
||||
use \OCP\Util;
|
||||
use \OCA\Registration\Wrapper;
|
||||
|
||||
class RegisterController extends Controller {
|
||||
|
|
@ -54,30 +55,29 @@ class RegisterController extends Controller {
|
|||
public function validateEmail() {
|
||||
$email = $this->request->getParam('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;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
// FEATURE: allow only from specific email domain
|
||||
|
||||
$token = $this->pendingreg->save($email);
|
||||
$link = $this->urlgenerator->linkToRoute('registration.verify.token', 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();
|
||||
$link = $this->urlgenerator->linkToRoute('registration.register.verifytoken', array('token' => $token));
|
||||
$link = $this->urlgenerator->getAbsoluteURL($link);
|
||||
$from = Util::getDefaultEmailAddress('register');
|
||||
$res = new TemplateResponse('registration', 'email', array('link' => $link));
|
||||
$msg = $res->render();
|
||||
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) {
|
||||
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;
|
||||
}
|
||||
$this->displayRegisterPage('', true);
|
||||
$this->askEmail('', true);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ namespace OCA\Registration\Db;
|
|||
|
||||
use \OCP\IDb;
|
||||
use \OCP\Util;
|
||||
use \OCP\Config;
|
||||
|
||||
class PendingRegist {
|
||||
|
||||
|
|
@ -15,7 +16,7 @@ class PendingRegist {
|
|||
public function save($email) {
|
||||
$query = $this->db->prepareQuery( 'INSERT INTO `*PREFIX*registration`'
|
||||
.' ( `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() ));
|
||||
return $token;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue