验证码区分mobile与email

This commit is contained in:
lxy 2024-08-19 11:48:02 +08:00
parent 8ba03c64b5
commit 24ccac2059
4 changed files with 34 additions and 26 deletions

View File

@ -606,7 +606,8 @@ export async function loginByMobile<ED extends EntityDict>(
expired: 1, expired: 1,
}, },
filter: { filter: {
mobile, origin: 'mobile',
content: mobile,
code: captcha, code: captcha,
}, },
sorter: [ sorter: [
@ -1574,7 +1575,8 @@ export async function sendCaptcha<ED extends EntityDict>(
'captcha', 'captcha',
{ {
filter: { filter: {
mobile, origin: 'mobile',
content: mobile,
$$createAt$$: { $$createAt$$: {
$gt: now - 3600 * 1000, $gt: now - 3600 * 1000,
}, },
@ -1600,7 +1602,8 @@ export async function sendCaptcha<ED extends EntityDict>(
$$createAt$$: 1, $$createAt$$: 1,
}, },
filter: { filter: {
mobile, origin: 'mobile',
content: mobile,
$$createAt$$: { $$createAt$$: {
$gt: now - duration * 60 * 1000, $gt: now - duration * 60 * 1000,
}, },
@ -1657,7 +1660,8 @@ export async function sendCaptcha<ED extends EntityDict>(
action: 'create', action: 'create',
data: { data: {
id, id,
mobile, origin: 'mobile',
content: mobile,
code, code,
visitorId, visitorId,
env, env,

View File

@ -8,17 +8,17 @@ import dayjs from 'dayjs';
import { BRC } from "../types/RuntimeCxt"; import { BRC } from "../types/RuntimeCxt";
export async function mergeUser<ED extends EntityDict>( export async function mergeUser<ED extends EntityDict>(
params: { params: {
from: string, from: string,
to: string, to: string,
mergeMobile?: true, mergeMobile?: true,
mergeEmail?: true, mergeEmail?: true,
mergeWechatUser?: true, mergeWechatUser?: true,
}, context: BRC<ED>, innerLogic?: boolean }, context: BRC<ED>, innerLogic?: boolean
) { ) {
const { from, to, mergeMobile, mergeEmail, mergeWechatUser } = params; const { from, to, mergeMobile, mergeEmail, mergeWechatUser } = params;
if (!innerLogic && !context.isRoot()) { if (!innerLogic && !context.isRoot()) {
throw new OakUserUnpermittedException('user', { id: 'merge', action: 'merge', data: {}, filter: { id: from }}, '不允许执行mergeUser操作'); throw new OakUserUnpermittedException('user', { id: 'merge', action: 'merge', data: {}, filter: { id: from } }, '不允许执行mergeUser操作');
} }
assert(from); assert(from);
assert(to); assert(to);
@ -91,7 +91,7 @@ export async function mergeUser<ED extends EntityDict>(
], ],
}, },
}, {}); }, {});
if (mergeEmail) { if (mergeEmail) {
await context.operate('email', { await context.operate('email', {
id: await generateNewIdAsync(), id: await generateNewIdAsync(),
@ -228,19 +228,19 @@ export async function updateUserPassword<ED extends EntityDict>(params: { userId
{ {
filter: lastSuccessfulTemp filter: lastSuccessfulTemp
? { ? {
userId, userId,
$$seq$$: { $$seq$$: {
$gt: lastSuccessfulTemp.$$seq$$!, $gt: lastSuccessfulTemp.$$seq$$!,
}, },
result: 'fail', result: 'fail',
} }
: { : {
userId, userId,
$$createAt$$: { $$createAt$$: {
$gt: dayjs().startOf('day').valueOf(), $gt: dayjs().startOf('day').valueOf(),
}, },
result: 'fail', result: 'fail',
}, },
}, },
{ {
dontCollect: true, dontCollect: true,
@ -326,7 +326,8 @@ export async function updateUserPassword<ED extends EntityDict>(params: { userId
id: 1, id: 1,
}, },
filter: { filter: {
mobile, origin: 'mobile',
content: mobile,
code: captcha, code: captcha,
expired: false, expired: false,
}, },

View File

@ -47,7 +47,8 @@ export async function unbindingWechat<ED extends EntityDict>(
expired: 1, expired: 1,
}, },
filter: { filter: {
mobile, origin: 'mobile',
content: mobile,
code: captcha, code: captcha,
}, },
sorter: [{ sorter: [{

View File

@ -4,7 +4,8 @@ import { ActionDef, Index } from 'oak-domain/lib/types';
import { EntityDesc } from 'oak-domain/lib/types/EntityDesc'; import { EntityDesc } from 'oak-domain/lib/types/EntityDesc';
export interface Schema extends EntityShape { export interface Schema extends EntityShape {
mobile: String<11>; origin: 'mobile' | 'email';
content: String<32>;
code: String<4>; code: String<4>;
visitorId: Text; visitorId: Text;
reason?: Text; reason?: Text;
@ -36,7 +37,8 @@ export const entityDesc: EntityDesc<Schema, Action, '', {
zh_CN: { zh_CN: {
name: '验证码', name: '验证码',
attr: { attr: {
mobile: '手机号', origin: '源',
content: '内容',
code: '验证码', code: '验证码',
visitorId: '用户标识', visitorId: '用户标识',
reason: '失败原因', reason: '失败原因',
@ -71,7 +73,7 @@ export const entityDesc: EntityDesc<Schema, Action, '', {
name: 'index_mobile_code', name: 'index_mobile_code',
attributes: [ attributes: [
{ {
name: 'mobile', name: 'content',
direction: 'ASC', direction: 'ASC',
}, },
{ {