core: fix change language

This commit is contained in:
undefined committed 2021-09-30 07:42:39 +08:00
1 parent 5b9601f8c3
commit b776155993
4 files changed
+9 -4

No files matched your search

+1
View File
@@ -253,6 +253,7 @@ class HomeSettingsHandler extends Handler {
}
for (const key in booleanKeys) if (!args[key]) $set[key] = false;
await setter($set);
if (args.viewLang && args.viewLang !== this.session.viewLang) this.session.viewLang = '';
this.back();
}
}
+6 -1
View File
@@ -83,6 +83,7 @@ class UserLoginHandler extends Handler {
udoc.checkPassword(password);
await user.setById(udoc._id, { loginat: new Date(), loginip: this.request.ip });
if (!udoc.hasPriv(PRIV.PRIV_USER_PROFILE)) throw new BlacklistedError(uname);
this.session.viewLang = '';
this.session.uid = udoc._id;
this.session.scope = PERM.PERM_ALL.toString();
this.session.save = rememberme;
@@ -175,7 +176,11 @@ class UserRegisterWithCodeHandler extends Handler {
const uid = await user.create(tdoc.mail, uname, password, undefined, this.request.ip);
await token.del(code, token.TYPE_REGISTRATION);
const [id, domain] = tdoc.mail.split('@');
if (domain === 'qq.com' && !Number.isNaN(+id)) await user.setById(uid, { avatar: `qq:${id}` });
const $set: any = {};
if (domain === 'qq.com' && !Number.isNaN(+id)) $set.avatar = `qq:${id}`;
if (this.session.viewLang) $set.viewLang = this.session.viewLang;
if (Object.keys($set).length) await user.setById(uid, $set);
this.session.viewLang = '';
this.session.uid = uid;
this.session.scpoe = PERM.PERM_ALL.toString();
this.response.redirect = this.url('home_settings', { category: 'preference' });
+1 -2
View File
@@ -527,8 +527,7 @@ export class Handler extends HandlerCommon {
this.session.scope = PERM.PERM_ALL.toString();
this.user = await user.getById(domainId, this.session.uid, this.session.scope);
}
if (this.user._id !== 0 && this.session.viewLang) this.user.viewLang = this.session.viewLang;
else if (this.user._id === 0) delete this.user.viewLang;
if (this.user._id === 0) delete this.user.viewLang;
this.user.avatarUrl = avatar(this.user.avatar, 128);
this.csrfToken = this.getCsrfToken(this.session._id || String.random(32));
this.UiContext.csrfToken = this.csrfToken;