Merge branch '14-user-add-support-for-removing-account' into dev
This commit is contained in:
commit
6d8025c5d6
7 changed files with 95 additions and 3 deletions
|
|
@ -45,6 +45,11 @@
|
|||
.button-brand { .button-variant(@button-brand-color, @button-brand-bg); }
|
||||
.button-light { .button-variant(@text-light-color, @button-bg-color, @button-hover-color); }
|
||||
|
||||
.button-info { .button-variant(@button-info-color, @button-info-bg); }
|
||||
.button-success { .button-variant(@button-success-color, @button-success-bg); }
|
||||
.button-warning { .button-variant(@button-warning-color, @button-warning-bg); }
|
||||
.button-danger { .button-variant(@button-danger-color, @button-danger-bg); }
|
||||
|
||||
.button-github { .button-variant(@button-github-color, @button-github-bg); }
|
||||
.button-gitlab { .button-variant(@button-gitlab-color, @button-gitlab-bg); }
|
||||
.button-google { .button-variant(@button-google-color, @button-google-bg); }
|
||||
|
|
|
|||
|
|
@ -104,6 +104,16 @@
|
|||
@button-brand-color: white;
|
||||
@button-brand-bg: @brand-color;
|
||||
|
||||
// State
|
||||
@button-info-color: white;
|
||||
@button-info-bg: @state-info-text;
|
||||
@button-success-color: white;
|
||||
@button-success-bg: @state-success-text;
|
||||
@button-warning-color: white;
|
||||
@button-warning-bg: @state-warning-text;
|
||||
@button-danger-color: white;
|
||||
@button-danger-bg: @state-danger-text;
|
||||
|
||||
// Company.
|
||||
|
||||
@button-google-color: white;
|
||||
|
|
|
|||
|
|
@ -30,7 +30,7 @@
|
|||
@import (reference) "bootstrap/panels.less";
|
||||
@import (reference) "bootstrap/wells.less";
|
||||
@import "bootstrap/close.less";
|
||||
@import (reference) "bootstrap/modals.less";
|
||||
@import "bootstrap/modals.less";
|
||||
@import (reference) "bootstrap/tooltip.less";
|
||||
@import (reference) "bootstrap/popovers.less";
|
||||
@import (reference) "bootstrap/carousel.less";
|
||||
|
|
|
|||
|
|
@ -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.
|
||||
*
|
||||
|
|
|
|||
|
|
@ -58,6 +58,13 @@ class Auth extends Component
|
|||
return $user->getMessages();
|
||||
}
|
||||
}
|
||||
// Here we activate the user.
|
||||
// As for OAuth we perform registration if the user does not exist.
|
||||
// We should therefore activate deleted accounts.
|
||||
else if ($user->Status == User::STATUS_DELETED) {
|
||||
$user->Status = User::STATUS_ACTIVE;
|
||||
$user->save();
|
||||
}
|
||||
|
||||
$this->setIdentity($user->getId());
|
||||
|
||||
|
|
|
|||
|
|
@ -281,8 +281,8 @@ class User extends Model
|
|||
static public function findFirstByUsernameOrEmail($value)
|
||||
{
|
||||
return self::findFirst([
|
||||
"email = :v: OR username = :v:",
|
||||
"bind" => [ 'v' => $value ]
|
||||
"(email = :v: OR username = :v:) AND status = :s:",
|
||||
"bind" => [ 'v' => $value, 's' => self::STATUS_ACTIVE ]
|
||||
]);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -71,8 +71,46 @@
|
|||
<div class="col-sm-offset-2 col-sm-10">
|
||||
<hr />
|
||||
{{ form.render('Save') }}
|
||||
|
||||
<button class="button button-danger pull-right" type="button" data-toggle="modal" data-target="#deleteModal">
|
||||
Delete Account
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</form>
|
||||
</div>
|
||||
|
||||
<div class="modal fade" id="deleteModal" tabindex="-1" role="dialog" aria-labelledby="deleteModalLabel" aria-hidden="true">
|
||||
<div class="modal-dialog" role="document">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<h4 class="modal-title pull-left" id="deleteModalLabel">Delete account</h4>
|
||||
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
|
||||
<span aria-hidden="true">×</span>
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<form method="post" action="/user/delete">
|
||||
<div class="modal-body">
|
||||
<p>
|
||||
Deleting your account is a non-reversible action.
|
||||
All data associated with your account will be lost in the process.
|
||||
</p>
|
||||
{% if user.password|length > 0 %}
|
||||
<p>Enter your <kbd>password</kbd> to confirm:</p>
|
||||
|
||||
<input type="password" name="currentpw" class="form-control" />
|
||||
{% endif %}
|
||||
</div>
|
||||
|
||||
<div class="modal-footer">
|
||||
<button type="button" class="button button-default" data-dismiss="modal">Close</button>
|
||||
<input type="submit" name="deleteAcc" class="button button-danger" value="Delete account">
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
|
|
|
|||
Reference in a new issue