Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

users now can delete their account

  • Loading branch information...
commit 471893c45b848239b103869ea24fb18d961986ea 1 parent 131a280
@gka gka authored
Showing with 60 additions and 1 deletion.
  1. +37 −0 lib/api/users.php
  2. +23 −1 templates/settings.twig
View
37 lib/api/users.php
@@ -139,3 +139,40 @@ function email_exists($email) {
}
});
+
+
+/*
+ * delete a user
+ * @needs admin or existing user
+ */
+$app->delete('/users/:id', function($user_id) use ($app) {
+ $curUser = DatawrapperSession::getUser();
+ if ($curUser->isLoggedIn()) {
+ if ($user_id == 'current' || $curUser->getId() === $user_id) {
+ $user = $curUser;
+ } else if ($curUser->isAdmin()) {
+ $user = UserQuery::create()->findPK($user_id);
+ }
+ if (!empty($user)) {
+
+ // Delete all charts
+ ChartQuery::create()
+ ->findByUser($user)
+ ->delete();
+
+ // Delete user actions from log
+ ActionQuery::create()
+ ->findByUser($user)
+ ->delete();
+
+ // Delete user
+ $user->delete();
+
+ ok();
+ } else {
+ error('user-not-found', 'no user found with that id');
+ }
+ } else {
+ error('need-login', 'you must be logged in to do that');
+ }
+});
View
24 templates/settings.twig
@@ -179,6 +179,10 @@
<div class="btn btn-info" data-dismiss="modal">No, changed my mind..</div>
<div id="really-delete-account" class="btn btn-danger">Yes, delete it!</div>
</div>
+ <div class="post-delete" style="display:none">
+ <h2 style="margin-bottom:20px;text-align:center">Your account has been deleted.</h2>
+ <a href="/" class="btn btn-primary btn-large">Goodbye!</a>
+ </div>
</div>
</fieldset>
<p></p>
@@ -329,7 +333,25 @@ $(function() {
keyboard: true
});
});
-
+ $('#really-delete-account').click(function() {
+ $.ajax({
+ url: '/api/users/current',
+ type: 'delete',
+ dataType: 'json',
+ success: function(res) {
+ if (res.status == 'ok') {
+ $('#confirmDeletion .modal-body').remove();
+ $('#confirmDeletion .modal-footer').remove();
+ $('#confirmDeletion .post-delete').css({
+ 'text-align': 'center',
+ 'padding': '30px'
+ });
+ $('#confirmDeletion .post-delete').addClass('modal-body');
+ $('#confirmDeletion .post-delete').show();
+ }
+ }
+ });
+ });
});
</script>
Please sign in to comment.
Something went wrong with that request. Please try again.