Connect controllers to DB, try to use dependency injection
This commit is contained in:
parent
b1b06947bf
commit
5ed6060606
|
|
@ -21,10 +21,12 @@ class RegistrationController extends Controller {
|
||||||
|
|
||||||
private $mail;
|
private $mail;
|
||||||
private $l10n;
|
private $l10n;
|
||||||
|
private $db;
|
||||||
|
|
||||||
public function __construct($appName, IRequest $request, Mail $mail, $l10n){
|
public function __construct($appName, IRequest $request, Mail $mail, $l10n, $db){
|
||||||
$this->mail = $mail;
|
$this->mail = $mail;
|
||||||
$this->l10n = $l10n;
|
$this->l10n = $l10n;
|
||||||
|
$this->db = $db;
|
||||||
parent::__construct($appName, $request);
|
parent::__construct($appName, $request);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -46,33 +48,33 @@ class RegistrationController extends Controller {
|
||||||
* @NoCSRFRequired
|
* @NoCSRFRequired
|
||||||
* @PublicPage
|
* @PublicPage
|
||||||
*/
|
*/
|
||||||
public function sendEmail() {
|
public function validateEmail() {
|
||||||
// TODO: Check if user with this email already exists
|
$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);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if ( !filter_var($_POST['email'], FILTER_VALIDATE_EMAIL) ) {
|
if ( $this->db->find($email) ) {
|
||||||
$this->displayRegisterPage($l->t('Email address you entered is not valid'), true);
|
$this->displayRegisterPage($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 = self::savePendingRegistration($_POST['email']);
|
$token = $this->db->savePendingRegistration($email);
|
||||||
if ( $token === false ) {
|
$link = OC_Helper::linkToRoute('core_registration_register_form',
|
||||||
$this->displayRegisterPage($l->t('There is already a pending registration with this email'), true);
|
array('token' => $token));
|
||||||
} elseif ( strlen($token) === 64 ) {
|
$link = OC_Helper::makeURLAbsolute($link);
|
||||||
$link = OC_Helper::linkToRoute('core_registration_register_form',
|
$from = OCP\Util::getDefaultEmailAddress('register');
|
||||||
array('token' => $token));
|
$tmpl = new OC_Template('core/registration', 'email');
|
||||||
$link = OC_Helper::makeURLAbsolute($link);
|
$tmpl->assign('link', $link, false);
|
||||||
$from = OCP\Util::getDefaultEmailAddress('register');
|
$msg = $tmpl->fetchPage();
|
||||||
$tmpl = new OC_Template('core/registration', 'email');
|
try {
|
||||||
$tmpl->assign('link', $link, false);
|
OC_Mail::send($_POST['email'], 'ownCloud User', $l->t('Verify your ownCloud registration request'), $msg, $from, 'ownCloud');
|
||||||
$msg = $tmpl->fetchPage();
|
} catch (Exception $e) {
|
||||||
try {
|
OC_Template::printErrorPage( 'A problem occurs during sending the e-mail please contact your administrator.');
|
||||||
OC_Mail::send($_POST['email'], 'ownCloud User', $l->t('Verify your ownCloud registration request'), $msg, $from, 'ownCloud');
|
return;
|
||||||
} catch (Exception $e) {
|
|
||||||
OC_Template::printErrorPage( 'A problem occurs during sending the e-mail please contact your administrator.');
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
$this->displayRegisterPage('', true);
|
|
||||||
}
|
}
|
||||||
|
$this->displayRegisterPage('', true);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue