2017-02-18 01:56:23 -07:00
|
|
|
'use strict';
|
2017-02-17 21:55:19 -07:00
|
|
|
|
2015-02-25 19:09:39 -05:00
|
|
|
|
2021-12-06 14:31:35 -05:00
|
|
|
define('forum/reset_code', ['zxcvbn', 'alerts'], function (zxcvbn, alerts) {
|
2021-10-12 17:26:18 +03:00
|
|
|
const ResetCode = {};
|
2014-10-08 15:36:47 -04:00
|
|
|
|
2016-10-13 11:43:39 +02:00
|
|
|
ResetCode.init = function () {
|
2021-10-12 17:26:18 +03:00
|
|
|
const reset_code = ajaxify.data.code;
|
2014-10-08 15:36:47 -04:00
|
|
|
|
2021-10-12 17:26:18 +03:00
|
|
|
const resetEl = $('#reset');
|
|
|
|
|
const password = $('#password');
|
|
|
|
|
const repeat = $('#repeat');
|
2014-10-08 15:36:47 -04:00
|
|
|
|
2016-10-13 11:43:39 +02:00
|
|
|
resetEl.on('click', function () {
|
2021-10-12 17:26:18 +03:00
|
|
|
const strength = zxcvbn(password.val());
|
2016-02-10 12:53:39 +02:00
|
|
|
if (password.val().length < ajaxify.data.minimumPasswordLength) {
|
2019-05-22 12:35:56 -04:00
|
|
|
$('#notice').removeClass('hidden');
|
|
|
|
|
$('#notice strong').translateText('[[reset_password:password_too_short]]');
|
2018-03-26 12:55:15 -04:00
|
|
|
} else if (password.val().length > 512) {
|
2019-05-22 12:35:56 -04:00
|
|
|
$('#notice').removeClass('hidden');
|
|
|
|
|
$('#notice strong').translateText('[[error:password-too-long]]');
|
2015-02-08 21:06:38 -05:00
|
|
|
} else if (password.val() !== repeat.val()) {
|
2019-05-22 12:35:56 -04:00
|
|
|
$('#notice').removeClass('hidden');
|
|
|
|
|
$('#notice strong').translateText('[[reset_password:passwords_do_not_match]]');
|
2018-03-26 12:35:51 -04:00
|
|
|
} else if (strength.score < ajaxify.data.minimumPasswordStrength) {
|
2019-05-22 12:35:56 -04:00
|
|
|
$('#notice').removeClass('hidden');
|
|
|
|
|
$('#notice strong').translateText('[[user:weak_password]]');
|
2014-10-08 15:36:47 -04:00
|
|
|
} else {
|
2020-10-21 13:05:46 -04:00
|
|
|
resetEl.prop('disabled', true).translateHtml('<i class="fa fa-spin fa-refresh"></i> [[reset_password:changing_password]]');
|
2014-10-08 15:36:47 -04:00
|
|
|
socket.emit('user.reset.commit', {
|
|
|
|
|
code: reset_code,
|
2017-02-17 19:31:21 -07:00
|
|
|
password: password.val(),
|
2016-10-13 11:43:39 +02:00
|
|
|
}, function (err) {
|
2015-02-08 21:06:38 -05:00
|
|
|
if (err) {
|
|
|
|
|
ajaxify.refresh();
|
2021-12-06 14:31:35 -05:00
|
|
|
return alerts.error(err);
|
2014-10-08 15:36:47 -04:00
|
|
|
}
|
2015-02-08 21:06:38 -05:00
|
|
|
|
2016-02-10 12:53:39 +02:00
|
|
|
window.location.href = config.relative_path + '/login';
|
2014-10-08 15:36:47 -04:00
|
|
|
});
|
|
|
|
|
}
|
2015-03-17 15:53:05 -04:00
|
|
|
return false;
|
2014-10-08 15:36:47 -04:00
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
return ResetCode;
|
|
|
|
|
});
|