mirror of
https://github.com/labring/FastGPT.git
synced 2025-07-29 01:40:51 +00:00
Feat: prelogin (#4773)
* add prelogin api (#4762) * add prelogin api * move type.d.ts * perf: prelogin code * doc * fix: ts --------- Co-authored-by: dreamer6680 <1468683855@qq.com>
This commit is contained in:
63
packages/service/support/user/auth/controller.ts
Normal file
63
packages/service/support/user/auth/controller.ts
Normal file
@@ -0,0 +1,63 @@
|
||||
import type { UserAuthTypeEnum } from '@fastgpt/global/support/user/auth/constants';
|
||||
import { MongoUserAuth } from './schema';
|
||||
import { i18nT } from '../../../../web/i18n/utils';
|
||||
import { mongoSessionRun } from '../../../common/mongo/sessionRun';
|
||||
|
||||
export const addAuthCode = async ({
|
||||
key,
|
||||
code,
|
||||
openid,
|
||||
type,
|
||||
expiredTime
|
||||
}: {
|
||||
key: string;
|
||||
code?: string;
|
||||
openid?: string;
|
||||
type: `${UserAuthTypeEnum}`;
|
||||
expiredTime?: Date;
|
||||
}) => {
|
||||
return MongoUserAuth.updateOne(
|
||||
{
|
||||
key,
|
||||
type
|
||||
},
|
||||
{
|
||||
code,
|
||||
openid,
|
||||
expiredTime
|
||||
},
|
||||
{
|
||||
upsert: true
|
||||
}
|
||||
);
|
||||
};
|
||||
|
||||
export const authCode = async ({
|
||||
key,
|
||||
type,
|
||||
code
|
||||
}: {
|
||||
key: string;
|
||||
type: `${UserAuthTypeEnum}`;
|
||||
code: string;
|
||||
}) => {
|
||||
return mongoSessionRun(async (session) => {
|
||||
const result = await MongoUserAuth.findOne(
|
||||
{
|
||||
key,
|
||||
type,
|
||||
code: { $regex: new RegExp(`^${code}$`, 'i') }
|
||||
},
|
||||
undefined,
|
||||
{ session }
|
||||
);
|
||||
|
||||
if (!result) {
|
||||
return Promise.reject(i18nT('common:error.code_error'));
|
||||
}
|
||||
|
||||
await result.deleteOne({ session });
|
||||
|
||||
return 'SUCCESS';
|
||||
});
|
||||
};
|
Reference in New Issue
Block a user