app/controllers/UserController.php: add deleteAction()
This commit is contained in:
parent
6ce456fff7
commit
0e7849e5f7
1 changed files with 32 additions and 0 deletions
|
|
@ -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.
|
||||
*
|
||||
|
|
|
|||
Reference in a new issue