app/controllers/AuthController.php: in registerAction() send activation mail if email from oauth is changed.
This commit is contained in:
parent
4ff298e7ea
commit
2faf85359a
1 changed files with 32 additions and 3 deletions
|
|
@ -4,6 +4,7 @@ namespace App\Controller;
|
|||
|
||||
use App\Controller\ControllerBase,
|
||||
App\Model\Data\User,
|
||||
App\Model\Data\UserActivation,
|
||||
App\Form\Login as LoginForm,
|
||||
App\Form\Registration as RegistrationForm,
|
||||
Httpcb\OAuth\UserData\UserDataInterface,
|
||||
|
|
@ -133,11 +134,39 @@ class AuthController extends ControllerBase
|
|||
|
||||
$formData = $this->request->getPost();
|
||||
if ($form->isValid($formData)) {
|
||||
|
||||
// Check if email was changed.
|
||||
$activationNeeded = false;
|
||||
if ($form->getValue('email') !== $data->getEmail()) {
|
||||
$activationNeeded = true;
|
||||
|
||||
// Set suspended until the email address is confirmed
|
||||
$user->setStatus(User::STATUS_SUSPENDED);
|
||||
}
|
||||
|
||||
$user->setOAuthId($data->getProvider(), $data->getId());
|
||||
if ($user->save()) {
|
||||
$this->auth->systemLogin($user);
|
||||
$this->flash->success('User successfully created. Now add your first callback!');
|
||||
$this->response->redirect('/callback/new');
|
||||
|
||||
if ($activationNeeded) {
|
||||
|
||||
$activation = new UserActivation();
|
||||
$activation->setUserId($user->getId())
|
||||
->save();
|
||||
|
||||
$content = $this->di->getShared('template')->render('mail/account_activation', [
|
||||
'link' => $activation->getActivationKey()
|
||||
]);
|
||||
|
||||
$this->di->getMail()->send('Httpcb account activation', $user->getEmail(), $content);
|
||||
|
||||
$this->flash->success('User successfully created.');
|
||||
$this->flash->notice("An email has been sent to {$form->getValue('email')} with an activation code.");
|
||||
$this->response->redirect('/login');
|
||||
} else {
|
||||
$this->auth->systemLogin($user);
|
||||
$this->flash->success('User successfully created. Now add your first callback!');
|
||||
$this->response->redirect('/callback/new');
|
||||
}
|
||||
} else {
|
||||
$this->flash->error('Could not create user');
|
||||
}
|
||||
|
|
|
|||
Reference in a new issue