开启 ppr 优化渲染性能
This commit is contained in:
@@ -12,11 +12,13 @@ type TokenResp = {
|
||||
scope?: string
|
||||
}
|
||||
|
||||
export type LoginMode = 'phone_code' | 'password'
|
||||
|
||||
export async function login(props: {
|
||||
username: string
|
||||
password: string
|
||||
remember: boolean
|
||||
mode: 'phone_code' | 'password'
|
||||
mode: LoginMode
|
||||
}): Promise<ApiResponse> {
|
||||
// 尝试登录
|
||||
const result = await callByDevice<TokenResp>('/api/auth/token', {
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
'use server'
|
||||
import {ApiResponse} from '@/lib/api'
|
||||
import {callByDevice} from '@/actions/base'
|
||||
import {cookies} from 'next/headers'
|
||||
import crypto from 'crypto'
|
||||
import {getCap} from '@/lib/cap'
|
||||
|
||||
export async function sendSMS(props: {
|
||||
phone: string
|
||||
@@ -17,7 +16,9 @@ export async function sendSMS(props: {
|
||||
message: '请输入验证码',
|
||||
}
|
||||
}
|
||||
const valid = await checkCaptcha(props.captcha)
|
||||
|
||||
const cap = await getCap()
|
||||
const valid = await cap.validateToken(props.captcha)
|
||||
if (!valid) {
|
||||
return {
|
||||
success: false,
|
||||
@@ -37,32 +38,3 @@ export async function sendSMS(props: {
|
||||
throw new Error('验证码验证失败', {cause: error})
|
||||
}
|
||||
}
|
||||
|
||||
export async function checkCaptcha(userInput: string): Promise<boolean> {
|
||||
const cookieStore = await cookies()
|
||||
const hash = cookieStore.get('captcha_hash')?.value
|
||||
const salt = cookieStore.get('captcha_salt')?.value
|
||||
|
||||
// 如果没有找到验证码cookie,验证失败
|
||||
if (!hash || !salt) {
|
||||
console.log('验证码cookie不存在')
|
||||
return false
|
||||
}
|
||||
|
||||
// 使用相同的方法哈希用户输入的验证码
|
||||
const userInputHash = crypto
|
||||
.createHmac('sha256', salt)
|
||||
.update(userInput.toLowerCase())
|
||||
.digest('hex')
|
||||
|
||||
// 比较哈希值
|
||||
const isValid = hash === userInputHash
|
||||
|
||||
// 验证后删除验证码cookie,防止重复使用
|
||||
if (isValid) {
|
||||
cookieStore.delete('captcha_hash')
|
||||
cookieStore.delete('captcha_salt')
|
||||
}
|
||||
|
||||
return isValid
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user