mirror of
https://github.com/mofeng-git/One-KVM.git
synced 2026-10-28 00:10:50 +08:00
refactor: 优化数据库初始化与 WOL 存储
This commit is contained in:
@@ -227,15 +227,14 @@ impl TwoFactorService {
|
||||
return Err(AppError::AuthError("Invalid TOTP code".to_string()));
|
||||
}
|
||||
|
||||
let mut transaction = self.pool.begin().await?;
|
||||
let result =
|
||||
sqlx::query("INSERT INTO user_totp_credentials (user_id, secret) VALUES (?1, ?2)")
|
||||
.bind(user_id)
|
||||
.bind(secret.to_string())
|
||||
.execute(&mut *transaction)
|
||||
.execute(&self.pool)
|
||||
.await;
|
||||
match result {
|
||||
Ok(_) => transaction.commit().await?,
|
||||
Ok(_) => {}
|
||||
Err(sqlx::Error::Database(error)) if error.is_unique_violation() => {
|
||||
return Err(AppError::Conflict("TOTP is already enabled".to_string()));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user