diff --git a/app/controllers/AuthController.php b/app/controllers/AuthController.php index 1fcb8d6..5c20761 100644 --- a/app/controllers/AuthController.php +++ b/app/controllers/AuthController.php @@ -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'); }