mirror of
https://github.com/whoswhip/Sharpbin.git
synced 2026-12-06 02:48:43 +00:00
feat: totp 2fa; httpcontext extension for jwtuser; asp.net data protection; prevent banned users from certain actions; account deletion requires 2fa if enabled; making users admins requires 2fa if enabled; httpcontext extension to get ip; enhance user store
refactor: organize dtos by domain; verification providers use verification context; move ip parsing into http context extensions chore: clean code
This commit is contained in:
@@ -0,0 +1,18 @@
|
||||
export function parseTotpEnabled(tokenValue: string | null) {
|
||||
if (!tokenValue) return false;
|
||||
try {
|
||||
const payload = JSON.parse(atob(tokenValue.split('.')[1]));
|
||||
const flag = payload?.TOTP_Enabled ?? payload?.totp_enabled ?? payload?.totpEnabled;
|
||||
if (typeof flag === 'string') return flag.toLowerCase() === 'true';
|
||||
return Boolean(flag);
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
export function needsAdminTotp(totpEnabled: boolean, currentRoles: number[], nextRoles: number[]) {
|
||||
if (!totpEnabled) return false;
|
||||
const nextHasAdmin = nextRoles.includes(255);
|
||||
const alreadyAdmin = currentRoles.includes(255);
|
||||
return nextHasAdmin && !alreadyAdmin;
|
||||
}
|
||||
Reference in New Issue
Block a user