Merge pull request #21846 from RitvikSardana/develop-ritvik-better-set-password-page
This commit is contained in:
commit
eebbcd02b5
1 changed files with 92 additions and 24 deletions
|
|
@ -23,10 +23,10 @@
|
|||
<input id="confirm_password" type="password"
|
||||
class="form-control" placeholder="{{ _('Confirm Password') }}" autocomplete="new-password">
|
||||
|
||||
<p class="password-mismatch-message text-muted small hidden mt-2"></p>
|
||||
</div>
|
||||
<p class='password-strength-message text-muted small hidden'></p>
|
||||
<button type="submit" id="update"
|
||||
<p class="password-mismatch-message text-muted small hidden mt-2"></p>
|
||||
<p class='password-strength-message text-muted small mt-2 hidden'></p>
|
||||
<button type="submit" id="update" disabled = true style="cursor: not-allowed;"
|
||||
class="btn btn-primary btn-block btn-update">{{_("Confirm")}}</button>
|
||||
</form>
|
||||
{%- if not disable_signup -%}
|
||||
|
|
@ -43,11 +43,27 @@
|
|||
<script>
|
||||
|
||||
frappe.ready(function() {
|
||||
if(frappe.utils.get_url_arg("key")) {
|
||||
$("#old_password").parent().toggle();
|
||||
// URL args
|
||||
const key = frappe.utils.get_url_arg('key');
|
||||
const password_expired = frappe.utils.get_url_arg('password_expired');
|
||||
// inputs, paragraphs and button elements
|
||||
const old_password = $('#old_password');
|
||||
const new_password = $('#new_password');
|
||||
const confirm_password = $('#confirm_password');
|
||||
const update_button = $('#update');
|
||||
const password_strength_indicator = $('.password-strength-indicator');
|
||||
const password_strength_message =$('.password-strength-message');
|
||||
const password_mismatch_message = $('.password-mismatch-message');
|
||||
// Info text
|
||||
const password_not_same_as_old_password = "{{ _('New password cannot be same as old password') }}";
|
||||
const password_mismatch = "{{ _('Passwords do not match') }}";
|
||||
const password_strength_message_success = "{{ _('Success! You are good to go 👍') }}";
|
||||
|
||||
if(key) {
|
||||
old_password.parent().toggle();
|
||||
}
|
||||
|
||||
if(frappe.utils.get_url_arg("password_expired")) {
|
||||
if(password_expired) {
|
||||
$(".password-box").html("{{ _('The password of your account has expired.') }}");
|
||||
}
|
||||
|
||||
|
|
@ -55,18 +71,18 @@ frappe.ready(function() {
|
|||
return false;
|
||||
});
|
||||
|
||||
$("#new_password").on("keypress", function(e) {
|
||||
if(e.which===13) $("#update").click();
|
||||
new_password.on("keypress", function(e) {
|
||||
if(e.which===13) update_button.click();
|
||||
})
|
||||
|
||||
$("#update").click(function() {
|
||||
update_button.click(function() {
|
||||
var args = {
|
||||
key: frappe.utils.get_url_arg("key") || "",
|
||||
old_password: $("#old_password").val(),
|
||||
new_password: $("#new_password").val(),
|
||||
key: key || "",
|
||||
old_password: old_password.val(),
|
||||
new_password: new_password.val(),
|
||||
confirm_password: confirm_password.val(),
|
||||
logout_all_sessions: 1
|
||||
}
|
||||
const confirm_password = $('#confirm_password').val()
|
||||
if (!args.old_password && !args.key) {
|
||||
frappe.msgprint({
|
||||
title: "{{ _('Missing Value') }}",
|
||||
|
|
@ -81,20 +97,36 @@ frappe.ready(function() {
|
|||
clear: true
|
||||
});
|
||||
}
|
||||
if (args.new_password !== confirm_password) {
|
||||
$('.password-mismatch-message').text("{{ _('Passwords do not match') }}")
|
||||
if (args.old_password === args.new_password) {
|
||||
frappe.msgprint({
|
||||
title: "{{ _('Invalid Password') }}",
|
||||
message: password_not_same_as_old_password,
|
||||
});
|
||||
password_strength_message.addClass('hidden');
|
||||
return;
|
||||
}
|
||||
|
||||
if (args.new_password !== args.confirm_password) {
|
||||
password_mismatch_message.text(password_mismatch)
|
||||
.removeClass('hidden text-muted').addClass('text-danger');
|
||||
return false;
|
||||
password_strength_message.addClass('hidden');
|
||||
return;
|
||||
}
|
||||
|
||||
frappe.call({
|
||||
type: "POST",
|
||||
method: "frappe.core.doctype.user.user.update_password",
|
||||
btn: $("#update"),
|
||||
btn: update_button,
|
||||
args: args,
|
||||
statusCode: {
|
||||
401: function() {
|
||||
$(".page-card-head .reset-password-heading").text("{{ _('Invalid Password') }}");
|
||||
frappe.msgprint({
|
||||
title: "{{ _('Invalid Password') }}",
|
||||
message: "{{ _('Your old password is incorrect.') }}",
|
||||
// clear any server message
|
||||
clear: true
|
||||
});
|
||||
},
|
||||
410: function({ responseJSON }) {
|
||||
const title = "{{ _('Invalid Link') }}";
|
||||
|
|
@ -127,21 +159,55 @@ frappe.ready(function() {
|
|||
return false;
|
||||
});
|
||||
|
||||
window.strength_indicator = $('.password-strength-indicator');
|
||||
window.strength_message = $('.password-strength-message');
|
||||
window.strength_indicator = password_strength_indicator;
|
||||
window.strength_message = password_strength_message;
|
||||
|
||||
$('#new_password').on('keyup', function() {
|
||||
new_password.on('keyup', function() {
|
||||
window.clear_timeout();
|
||||
window.timout_password_strength = setTimeout(window.test_password_strength, 200);
|
||||
});
|
||||
|
||||
$("#old_password, #new_password, #confirm_password").on("keyup", frappe.utils.debounce(function () {
|
||||
let common_conditions = new_password.val() && confirm_password.val() && new_password.val() === confirm_password.val() &&
|
||||
password_strength_message.text() === password_strength_message_success
|
||||
|
||||
if (new_password.val() && old_password.val() === new_password.val()) {
|
||||
password_mismatch_message.text(password_not_same_as_old_password)
|
||||
.removeClass("hidden text-muted").addClass("text-danger");
|
||||
|
||||
password_strength_message.addClass("hidden");
|
||||
}
|
||||
if ((new_password.val() || old_password.val) && old_password.val() !== new_password.val()) {
|
||||
password_mismatch_message.addClass("hidden");
|
||||
password_strength_message.removeClass("hidden");
|
||||
password_mismatch_message.text('')
|
||||
}
|
||||
|
||||
if (new_password.val() === confirm_password.val() && old_password.val() !== new_password.val() ) {
|
||||
password_mismatch_message.addClass("hidden");
|
||||
password_strength_message.removeClass("hidden");
|
||||
}
|
||||
if (confirm_password.val() && new_password.val() !== confirm_password.val()) {
|
||||
password_mismatch_message.text(password_mismatch)
|
||||
.removeClass("hidden text-muted").addClass("text-danger");
|
||||
password_strength_message.addClass("hidden");
|
||||
}
|
||||
if ((key || (!key && old_password.val() && password_mismatch_message.text() !== password_not_same_as_old_password )) && common_conditions ) {
|
||||
update_button.prop("disabled", false).css("cursor", "pointer");
|
||||
}
|
||||
else {
|
||||
update_button.prop("disabled", true).css("cursor", "not-allowed");
|
||||
}
|
||||
},500)
|
||||
)
|
||||
|
||||
window.test_password_strength = function() {
|
||||
window.timout_password_strength = null;
|
||||
|
||||
var args = {
|
||||
key: frappe.utils.get_url_arg("key") || "",
|
||||
old_password: $("#old_password").val(),
|
||||
new_password: $("#new_password").val()
|
||||
key: key || "",
|
||||
old_password: old_password.val(),
|
||||
new_password: new_password.val()
|
||||
}
|
||||
|
||||
if (!args.new_password) {
|
||||
|
|
@ -195,9 +261,11 @@ frappe.ready(function() {
|
|||
message.push(feedback.help_msg);
|
||||
|
||||
} else {
|
||||
message.push("{{ _('Success! You are good to go 👍') }}");
|
||||
message.push(password_strength_message_success);
|
||||
}
|
||||
}
|
||||
password_mismatch_message.addClass('hidden');
|
||||
|
||||
strength_message.html(message.join(' ') || '').removeClass('hidden');
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue