250 lines
10 KiB
JavaScript
250 lines
10 KiB
JavaScript
import { OakPreConditionUnsetException } from "oak-domain/lib/types";
|
|
import { encryptPasswordSha1 } from "../../../utils/password";
|
|
export default OakComponent({
|
|
isList: false,
|
|
data: {
|
|
allowRegister: false,
|
|
loginNameMin: 2,
|
|
loginNameMax: 8,
|
|
loginNameNeedVerify: false,
|
|
loginNameRegexs: [],
|
|
loginNameTip: '',
|
|
mode: 'all',
|
|
pwdMin: 8,
|
|
pwdMax: 24,
|
|
pwdNeedVerify: false,
|
|
pwdRegexs: [],
|
|
pwdTip: '',
|
|
loginNameRulesMp: [], //小程序校验账号
|
|
passwordRulesMp: [], //小程序校验密码
|
|
confirmRulesMp: [], //小程序校验密码确认
|
|
loginName: '',
|
|
password: '',
|
|
confirm: '',
|
|
loginNameHasErr: false,
|
|
passwordHasErr: false,
|
|
confirmHasErr: false,
|
|
},
|
|
properties: {
|
|
goLogin: undefined,
|
|
goBack: undefined,
|
|
},
|
|
lifetimes: {
|
|
async ready() {
|
|
const application = this.features.application.getApplication();
|
|
const { result: applicationPassports } = await this.features.cache.exec('getApplicationPassports', { applicationId: application.id });
|
|
const loginNameAP = applicationPassports.find((ele) => ele.passport.type === 'loginName');
|
|
const loginNameConfig = loginNameAP?.passport?.config;
|
|
const loginNameMin = loginNameConfig?.min ?? 2;
|
|
const loginNameMax = loginNameConfig?.max ?? 8;
|
|
const loginNameNeedVerify = loginNameConfig?.verify;
|
|
const loginNameRegexs = (loginNameConfig?.regexs && loginNameConfig?.regexs.length > 0) ? loginNameConfig?.regexs : [];
|
|
const loginNameTip = loginNameConfig?.tip;
|
|
const allowRegister = !!loginNameConfig?.register;
|
|
const pwdConfig = application?.system?.config?.Password;
|
|
const mode = pwdConfig?.mode ?? 'all';
|
|
const pwdMin = pwdConfig?.min ?? 8;
|
|
const pwdMax = pwdConfig?.max ?? 24;
|
|
const pwdNeedVerify = !!pwdConfig?.verify;
|
|
const pwdRegexs = (pwdConfig?.regexs && pwdConfig?.regexs.length > 0) ? pwdConfig?.regexs : [];
|
|
const pwdTip = pwdConfig?.tip ?? '';
|
|
const loginNameRulesMp = [
|
|
{ required: true, message: this.t('placeholder.loginName'), trigger: 'blur' },
|
|
// { min: loginNameMin, message: this.t('validator.loginNameMin', { loginNameMin }), trigger: 'change' },
|
|
// { max: loginNameMax, message: this.t('validator.loginNameMax', { loginNameMax }), trigger: 'change' },
|
|
{
|
|
validator: (rule, value, callback, source) => {
|
|
if (!value || value.length < loginNameMin) {
|
|
this.setState({
|
|
loginNameHasErr: true
|
|
});
|
|
callback(false);
|
|
return;
|
|
}
|
|
this.setState({
|
|
loginNameHasErr: false
|
|
});
|
|
callback();
|
|
}, message: this.t('validator.loginNameMin', { loginNameMin }), trigger: 'change'
|
|
},
|
|
{
|
|
validator: (rule, value, callback, source) => {
|
|
if (!value || value.length > loginNameMax) {
|
|
this.setState({
|
|
loginNameHasErr: true
|
|
});
|
|
callback(false);
|
|
return;
|
|
}
|
|
this.setState({
|
|
loginNameHasErr: false
|
|
});
|
|
callback();
|
|
}, message: this.t('validator.loginNameMax', { loginNameMax }), trigger: 'change'
|
|
},
|
|
{
|
|
validator: (rule, value, callback, source) => {
|
|
if (!!loginNameNeedVerify && loginNameRegexs && loginNameRegexs.length > 0) {
|
|
for (const regex of loginNameRegexs) {
|
|
const pattern = new RegExp(regex);
|
|
if (!pattern.test(value)) {
|
|
this.setState({
|
|
loginNameHasErr: true
|
|
});
|
|
callback(false);
|
|
return;
|
|
}
|
|
}
|
|
}
|
|
this.setState({
|
|
loginNameHasErr: false
|
|
});
|
|
callback();
|
|
},
|
|
message: this.t('validator.loginNameVerify'),
|
|
trigger: 'change'
|
|
}
|
|
];
|
|
const passwordRulesMp = [
|
|
{ required: true, message: this.t('placeholder.password'), trigger: 'blur' },
|
|
// { min: pwdMin, message: this.t('validator.pwdMin', { pwdMin }), trigger: 'change' },
|
|
// { max: pwdMax, message: this.t('validator.pwdMax', { pwdMax }), trigger: 'change' },
|
|
{
|
|
validator: (rule, value, callback, source) => {
|
|
if (!value || value.length < pwdMin) {
|
|
this.setState({
|
|
passwordHasErr: true
|
|
});
|
|
callback(false);
|
|
return;
|
|
}
|
|
this.setState({
|
|
passwordHasErr: false
|
|
});
|
|
callback();
|
|
}, message: this.t('validator.pwdMin', { pwdMin }), trigger: 'change'
|
|
},
|
|
{
|
|
validator: (rule, value, callback, source) => {
|
|
if (!value || value.length > pwdMax) {
|
|
this.setState({
|
|
passwordHasErr: true
|
|
});
|
|
callback(false);
|
|
return;
|
|
}
|
|
this.setState({
|
|
passwordHasErr: false
|
|
});
|
|
callback();
|
|
}, message: this.t('validator.pwdMax', { pwdMax }), trigger: 'change'
|
|
},
|
|
{
|
|
validator: (rule, value, callback, source) => {
|
|
if (!!pwdNeedVerify && pwdRegexs && pwdRegexs.length > 0) {
|
|
for (const regex of pwdRegexs) {
|
|
const pattern = new RegExp(regex);
|
|
if (!pattern.test(value)) {
|
|
this.setState({
|
|
hasErr: true
|
|
});
|
|
callback(false);
|
|
return;
|
|
}
|
|
}
|
|
}
|
|
this.setState({
|
|
hasErr: false
|
|
});
|
|
callback();
|
|
},
|
|
message: this.t('validator.pwdVerify'),
|
|
trigger: 'change'
|
|
}
|
|
];
|
|
const confirmRulesMp = [
|
|
{ required: true, message: this.t('validator.noRepwd'), trigger: 'blur' },
|
|
{
|
|
validator: (rule, value, callback, source) => {
|
|
const { password } = this.state;
|
|
if (password !== value) {
|
|
this.setState({
|
|
confirmHasErr: true
|
|
});
|
|
callback(false);
|
|
return;
|
|
}
|
|
this.setState({
|
|
confirmHasErr: false
|
|
});
|
|
callback();
|
|
},
|
|
message: this.t('validator.pwdDiff'),
|
|
trigger: 'change'
|
|
}
|
|
];
|
|
this.setState({
|
|
allowRegister,
|
|
loginNameMin,
|
|
loginNameMax,
|
|
loginNameNeedVerify,
|
|
loginNameRegexs,
|
|
loginNameTip,
|
|
mode,
|
|
pwdMin,
|
|
pwdMax,
|
|
pwdNeedVerify,
|
|
pwdRegexs,
|
|
pwdTip,
|
|
loginNameRulesMp,
|
|
passwordRulesMp,
|
|
confirmRulesMp,
|
|
}, () => this.reRender());
|
|
},
|
|
},
|
|
methods: {
|
|
async onConfirm(loginName, password) {
|
|
const { mode } = this.state;
|
|
let pwd = password;
|
|
if (mode === 'sha1') {
|
|
pwd = encryptPasswordSha1(password);
|
|
}
|
|
try {
|
|
await this.features.cache.exec('registerUserByLoginName', {
|
|
loginName,
|
|
password: pwd
|
|
});
|
|
this.setMessage({
|
|
type: 'success',
|
|
content: this.t('success')
|
|
});
|
|
}
|
|
catch (err) {
|
|
if (err instanceof OakPreConditionUnsetException || err.name === 'OakPreConditionUnsetException') {
|
|
this.setMessage({
|
|
type: 'error',
|
|
content: err.message
|
|
});
|
|
}
|
|
else {
|
|
throw err;
|
|
}
|
|
}
|
|
},
|
|
setValueMp(input) {
|
|
const { detail, target: { dataset }, } = input;
|
|
const { attr } = dataset;
|
|
const { value } = detail;
|
|
this.setState({ [attr]: value });
|
|
},
|
|
async onConfirmMp() {
|
|
const { loginName, password, } = this.state;
|
|
await this.onConfirm(loginName, password);
|
|
},
|
|
goLoginMp() {
|
|
const { goLogin } = this.props;
|
|
goLogin && goLogin();
|
|
}
|
|
},
|
|
});
|