mirror of
https://github.com/MewoLab/AquaDX.git
synced 2026-02-07 23:07:38 +08:00
[+] Confirm email
This commit is contained in:
@@ -125,6 +125,23 @@ class UserRegistrar(
|
|||||||
return mapOf("token" to token)
|
return mapOf("token" to token)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@PostMapping("/confirm-email")
|
||||||
|
suspend fun confirmEmail(@RP token: Str): Any {
|
||||||
|
// Find the confirmation
|
||||||
|
val confirmation = async { confirmationRepo.findByToken(token) }
|
||||||
|
|
||||||
|
// Check if the token is valid
|
||||||
|
if (confirmation == null) 400 - "Invalid token"
|
||||||
|
|
||||||
|
// Check if the token is expired
|
||||||
|
if (confirmation.createdAt.plusSeconds(60 * 60 * 24).isBefore(Instant.now())) 400 - "Token expired"
|
||||||
|
|
||||||
|
// Confirm the email
|
||||||
|
async { userRepo.save(confirmation.aquaNetUser.apply { emailConfirmed = true }) }
|
||||||
|
|
||||||
|
return mapOf("success" to true)
|
||||||
|
}
|
||||||
|
|
||||||
@PostMapping("/me")
|
@PostMapping("/me")
|
||||||
suspend fun getUser(@RP token: Str) = jwt.auth(token)
|
suspend fun getUser(@RP token: Str) = jwt.auth(token)
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user