1
0
Fork 0
mirror of https://github.com/overleaf/overleaf.git synced 2025-04-23 03:26:27 +00:00

Functioning account deletion with password

This commit is contained in:
Shane Kilkelly 2016-10-25 16:23:50 +01:00
parent efe6df145c
commit 1c8721ceab
4 changed files with 34 additions and 17 deletions
services/web
app
coffee/Features/User
views/user
public

View file

@ -26,8 +26,7 @@ module.exports = UserController =
tryDeleteUser: (req, res, next) ->
user_id = AuthenticationController.getLoggedInUserId(req)
password = req.body.password
console.log '>> here', user_id, password
return res.sendStatus(500)
logger.info {user_id}, "trying to delete user account"
if !password? or password == ''
logger.err {user_id}, 'no password supplied for attempt to delete account'
return res.sendStatus(403)
@ -35,13 +34,15 @@ module.exports = UserController =
if err?
logger.err {user_id}, 'error authenticating during attempt to delete account'
return next(err)
if user
UserDeleter.deleteUser user_id, (err) ->
if err?
logger.err {user_id}, "error while deleting user account"
return next(err)
req.session?.destroy()
res.sendStatus(200)
if !user
logger.err {user_id}, 'auth failde during attempt to delete account'
return res.sendStatus(403)
UserDeleter.deleteUser user_id, (err) ->
if err?
logger.err {user_id}, "error while deleting user account"
return next(err)
req.session?.destroy()
res.sendStatus(200)
unsubscribe: (req, res)->
user_id = AuthenticationController.getLoggedInUserId(req)

View file

@ -150,8 +150,8 @@ block content
script(type='text/ng-template', id='deleteAccountModalTemplate')
.modal-header
h3 #{translate("delete_account")}
.modal-body
p !{translate("delete_account_warning_message_2")}
div.modal-body#delete-account-modal
p !{translate("delete_account_warning_message_3")}
form(novalidate, name="deleteAccountForm")
label #{translate('email')}
input.form-control(
@ -166,11 +166,14 @@ block content
type="password",
placeholder="",
ng-model="state.password",
ng-keyup="checkValidation()"
)
div(ng-if="state.error")
br
div.alert.alert-danger
| #{translate('generic_something_went_wrong')}
div(ng-if="state.invalidCredentials")
div.alert.alert-danger
| #{translate('email_or_password_wrong_try_again')}
.modal-footer
button.btn.btn-default(
ng-click="cancel()"

View file

@ -32,8 +32,10 @@ define [
$scope.state =
isValid : false
deleteText: ""
password: ""
inflight: false
error: false
invalidCredentials: false
$modalInstance.opened.then () ->
$timeout () ->
@ -41,11 +43,12 @@ define [
, 700
$scope.checkValidation = ->
$scope.state.isValid = $scope.state.deleteText == $scope.email
$scope.state.isValid = $scope.state.deleteText == $scope.email and $scope.state.password.length > 0
$scope.delete = () ->
$scope.state.inflight = true
$scope.state.error = false
$scope.state.invalidCredentials = false
$http({
method: "POST"
url: "/user/delete"
@ -59,11 +62,14 @@ define [
$modalInstance.close()
$scope.state.inflight = false
$scope.state.error = false
$scope.state.invalidCredentials = false
window.location = "/"
.error (err) ->
console.log ">> error", err
$scope.state.error = true
.error (data, status) ->
$scope.state.inflight = false
if status == 403
$scope.state.invalidCredentials = true
else
$scope.state.error = true
$scope.cancel = () ->
$modalInstance.dismiss('cancel')

View file

@ -2,4 +2,11 @@
.alert {
margin-bottom: 0;
}
}
}
#delete-account-modal {
.alert {
margin-top: 25px;
margin-bottom: 4px;
}
}