mirror of
https://github.com/MewoLab/AquaDX.git
synced 2026-02-08 08:27:26 +08:00
[+] Login
This commit is contained in:
@@ -26,9 +26,10 @@ class UserRegistrar(
|
|||||||
*/
|
*/
|
||||||
@PostMapping("/register")
|
@PostMapping("/register")
|
||||||
suspend fun register(
|
suspend fun register(
|
||||||
@RP username: Str, @RP email: Str, @RP password: Str,
|
@RP username: Str, @RP email: Str, @RP password: Str, @RP turnstile: Str,
|
||||||
@RP turnstile: Str, request: HttpServletRequest
|
request: HttpServletRequest
|
||||||
) {
|
): Any {
|
||||||
|
|
||||||
val ip = geoIP.getIP(request)
|
val ip = geoIP.getIP(request)
|
||||||
|
|
||||||
// Check captcha
|
// Check captcha
|
||||||
@@ -69,6 +70,27 @@ class UserRegistrar(
|
|||||||
|
|
||||||
// TODO: Send confirmation email
|
// 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)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user