2021-03-24 21:22:25 +08:00
|
|
|
import { Notification } from 'Common/Enums';
|
2022-03-14 22:42:05 +08:00
|
|
|
import { ClientSideKeyNameLastSignMe } from 'Common/EnumsUser';
|
2022-02-11 21:21:41 +08:00
|
|
|
import { SettingsGet, fireEvent } from 'Common/Globals';
|
2021-11-01 18:24:11 +08:00
|
|
|
import { getNotification, translatorReload, convertLangName } from 'Common/Translator';
|
2022-10-31 05:19:52 +08:00
|
|
|
import { addObservablesTo, addComputablesTo, addSubscribablesTo } from 'External/ko';
|
2016-08-17 06:01:20 +08:00
|
|
|
|
2021-01-27 17:59:15 +08:00
|
|
|
import { LanguageStore } from 'Stores/Language';
|
2016-08-17 06:01:20 +08:00
|
|
|
|
|
|
|
import * as Local from 'Storage/Client';
|
|
|
|
|
2020-09-15 01:40:56 +08:00
|
|
|
import Remote from 'Remote/User/Fetch';
|
2016-08-17 06:01:20 +08:00
|
|
|
|
2021-02-19 19:09:20 +08:00
|
|
|
import { decorateKoCommands, showScreenPopup } from 'Knoin/Knoin';
|
2021-11-08 00:06:08 +08:00
|
|
|
import { AbstractViewLogin } from 'Knoin/AbstractViews';
|
2016-08-17 06:01:20 +08:00
|
|
|
|
2021-01-26 05:00:13 +08:00
|
|
|
import { LanguagesPopupView } from 'View/Popup/Languages';
|
|
|
|
|
2022-03-14 22:42:05 +08:00
|
|
|
const
|
|
|
|
SignMeOff = 0,
|
2021-07-23 17:57:45 +08:00
|
|
|
SignMeOn = 1,
|
|
|
|
SignMeUnused = 2;
|
2021-01-25 05:58:06 +08:00
|
|
|
|
2020-09-04 18:05:17 +08:00
|
|
|
|
2022-02-11 21:52:04 +08:00
|
|
|
export class LoginUserView extends AbstractViewLogin {
|
2016-08-17 06:01:20 +08:00
|
|
|
constructor() {
|
2022-03-08 19:28:16 +08:00
|
|
|
super();
|
2014-08-21 23:08:34 +08:00
|
|
|
|
2022-10-31 05:19:52 +08:00
|
|
|
addObservablesTo(this, {
|
2021-03-10 18:44:48 +08:00
|
|
|
loadingDesc: SettingsGet('LoadingDescription'),
|
2020-11-26 17:41:53 +08:00
|
|
|
|
2021-03-16 23:06:16 +08:00
|
|
|
email: SettingsGet('DevEmail'),
|
|
|
|
password: SettingsGet('DevPassword'),
|
2020-10-26 19:54:03 +08:00
|
|
|
signMe: false,
|
2013-11-16 06:21:12 +08:00
|
|
|
|
2020-10-26 19:54:03 +08:00
|
|
|
emailError: false,
|
|
|
|
passwordError: false,
|
2014-04-06 03:48:22 +08:00
|
|
|
|
2020-10-26 19:54:03 +08:00
|
|
|
submitRequest: false,
|
|
|
|
submitError: '',
|
2022-04-29 05:10:21 +08:00
|
|
|
submitErrorAdditional: '',
|
2020-10-26 19:54:03 +08:00
|
|
|
|
|
|
|
langRequest: false,
|
|
|
|
|
2021-07-23 17:57:45 +08:00
|
|
|
signMeType: SignMeUnused
|
2020-10-26 19:54:03 +08:00
|
|
|
});
|
|
|
|
|
2021-03-10 18:44:48 +08:00
|
|
|
this.allowLanguagesOnLogin = !!SettingsGet('AllowLanguagesOnLogin');
|
2020-10-26 20:43:56 +08:00
|
|
|
|
|
|
|
this.language = LanguageStore.language;
|
|
|
|
this.languages = LanguageStore.languages;
|
|
|
|
|
|
|
|
this.bSendLanguage = false;
|
|
|
|
|
2022-10-31 05:19:52 +08:00
|
|
|
addComputablesTo(this, {
|
2013-11-16 06:21:12 +08:00
|
|
|
|
2020-10-26 19:54:03 +08:00
|
|
|
languageFullName: () => convertLangName(this.language()),
|
2015-04-14 02:45:09 +08:00
|
|
|
|
2021-07-23 17:57:45 +08:00
|
|
|
signMeVisibility: () => SignMeUnused !== this.signMeType()
|
2016-08-17 06:01:20 +08:00
|
|
|
});
|
2015-04-14 02:45:09 +08:00
|
|
|
|
2022-10-31 05:19:52 +08:00
|
|
|
addSubscribablesTo(this, {
|
2021-07-23 17:57:45 +08:00
|
|
|
email: () => this.emailError(false),
|
2014-04-06 03:48:22 +08:00
|
|
|
|
2020-10-26 19:54:03 +08:00
|
|
|
password: () => this.passwordError(false),
|
2014-04-06 03:48:22 +08:00
|
|
|
|
2022-04-29 05:10:21 +08:00
|
|
|
submitError: value => value || this.submitErrorAdditional(''),
|
2015-04-14 02:45:09 +08:00
|
|
|
|
2021-07-23 17:57:45 +08:00
|
|
|
signMeType: iValue => this.signMe(SignMeOn === iValue),
|
2021-03-23 21:48:34 +08:00
|
|
|
|
|
|
|
language: value => {
|
|
|
|
this.langRequest(true);
|
2022-12-23 19:22:57 +08:00
|
|
|
translatorReload(value).then(
|
2021-03-23 21:48:34 +08:00
|
|
|
() => {
|
|
|
|
this.langRequest(false);
|
|
|
|
this.bSendLanguage = true;
|
|
|
|
},
|
|
|
|
() => this.langRequest(false)
|
|
|
|
);
|
|
|
|
}
|
2020-10-26 19:54:03 +08:00
|
|
|
});
|
2015-01-08 22:00:03 +08:00
|
|
|
|
2021-03-10 18:44:48 +08:00
|
|
|
if (SettingsGet('AdditionalLoginError') && !this.submitError()) {
|
|
|
|
this.submitError(SettingsGet('AdditionalLoginError'));
|
2016-08-17 06:01:20 +08:00
|
|
|
}
|
2021-02-19 19:09:20 +08:00
|
|
|
|
|
|
|
decorateKoCommands(this, {
|
|
|
|
submitCommand: self => !self.submitRequest()
|
|
|
|
});
|
2016-09-03 07:19:37 +08:00
|
|
|
}
|
2016-09-02 04:41:36 +08:00
|
|
|
|
2022-11-30 00:29:06 +08:00
|
|
|
hideError() {
|
|
|
|
this.submitError('');
|
|
|
|
}
|
|
|
|
|
|
|
|
toggleSignMe() {
|
|
|
|
this.signMe(!this.signMe());
|
|
|
|
}
|
|
|
|
|
2021-03-23 18:28:36 +08:00
|
|
|
submitCommand(self, event) {
|
2022-06-14 02:54:36 +08:00
|
|
|
const email = this.email().trim();
|
|
|
|
this.email(email);
|
|
|
|
|
2021-07-23 17:40:03 +08:00
|
|
|
let form = event.target.form,
|
|
|
|
data = new FormData(form),
|
2022-04-29 19:07:49 +08:00
|
|
|
valid = form.reportValidity() && fireEvent('sm-user-login', data, 1);
|
2016-12-15 05:56:17 +08:00
|
|
|
|
2022-06-14 02:54:36 +08:00
|
|
|
this.emailError(!email);
|
2021-07-23 17:40:03 +08:00
|
|
|
this.passwordError(!this.password());
|
2021-03-24 21:22:25 +08:00
|
|
|
this.formError(!valid);
|
2016-09-02 04:41:36 +08:00
|
|
|
|
2021-03-23 18:28:36 +08:00
|
|
|
if (valid) {
|
|
|
|
this.submitRequest(true);
|
2021-07-23 17:40:03 +08:00
|
|
|
data.set('Language', this.bSendLanguage ? this.language() : '');
|
|
|
|
data.set('SignMe', this.signMe() ? 1 : 0);
|
2021-12-03 06:15:24 +08:00
|
|
|
Remote.request('Login',
|
2021-03-16 16:46:23 +08:00
|
|
|
(iError, oData) => {
|
2022-02-11 21:21:41 +08:00
|
|
|
fireEvent('sm-user-login-response', {
|
|
|
|
error: iError,
|
|
|
|
data: oData
|
|
|
|
});
|
2021-03-18 19:33:13 +08:00
|
|
|
if (iError) {
|
2021-03-23 18:28:36 +08:00
|
|
|
this.submitRequest(false);
|
2021-03-18 19:33:13 +08:00
|
|
|
if (Notification.InvalidInputArgument == iError) {
|
|
|
|
iError = Notification.AuthError;
|
2019-07-05 03:19:24 +08:00
|
|
|
}
|
2022-09-02 17:52:07 +08:00
|
|
|
this.submitError(getNotification(iError, oData?.ErrorMessage,
|
2021-07-14 16:32:21 +08:00
|
|
|
Notification.UnknownNotification));
|
2022-09-02 17:52:07 +08:00
|
|
|
this.submitErrorAdditional(oData?.ErrorMessageAdditional);
|
2019-07-05 03:19:24 +08:00
|
|
|
} else {
|
2021-11-01 18:24:11 +08:00
|
|
|
rl.setData(oData.Result);
|
2019-07-05 03:19:24 +08:00
|
|
|
}
|
|
|
|
},
|
2021-12-03 06:15:24 +08:00
|
|
|
data
|
2019-07-05 03:19:24 +08:00
|
|
|
);
|
|
|
|
|
2022-03-14 22:42:05 +08:00
|
|
|
Local.set(ClientSideKeyNameLastSignMe, this.signMe() ? '-1-' : '-0-');
|
2021-03-23 18:28:36 +08:00
|
|
|
}
|
2016-09-02 04:41:36 +08:00
|
|
|
|
2021-03-23 18:28:36 +08:00
|
|
|
return valid;
|
2016-06-30 08:02:45 +08:00
|
|
|
}
|
2016-08-17 06:01:20 +08:00
|
|
|
|
2021-11-08 00:06:08 +08:00
|
|
|
onBuild(dom) {
|
|
|
|
super.onBuild(dom);
|
2016-06-30 08:02:45 +08:00
|
|
|
|
2022-03-14 22:42:05 +08:00
|
|
|
const signMe = (SettingsGet('SignMe') || '').toLowerCase();
|
2014-08-21 23:08:34 +08:00
|
|
|
|
2019-07-05 03:19:24 +08:00
|
|
|
switch (signMe) {
|
2021-07-23 17:57:45 +08:00
|
|
|
case 'defaultoff':
|
|
|
|
case 'defaulton':
|
2019-07-05 03:19:24 +08:00
|
|
|
this.signMeType(
|
2021-07-23 17:57:45 +08:00
|
|
|
'defaulton' === signMe ? SignMeOn : SignMeOff
|
2019-07-05 03:19:24 +08:00
|
|
|
);
|
2016-08-17 06:01:20 +08:00
|
|
|
|
2022-03-14 22:42:05 +08:00
|
|
|
switch (Local.get(ClientSideKeyNameLastSignMe)) {
|
2016-08-17 06:01:20 +08:00
|
|
|
case '-1-':
|
2021-07-23 17:57:45 +08:00
|
|
|
this.signMeType(SignMeOn);
|
2016-08-17 06:01:20 +08:00
|
|
|
break;
|
|
|
|
case '-0-':
|
2021-07-23 17:57:45 +08:00
|
|
|
this.signMeType(SignMeOff);
|
2016-08-17 06:01:20 +08:00
|
|
|
break;
|
|
|
|
// no default
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
default:
|
2021-07-23 17:57:45 +08:00
|
|
|
this.signMeType(SignMeUnused);
|
2016-08-17 06:01:20 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2014-07-25 06:28:10 +08:00
|
|
|
|
2016-08-17 06:01:20 +08:00
|
|
|
selectLanguage() {
|
2021-01-26 05:00:13 +08:00
|
|
|
showScreenPopup(LanguagesPopupView, [this.language, this.languages(), LanguageStore.userLanguage()]);
|
2016-08-17 06:01:20 +08:00
|
|
|
}
|
|
|
|
}
|