Require user password for deleting accounts #2842

This commit is contained in:
Lai Tuan 2015-06-20 23:03:37 +09:00
parent 37257d2477
commit 39fc882303
3 changed files with 48 additions and 12 deletions

View file

@ -709,6 +709,7 @@
picture_tab: "Picture" picture_tab: "Picture"
delete_account_tab: "Delete Your Account" delete_account_tab: "Delete Your Account"
wrong_email: "Wrong Email" wrong_email: "Wrong Email"
wrong_password: "Wrong Password"
upload_picture: "Upload a picture" upload_picture: "Upload a picture"
delete_this_account: "Delete this account permanently" delete_this_account: "Delete this account permanently"
god_mode: "God Mode" god_mode: "God Mode"
@ -718,6 +719,7 @@
new_password: "New Password" new_password: "New Password"
new_password_verify: "Verify" new_password_verify: "Verify"
type_in_email: "Type in your email to confirm the deletion" type_in_email: "Type in your email to confirm the deletion"
type_in_password: "Type in your password also"
email_subscriptions: "Email Subscriptions" email_subscriptions: "Email Subscriptions"
email_subscriptions_none: "No Email Subscriptions." email_subscriptions_none: "No Email Subscriptions."
email_announcements: "Announcements" email_announcements: "Announcements"

View file

@ -56,7 +56,10 @@ else
.form-group .form-group
label.control-label(for="email1", data-i18n="account_settings.type_in_email") Type in your email to confirm the deletion label.control-label(for="email1", data-i18n="account_settings.type_in_email") Type in your email to confirm the deletion
input#email1.form-control(name="email1", type="text") input#email1.form-control(name="email1", type="text")
button#delete-account-button.btn.form-control.btn-primary(data-i18n="account_settings.delete_this_account") .form-group
label.control-label(for="password1", data-i18n="account_settings.type_in_password") Type in your password also
input#password1.form-control(name="password1", type="password")
button#delete-account-button.btn.form-control.btn-primary(data-i18n="account_settings.delete_this_account")
.col-md-6 .col-md-6

View file

@ -40,7 +40,7 @@ module.exports = class AccountSettingsView extends CocoView
#- Form input callbacks #- Form input callbacks
onInputChanged: (e) -> onInputChanged: (e) ->
$(e.target).addClass 'changed' $(e.target).addClass 'changed'
if (JSON.stringify(document.getElementById('email1').className)).indexOf("changed") > -1 if (JSON.stringify(document.getElementById('email1').className)).indexOf("changed") > -1 or (JSON.stringify(document.getElementById('password1').className)).indexOf("changed") > -1
$(e.target).removeClass 'changed' $(e.target).removeClass 'changed'
else else
@trigger 'input-changed' @trigger 'input-changed'
@ -67,26 +67,57 @@ module.exports = class AccountSettingsView extends CocoView
#- Just copied from OptionsView, TODO refactor #- Just copied from OptionsView, TODO refactor
confirmAccountDeletion: -> confirmAccountDeletion: ->
forms.clearFormAlerts(@$el) forms.clearFormAlerts(@$el)
myEmail = me.get 'email' myEmail = me.get 'email'
email1 = document.getElementById('email1').value email1 = document.getElementById('email1').value
password1 = document.getElementById('password1').value
if Boolean(email1) and email1 is myEmail if Boolean(email1) and email1 is myEmail
renderData = isPasswordCorrect = false
'confirmTitle': 'Are you really sure?' toBeDelayed = true
'confirmBody': 'This will completely delete your account. This action CANNOT be undone. Are you entirely sure?' $.ajax
'confirmDecline': 'Not really' url: '/auth/login'
'confirmConfirm': 'Definitely' type: 'POST'
confirmModal = new ConfirmModal renderData data:
confirmModal.on 'confirm', @deleteAccount {
@openModalView confirmModal username: email1,
password: password1
}
parse: true
error: (error) ->
toBeDelayed = false
'Bad Error. Can\'t connect to server or something. ' + error
success: (response, textStatus, jqXHR) ->
toBeDelayed = false
unless jqXHR.status is 200
return
isPasswordCorrect = true
callback = (tempThis) ->
if toBeDelayed
setTimeout callback, 100, tempThis
else
if isPasswordCorrect
renderData =
'confirmTitle': 'Are you really sure?'
'confirmBody': 'This will completely delete your account. This action CANNOT be undone. Are you entirely sure?'
'confirmDecline': 'Not really'
'confirmConfirm': 'Definitely'
confirmModal = new ConfirmModal renderData
confirmModal.on 'confirm', tempThis.deleteAccount
tempThis.openModalView confirmModal
else
message = $.i18n.t('account_settings.wrong_password', defaultValue: 'Wrong Password.')
err = [message: message, property: 'password1', formatted: true]
forms.applyErrorsToForm(tempThis.$el, err)
$('.nano').nanoScroller({scrollTo: tempThis.$el.find('.has-error')})
setTimeout callback, 100, this
else else
message = $.i18n.t('account_settings.wrong_email', defaultValue: 'Wrong Email.') message = $.i18n.t('account_settings.wrong_email', defaultValue: 'Wrong Email.')
err = [message: message, property: 'email1', formatted: true] err = [message: message, property: 'email1', formatted: true]
forms.applyErrorsToForm(@$el, err) forms.applyErrorsToForm(@$el, err)
$('.nano').nanoScroller({scrollTo: @$el.find('.has-error')}) $('.nano').nanoScroller({scrollTo: @$el.find('.has-error')})
deleteAccount: -> deleteAccount: ->
myID = me.id myID = me.id
$.ajax $.ajax