mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-19 17:38:19 +08:00
core: add provideModule and injectUI API
This commit is contained in:
1 parent
672c553f4c
commit
28f03dbcbd
18 files changed
+211
-97
No files matched your search
@@ -5,7 +5,7 @@ import AdmZip from 'adm-zip';
|
||||
import fs from 'fs-extra';
|
||||
import yaml from 'js-yaml';
|
||||
import { ValidationError } from '../error';
|
||||
import { ProblemAdd } from '../lib/ui';
|
||||
import { PluginContext } from '../loader';
|
||||
import { PERM, PRIV } from '../model/builtin';
|
||||
import problem, { ProblemDoc } from '../model/problem';
|
||||
import { Handler } from '../service/server';
|
||||
@@ -93,7 +93,7 @@ class ProblemImportHydroHandler extends Handler {
|
||||
}
|
||||
}
|
||||
|
||||
export async function apply(ctx) {
|
||||
ProblemAdd('problem_import_hydro', {}, 'copy', 'Import From Hydro');
|
||||
export async function apply(ctx: PluginContext) {
|
||||
ctx.Route('problem_import_hydro', '/problem/import/hydro', ProblemImportHydroHandler, PERM.PERM_CREATE_PROBLEM);
|
||||
ctx.inject('ProblemAdd', 'problem_import_hydro', { icon: 'copy', text: 'Import From Hydro' });
|
||||
}
|
||||
@@ -6,7 +6,7 @@ import {
|
||||
SystemError, UserAlreadyExistError, UserFacingError,
|
||||
UserNotFoundError, ValidationError, VerifyPasswordError,
|
||||
} from '../error';
|
||||
import { OAuthUserResponse, Udoc, User } from '../interface';
|
||||
import { Udoc, User } from '../interface';
|
||||
import avatar from '../lib/avatar';
|
||||
import { sendMail } from '../lib/mail';
|
||||
import { isEmail, isPassword } from '../lib/validator';
|
||||
@@ -359,7 +359,7 @@ class OauthHandler extends Handler {
|
||||
|
||||
@param('type', Types.String)
|
||||
async get(domainId: string, type: string) {
|
||||
await global.Hydro.lib[`oauth_${type}`]?.get?.call(this);
|
||||
await global.Hydro.module.oauth[type]?.get.call(this);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -367,8 +367,8 @@ class OauthCallbackHandler extends Handler {
|
||||
noCheckPermView = true;
|
||||
|
||||
async get(args: any) {
|
||||
if (!global.Hydro.lib[`oauth_${args.type}`]) throw new UserFacingError('Oauth type');
|
||||
const r = await global.Hydro.lib[`oauth_${args.type}`].callback.call(this, args) as OAuthUserResponse;
|
||||
if (!global.Hydro.module.oauth[args.type]) throw new UserFacingError('Oauth type');
|
||||
const r = await global.Hydro.module.oauth[args.type].callback.call(this, args);
|
||||
const uid = await oauth.get(r._id);
|
||||
if (uid) {
|
||||
await user.setById(uid, { loginat: new Date(), loginip: this.request.ip });
|
||||
|
||||
Reference in new issue
Block a user