mirror of
https://github.com/MewoLab/AquaDX.git
synced 2025-10-26 04:22:38 +00:00
[+] Login
This commit is contained in:
parent
77b2f90259
commit
55cfb7b358
@ -26,9 +26,10 @@ class UserRegistrar(
|
||||
*/
|
||||
@PostMapping("/register")
|
||||
suspend fun register(
|
||||
@RP username: Str, @RP email: Str, @RP password: Str,
|
||||
@RP turnstile: Str, request: HttpServletRequest
|
||||
) {
|
||||
@RP username: Str, @RP email: Str, @RP password: Str, @RP turnstile: Str,
|
||||
request: HttpServletRequest
|
||||
): Any {
|
||||
|
||||
val ip = geoIP.getIP(request)
|
||||
|
||||
// Check captcha
|
||||
@ -69,6 +70,27 @@ class UserRegistrar(
|
||||
|
||||
// TODO: Send confirmation email
|
||||
|
||||
200 - "User created"
|
||||
return mapOf("success" to true)
|
||||
}
|
||||
|
||||
@PostMapping("/login")
|
||||
suspend fun login(
|
||||
@RP email: Str, @RP password: Str, @RP turnstile: Str,
|
||||
request: HttpServletRequest
|
||||
): Any {
|
||||
|
||||
// Check captcha
|
||||
val ip = geoIP.getIP(request)
|
||||
if (!turnstileService.validate(turnstile, ip)) 400 - "Invalid captcha"
|
||||
|
||||
// Treat email as email / username
|
||||
val user = async { userRepo.findByEmailIgnoreCase(email) ?: userRepo.findByUsernameIgnoreCase(email) }
|
||||
?: (400 - "User not found")
|
||||
if (!hasher.matches(password, user.pwHash)) 400 - "Invalid password"
|
||||
|
||||
// Generate JWT token
|
||||
val token = jwt.gen(user)
|
||||
|
||||
return mapOf("token" to token)
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user