From 0ddcee7336ed228894fc47627c1f3e94c83ebdfb Mon Sep 17 00:00:00 2001 From: undefined Date: Wed, 27 Aug 2025 03:23:37 +0800 Subject: [PATCH] core: add support for unlink oauth account --- packages/hydrooj/src/handler/home.ts | 7 +++++++ packages/hydrooj/src/model/oauth.ts | 6 +++--- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/packages/hydrooj/src/handler/home.ts b/packages/hydrooj/src/handler/home.ts index e6817d6a4..4ee54e1ee 100644 --- a/packages/hydrooj/src/handler/home.ts +++ b/packages/hydrooj/src/handler/home.ts @@ -259,6 +259,13 @@ class HomeSecurityHandler extends Handler { await this.ctx.oauth.providers[platform].get.call(this); } + @param('platform', Types.String) + async postUnlinkAccount({ }, platform: string) { + if (!this.ctx.oauth.providers[platform]) throw new ValidationError('platform'); + await this.ctx.oauth.unbind(platform, this.user._id); + this.back(); + } + @param('tokenDigest', Types.String) async postDeleteToken({ }, tokenDigest: string) { const sessions = await token.getSessionListByUid(this.user._id); diff --git a/packages/hydrooj/src/model/oauth.ts b/packages/hydrooj/src/model/oauth.ts index fb682c017..19b0671e3 100644 --- a/packages/hydrooj/src/model/oauth.ts +++ b/packages/hydrooj/src/model/oauth.ts @@ -50,7 +50,7 @@ export default class OauthModel extends Service { async [Context.init]() { await this.ctx.db.ensureIndexes(this.coll, - // { key: { platform: 1, id: 1 }, name: 'platform_id', unique: true }, + { key: { platform: 1, id: 1 }, name: 'platform_id', unique: true }, { key: { uid: 1, platform: 1 }, name: 'uid_platform' }, ); } @@ -70,8 +70,8 @@ export default class OauthModel extends Service { return res?.uid; } - async unbind(platform: string, id: string, uid: number) { - await this.coll.deleteOne({ platform, id, uid }); + async unbind(platform: string, uid: number) { + await this.coll.deleteOne({ platform, uid }); } async list(uid: number) {