diff --git a/app/controllers/UserController.php b/app/controllers/UserController.php index 3d4aab1..54973af 100644 --- a/app/controllers/UserController.php +++ b/app/controllers/UserController.php @@ -6,6 +6,7 @@ use App\Controller\ControllerBase, App\Form\UserSettings as UserSettingsForm, App\Model\Data\ActivityLog, App\Model\Data\PasswordLink, + App\Model\Data\User, SendGrid\Mail\Mail as SendGridMail; class UserController extends ControllerBase @@ -79,6 +80,37 @@ class UserController extends ControllerBase $this->view->form = $form; } + public function deleteAction() + { + $user = $this->_getAuth()->getUser(); + + if ($this->request->isPost()) { + $data = $this->request->getPost(); + } + + // Delete acc. + if (isset($data['deleteAcc'])) { + + if (strlen($user->getPassword()) > 0) { + if (!isset($data['currentpw']) || !$this->security->checkHash($data['currentpw'], $user->getPassword())) { + $this->flash->error('The password was not correct. Refusing to delete account.'); + $this->response->redirect('/settings'); + return; + } + } + + $user->setStatus(User::STATUS_DELETED); + $user->save(); + + // Logout the user. + $this->auth->clearIdentity(); + + $this->flash->success('The account was successfully removed.'); + } + + $this->response->redirect('/settings'); + } + /** * Activate a password. *