Basic disabling of TFA
All checks were successful
Deploy API / deploy (ubuntu-latest, 2.44.0) (push) Successful in 55s

This commit is contained in:
Braydon 2024-09-19 22:00:47 -04:00
parent 57d10bd9c1
commit b95c92707b
3 changed files with 31 additions and 0 deletions

@ -97,6 +97,17 @@ public final class UserController {
return ResponseEntity.ok(userService.enableTwoFactor(input));
}
/**
* A POST endpoint to disable TFA for a useer.
*
* @return the disabled response
*/
@PostMapping("/disable-tfa") @ResponseBody @NonNull
public ResponseEntity<Map<String, Object>> disableTwoFactor() {
userService.disableTwoFactor();
return ResponseEntity.ok(Map.of("success", true));
}
/**
* A POST endpoint to logout the user.
*

@ -78,6 +78,15 @@ public final class User {
flags |= flag.bitwise();
}
/**
* Remove a flag from this user.
*
* @param flag the flag to remove
*/
public void removeFlag(@NonNull UserFlag flag) {
flags &= ~flag.bitwise();
}
/**
* Check if this user has a given flag.
*

@ -222,6 +222,17 @@ public final class UserService {
return originalBackupCodes;
}
/**
* Disable two-factor auth for the
* currently authenticated user.
*/
public void disableTwoFactor() {
User user = authService.getAuthenticatedUser();
user.setTfa(null);
user.removeFlag(UserFlag.TFA_ENABLED);
userRepository.save(user);
}
/**
* Logout the user.
*/