Skip to content

Commit

Permalink
users now can delete their account
Browse files Browse the repository at this point in the history
  • Loading branch information
gka committed Aug 14, 2012
1 parent 131a280 commit 471893c
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 1 deletion.
37 changes: 37 additions & 0 deletions lib/api/users.php
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -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');
}
});
24 changes: 23 additions & 1 deletion templates/settings.twig
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -179,6 +179,10 @@
<div class="btn btn-info" data-dismiss="modal">No, changed my mind..</div> <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 id="really-delete-account" class="btn btn-danger">Yes, delete it!</div>
</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> </div>
</fieldset> </fieldset>
<p></p> <p></p>
Expand Down Expand Up @@ -329,7 +333,25 @@ $(function() {
keyboard: true 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> </script>
Expand Down

0 comments on commit 471893c

Please sign in to comment.