mirror of https://github.com/hykilpikonna/AquaDX
[F] Fix: Email and username should ignore case
parent
2815d76b1d
commit
32084eb1e7
|
@ -24,7 +24,7 @@ class UserRegistrar(
|
||||||
*/
|
*/
|
||||||
@PostMapping("/register")
|
@PostMapping("/register")
|
||||||
suspend fun register(@RP username: Str, @RP email: Str, @RP password: Str,
|
suspend fun register(@RP username: Str, @RP email: Str, @RP password: Str,
|
||||||
@RP turnstile: Str?, request: HttpServletRequest) {
|
@RP turnstile: Str, request: HttpServletRequest) {
|
||||||
val ip = geoIP.getIP(request)
|
val ip = geoIP.getIP(request)
|
||||||
|
|
||||||
// Check captcha
|
// Check captcha
|
||||||
|
@ -34,7 +34,8 @@ class UserRegistrar(
|
||||||
if (!email.isValidEmail()) 400 > "Invalid email"
|
if (!email.isValidEmail()) 400 > "Invalid email"
|
||||||
|
|
||||||
// Check if user with the same email exists
|
// Check if user with the same email exists
|
||||||
if (async { userRepo.existsByEmail(email) }) 400 > "User with email `$email` already exists"
|
if (async { userRepo.findByEmailIgnoreCase(email) != null })
|
||||||
|
400 > "User with email `$email` already exists"
|
||||||
|
|
||||||
// Check if username is valid
|
// Check if username is valid
|
||||||
if (username.length < 2) 400 > "Username must be at least 2 letters"
|
if (username.length < 2) 400 > "Username must be at least 2 letters"
|
||||||
|
@ -48,7 +49,8 @@ class UserRegistrar(
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if user with the same username exists
|
// Check if user with the same username exists
|
||||||
if (async { userRepo.existsByUsername(username) }) 400 > "User with username `$username` already exists"
|
if (async { userRepo.findByUsernameIgnoreCase(username) != null })
|
||||||
|
400 > "User with username `$username` already exists"
|
||||||
|
|
||||||
// Validate password
|
// Validate password
|
||||||
if (password.length < 8) 400 > "Password must be at least 8 characters"
|
if (password.length < 8) 400 > "Password must be at least 8 characters"
|
||||||
|
|
|
@ -10,7 +10,7 @@ import java.io.Serializable
|
||||||
@Table(name = "aqua_net_user")
|
@Table(name = "aqua_net_user")
|
||||||
class AquaNetUser(
|
class AquaNetUser(
|
||||||
@Id @GeneratedValue(strategy = GenerationType.IDENTITY)
|
@Id @GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||||
var auId: Int = 0,
|
var auId: Long = 0,
|
||||||
|
|
||||||
@Column(nullable = false, unique = true, length = 32)
|
@Column(nullable = false, unique = true, length = 32)
|
||||||
var username: String = "",
|
var username: String = "",
|
||||||
|
@ -43,7 +43,8 @@ class AquaNetUser(
|
||||||
) : Serializable
|
) : Serializable
|
||||||
|
|
||||||
@Repository("AquaNetUserRepository")
|
@Repository("AquaNetUserRepository")
|
||||||
interface AquaNetUserRepo : JpaRepository<AquaNetUser, Int> {
|
interface AquaNetUserRepo : JpaRepository<AquaNetUser, Long> {
|
||||||
fun existsByEmail(email: String): Boolean
|
fun findByAuId(auId: Long): AquaNetUser?
|
||||||
fun existsByUsername(username: String): Boolean
|
fun findByEmailIgnoreCase(email: String): AquaNetUser?
|
||||||
|
fun findByUsernameIgnoreCase(username: String): AquaNetUser?
|
||||||
}
|
}
|
Loading…
Reference in New Issue