mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-17 17:36:08 +08:00
core: fix bug (#551)
This commit is contained in:
1 parent
7d7b08ecf1
commit
335e8d6ee9
2 files changed
+28
-26
No files matched your search
@@ -301,11 +301,12 @@ class UserRegisterWithCodeHandler extends Handler {
|
||||
const tdoc = await token.get(code, token.TYPE_REGISTRATION);
|
||||
if (!tdoc || (!tdoc.mail && !tdoc.phone)) throw new InvalidTokenError(token.TYPE_TEXTS[token.TYPE_REGISTRATION], code);
|
||||
if (password !== verify) throw new VerifyPasswordError();
|
||||
if (tdoc.phone) tdoc.mail = `${tdoc.phone}@hydro.local`;
|
||||
if (tdoc.phone) tdoc.mail = `${String.random(12)}@hydro.local`;
|
||||
const uid = await user.create(tdoc.mail, uname, password, undefined, this.request.ip);
|
||||
await token.del(code, token.TYPE_REGISTRATION);
|
||||
const [id, mailDomain] = tdoc.mail.split('@');
|
||||
const $set: any = tdoc.set || {};
|
||||
if (tdoc.phone) $set.phone = tdoc.phone;
|
||||
if (mailDomain === '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);
|
||||
|
||||
@@ -293,7 +293,33 @@ SystemSetting(
|
||||
// eslint-disable-next-line import/no-mutable-exports
|
||||
export const langs: Record<string, LangConfig> = {};
|
||||
|
||||
declare module '../context' {
|
||||
interface Context {
|
||||
setting: SettingService;
|
||||
}
|
||||
}
|
||||
|
||||
const T = <F extends (...args: any[]) => any>(origFunc: F, disposeFunc?) =>
|
||||
function method(this: cordis.Service, ...args: Parameters<F>) {
|
||||
const res = origFunc(...args);
|
||||
this.caller?.on('dispose', () => (disposeFunc ? disposeFunc(res) : res()));
|
||||
};
|
||||
|
||||
export class SettingService extends Service {
|
||||
static readonly methods = ['PreferenceSetting', 'AccountSetting', 'DomainSetting', 'DomainUserSetting', 'SystemSetting'];
|
||||
PreferenceSetting = T(PreferenceSetting);
|
||||
AccountSetting = T(AccountSetting);
|
||||
DomainSetting = T(DomainSetting);
|
||||
DomainUserSetting = T(DomainUserSetting);
|
||||
SystemSetting = T(SystemSetting);
|
||||
constructor(ctx: Context) {
|
||||
super(ctx, 'setting', true);
|
||||
}
|
||||
}
|
||||
|
||||
export async function apply(ctx: Context) {
|
||||
Context.service('setting', SettingService);
|
||||
ctx.setting = new SettingService(ctx);
|
||||
logger.info('Ensuring settings');
|
||||
const system = global.Hydro.model.system;
|
||||
for (const setting of SYSTEM_SETTINGS) {
|
||||
@@ -320,31 +346,6 @@ export async function apply(ctx: Context) {
|
||||
});
|
||||
}
|
||||
|
||||
declare module '../context' {
|
||||
interface Context {
|
||||
setting: SettingService;
|
||||
}
|
||||
}
|
||||
|
||||
const T = <F extends (...args: any[]) => any>(origFunc: F, disposeFunc?) =>
|
||||
function method(this: cordis.Service, ...args: Parameters<F>) {
|
||||
const res = origFunc(...args);
|
||||
this.caller?.on('dispose', () => (disposeFunc ? disposeFunc(res) : res()));
|
||||
};
|
||||
|
||||
export class SettingService extends Service {
|
||||
static readonly methods = ['PreferenceSetting', 'AccountSetting', 'DomainSetting', 'DomainUserSetting', 'SystemSetting'];
|
||||
PreferenceSetting = T(PreferenceSetting);
|
||||
AccountSetting = T(AccountSetting);
|
||||
DomainSetting = T(DomainSetting);
|
||||
DomainUserSetting = T(DomainUserSetting);
|
||||
SystemSetting = T(SystemSetting);
|
||||
constructor(ctx: Context) {
|
||||
super(ctx, 'setting', true);
|
||||
}
|
||||
}
|
||||
Context.service('setting', SettingService);
|
||||
|
||||
global.Hydro.model.setting = {
|
||||
apply,
|
||||
SettingService,
|
||||
|
||||
Reference in new issue
Block a user