Bernd Storath
3 days ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with
21 additions and
0 deletions
-
src/server/api/me/totp.post.ts
-
src/server/database/repositories/user/service.ts
-
src/server/database/repositories/user/types.ts
|
|
|
@ -23,6 +23,13 @@ export default definePermissionEventHandler( |
|
|
|
checkPermissions(user); |
|
|
|
|
|
|
|
if (body.type === 'setup') { |
|
|
|
if (user.totpVerified) { |
|
|
|
throw createError({ |
|
|
|
statusCode: 409, |
|
|
|
statusMessage: 'TOTP is already enabled', |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
const key = new Secret({ size: 20 }); |
|
|
|
|
|
|
|
const totp = new TOTP({ |
|
|
|
@ -50,6 +57,13 @@ export default definePermissionEventHandler( |
|
|
|
type: 'created', |
|
|
|
} as Response; |
|
|
|
} else if (body.type === 'delete') { |
|
|
|
if (!user.totpVerified) { |
|
|
|
throw createError({ |
|
|
|
statusCode: 409, |
|
|
|
statusMessage: 'TOTP is not enabled', |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
await Database.users.deleteTotpKey(user.id, body.currentPassword); |
|
|
|
|
|
|
|
return { |
|
|
|
|
|
|
|
@ -221,6 +221,10 @@ export class UserService { |
|
|
|
throw new Error('User not found'); |
|
|
|
} |
|
|
|
|
|
|
|
if (txUser.totpVerified) { |
|
|
|
throw new Error('TOTP is already verified'); |
|
|
|
} |
|
|
|
|
|
|
|
const totpKey = txUser.totpKey; |
|
|
|
if (!totpKey) { |
|
|
|
throw new Error('TOTP key is not set'); |
|
|
|
|
|
|
|
@ -18,7 +18,10 @@ const remember = z.boolean({ message: t('zod.user.remember') }); |
|
|
|
|
|
|
|
const totpCode = z |
|
|
|
.string({ message: t('zod.user.totpCode') }) |
|
|
|
// min and max to improve error messages
|
|
|
|
.min(6, t('zod.user.totpCode')) |
|
|
|
.max(6, t('zod.user.totpCode')) |
|
|
|
.regex(/^\d{6}$/, t('zod.user.totpCode')) |
|
|
|
.pipe(safeStringRefine); |
|
|
|
|
|
|
|
export const UserLoginSchema = z.object({ |
|
|
|
|