first commit

This commit is contained in:
Rutra committed 2026-10-12 14:25:22 +02:00
commit 3c0479faf0
169 files changed
+27617

No files matched your search

+40
View File
@@ -0,0 +1,40 @@
import { BaseCommand, args } from '@adonisjs/core/ace'
import type { CommandOptions } from '@adonisjs/core/types/ace'
/**
* New double authentication secret (lost phone, new app…).
*/
export default class UserReset2fa extends BaseCommand {
static commandName = 'user:reset-2fa'
static description = 'Réinitialiser la double authentification d’un compte'
static options: CommandOptions = {
startApp: true,
}
@args.string({ description: 'Identifiant du compte' })
declare username: string
async run() {
const { default: User } = await import('#models/user')
const { enrollTotp } = await import('#services/totp_enrollment')
const user = await User.findBy('username', this.username)
if (!user) {
this.logger.error(`Compte « ${this.username} » introuvable.`)
this.exitCode = 1
return
}
const totpSecret = await enrollTotp(this, user.username)
if (!totpSecret) {
this.exitCode = 1
return
}
user.totpSecret = totpSecret
user.totpLastStep = null
await user.save()
this.logger.success('Double authentification réinitialisée.')
}
}