-
-
Save ireneyiu/8b404d2322033d0b6bd8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var wfApp = wfApp || {}; | |
wfApp.settings = wfApp.settings || {}; | |
wfApp.settings.password = wfApp.settings.password || {}; | |
wfApp.settings.password.onDomReady = function() { | |
this.form = $("#password-form"); | |
this.submitUrl = this.form.attr('action'); | |
}; | |
wfApp.settings.password.listen = function() { | |
$("#password-form").on('submit', this.submit.bind(this)); | |
}; | |
wfApp.settings.password.submit = function(e) { | |
e.preventDefault(); | |
var params = this.$el.serializeArray(); | |
var validationResult = this.validate(); | |
if (!validationResult.valid) { | |
$("#password-form input[name=new], | |
#password-form input[name=verify]").val("").first().focus(); | |
this.showMessage(this.form, validationResult.errors, "failure", 3000); | |
} else { | |
$("#password-form input").attr("disabled", true); | |
this.showMessage(this.form, "Saving..."); | |
$.post(this.submitUrl, params) | |
.then(this.processResponse.bind(this))) | |
.done(this.submitSuccess.bind(this)) | |
.fail(this.submitFail.bind(this)); | |
} | |
}; | |
wfApp.settings.password.validate = function() { | |
var params = this.params(); | |
if (!params.old.length) { | |
return {valid: false, errors: "Please enter your current password."}; | |
} else if (params.newPass.length < 6) { | |
return {valid: false, errors: "New password must be at least 6 characters."}; | |
} else if (params.newPass !== this.verify) { | |
return {valid: false, errors: "New password and confirmation do not match."}; | |
} else if (params.newPass === this.old) { | |
return {valid: false, errors: "New password should be different from current password."}; | |
} else { | |
return {valid: true}; | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment