验证20%
This commit is contained in:
+37
-2
@@ -104,6 +104,39 @@
|
||||
return config.successUrl || '';
|
||||
}
|
||||
|
||||
function normalizeGenealogyId(value) {
|
||||
var id = value === undefined || value === null ? '' : String(value).trim();
|
||||
|
||||
if (typeof value === 'number' && !Number.isSafeInteger(value)) return '';
|
||||
return /^[1-9][0-9]*$/.test(id) ? id : '';
|
||||
}
|
||||
|
||||
function getPostLoginUrl(genealogies) {
|
||||
var ids = (Array.isArray(genealogies) ? genealogies : []).map(function (item) {
|
||||
return normalizeGenealogyId(item && item.genealogyId);
|
||||
}).filter(Boolean).filter(function (id, index, values) {
|
||||
return values.indexOf(id) === index;
|
||||
});
|
||||
|
||||
if (ids.length === 1) {
|
||||
return 'profile-family-home.html?genealogyId=' + encodeURIComponent(ids[0]);
|
||||
}
|
||||
|
||||
return 'profile-families.html';
|
||||
}
|
||||
|
||||
async function resolvePostLoginUrl(api, formType) {
|
||||
if ((formType !== 'login' && formType !== 'sms-login') || !api || !api.genealogiesMine) {
|
||||
return getSuccessUrl(formType);
|
||||
}
|
||||
|
||||
try {
|
||||
return getPostLoginUrl(await api.genealogiesMine());
|
||||
} catch (error) {
|
||||
return getSuccessUrl(formType);
|
||||
}
|
||||
}
|
||||
|
||||
function getFormCaptchaOperation(form, formType) {
|
||||
// 业务动作由当前脚本统一管理,避免散落在 HTML 属性中。
|
||||
var operationCode = getCaptchaOperation(formType);
|
||||
@@ -327,7 +360,7 @@
|
||||
setBusy(button, true);
|
||||
try {
|
||||
await api.login(buildLoginBody(values));
|
||||
root.location.href = getSuccessUrl('login');
|
||||
root.location.href = await resolvePostLoginUrl(api, 'login');
|
||||
} catch (error) {
|
||||
showMessage(error.message || '登录失败');
|
||||
} finally {
|
||||
@@ -348,7 +381,7 @@
|
||||
setBusy(button, true);
|
||||
try {
|
||||
await api.loginBySms(buildSmsLoginBody(values));
|
||||
root.location.href = getSuccessUrl('sms-login');
|
||||
root.location.href = await resolvePostLoginUrl(api, 'sms-login');
|
||||
} catch (error) {
|
||||
showMessage(error.message || '短信登录失败');
|
||||
} finally {
|
||||
@@ -489,6 +522,8 @@
|
||||
getCaptchaOperation: getCaptchaOperation,
|
||||
getFormCaptchaOperation: getFormCaptchaOperation,
|
||||
getSuccessUrl: getSuccessUrl,
|
||||
getPostLoginUrl: getPostLoginUrl,
|
||||
resolvePostLoginUrl: resolvePostLoginUrl,
|
||||
validateAuthValues: validateAuthValues,
|
||||
init: init
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user