112 lines
4.3 KiB
JavaScript
112 lines
4.3 KiB
JavaScript
/*
|
|
* Security page scripts.
|
|
*/
|
|
|
|
(function (win, doc, undef)
|
|
{
|
|
"use strict";
|
|
let sc = sbm.mdl.Security = { env: {} };
|
|
|
|
//--------------------------------------------------------------
|
|
sc.doSignin = function ()
|
|
{
|
|
sbm.clearControlErrors();
|
|
sbm.ajaxSignin = sbm.ajaxSignin || { url: sbm.url.base + 'Security/Ajax/Signin', formId: 'frmSignIn', callbackFn: sc.onSignin };
|
|
sbm.doAjaxRequest(sbm.ajaxSignin, 50);
|
|
}
|
|
sc.onSignin = function (response)
|
|
{
|
|
sbm.refreshControlValues(response.controlValues, '#frmSignIn');
|
|
if (!response.success) return;
|
|
sbm.goToPage('');
|
|
}
|
|
|
|
//--------------------------------------------------------------
|
|
sc.doScorePassword = function ()
|
|
{
|
|
sbm.ajaxScorePassword = sbm.ajaxScorePassword || { url: sbm.url.base + 'Security/Ajax/ScorePassword', formId: 'frmChangePassword', callbackFn: sc.onScorePassword, noWaitIcon: true };
|
|
sbm.doAjaxRequest(sbm.ajaxScorePassword, 250);
|
|
}
|
|
sc.onScorePassword = function (response)
|
|
{
|
|
var score = (response || {}).score || 0;
|
|
sbm.$prgPasswordStrength.progressbar("option", "value", score).removeClass('amber green').addClass(score > 3 ? 'green' : score > 2 ? 'amber' : '');
|
|
}
|
|
|
|
//--------------------------------------------------------------
|
|
sc.doChangePassword = function ()
|
|
{
|
|
sbm.clearControlErrors();
|
|
sbm.ajaxChangePassword = sbm.ajaxChangePassword || { url: sbm.url.base + 'Security/Ajax/StorePassword', formId: 'frmChangePassword', callbackFn: sc.onChangePassword };
|
|
sbm.doAjaxRequest(sbm.ajaxChangePassword, 50);
|
|
}
|
|
sc.onChangePassword = function (response)
|
|
{
|
|
sbm.refreshControlValues(response.controlValues);
|
|
if (!response.success) return;
|
|
if ($('#ifRpe').length)
|
|
sbm.goToPage('Security/Signin');
|
|
else sbm.goToPage('');
|
|
}
|
|
|
|
//--------------------------------------------------------------
|
|
sc.doRequestPassword = function ()
|
|
{
|
|
sbm.clearControlErrors();
|
|
sbm.ajaxRequestPassword = sbm.ajaxRequestPassword || { url: sbm.url.base + 'Security/Ajax/RequestPassword', formId: 'frmRequestPassword', callbackFn: sc.onRequestPassword };
|
|
sbm.doAjaxRequest(sbm.ajaxRequestPassword, 50);
|
|
}
|
|
sc.onRequestPassword = function (response)
|
|
{
|
|
sbm.refreshControlValues(response.controlValues);
|
|
if (!response.success) return;
|
|
var gotoSigninPage = function ()
|
|
{
|
|
sbm.goToPage('Security/Signin');
|
|
}
|
|
if (response.successMsg)
|
|
sbm.doAlert($('.sbm-page-caption').text(), response.successMsg, gotoSigninPage);
|
|
else gotoSigninPage();
|
|
}
|
|
|
|
//--------------------------------------------------------------
|
|
$(function ()
|
|
{
|
|
let env = { mode: { search: 1 }, data: {}, ajax: {}, $pnl: {}, $frm: {}, $ctrl: {}, $dlg: {} };
|
|
|
|
$(':input:enabled:visible:first').trigger('focus');
|
|
$('.sbm-input').on('input', function () { sbm.clearControlError(this); });
|
|
env.$frm.signIn = $('#frmSignIn');
|
|
if (env.$frm.signIn.length)
|
|
{
|
|
env.$frm.signIn.on('keypress', '#ifEmailAddress,#ifPassword,#chkKeepMeSignedIn', function (e) { if (e.which == 13 && $('#ifEmailAddress', env.$frm.signIn).val() && $('#ifPassword', env.$frm.signIn).val()) sc.doSignin(); });
|
|
env.$frm.signIn.on('click', '#pbSignIn', function () { sc.doSignin(); }).on('keypress', '#pbSignIn', function (e) { if (e.which == 13) sc.doSignin(); });
|
|
env.$ctrl.ctxt = env.$frm.signIn.find('#ifRepositoryContext');
|
|
env.$ctrl.email = env.$frm.signIn.find('#ifEmailAddress');
|
|
env.$ctrl.pwrd = env.$frm.signIn.find('#ifPassword');
|
|
if (env.$ctrl.ctxt.val())
|
|
{
|
|
env.$ctrl.email.focus();
|
|
if (env.$ctrl.email.val())
|
|
env.$ctrl.pwrd.focus();
|
|
}
|
|
}
|
|
env.$frm.chgPword = $('#frmChangePassword');
|
|
if (env.$frm.chgPword.length)
|
|
{
|
|
env.$frm.chgPword.on('keypress', '#ifPasswordCurrent,#ifPassword,#ifPasswordConfirm', function (e) { if (e.which == 13) sc.doChangePassword(); });
|
|
env.$frm.chgPword.on('click', '#pbChangePassword', function () { sc.doChangePassword(); });
|
|
env.$frm.chgPword.on('keyup', '#ifPassword', sc.doScorePassword);
|
|
sbm.$prgPasswordStrength = env.$frm.chgPword.find('.sbm-password-strength').progressbar({ max: 5 });
|
|
}
|
|
env.$frm.reqPword = $('#frmRequestPassword');
|
|
if (env.$frm.reqPword.length)
|
|
{
|
|
env.$frm.reqPword.on('keypress', '#ifEmailAddress', function (e) { if (e.which == 13) sc.doRequestPassword(); });
|
|
env.$frm.reqPword.on('click', '#pbRequestPassword', function () { sc.doRequestPassword(); });
|
|
}
|
|
});
|
|
|
|
}(window, window.document));
|
|
|
|
/* The End */ |