[B][O] Use email as unique identifier instead of name

This commit is contained in:
Hykilpikonna
2021-01-09 21:34:35 -05:00
parent ed0ae5ae4b
commit c5ead62ec7
@@ -54,17 +54,17 @@ interface UserRepo: JpaRepository<User, Long>
@RequestMapping("/api/user") @RequestMapping("/api/user")
class UserApi(val repo: UserRepo) class UserApi(val repo: UserRepo)
{ {
val em = ExampleMatcher.matching().withIgnorePaths("id", "passHash", "passSalt").withMatcher("name", ignoreCase()) val em = ExampleMatcher.matching().withIgnorePaths("id", "passHash", "passSalt", "name").withMatcher("email", ignoreCase())
@GetMapping("/register") @GetMapping("/register")
fun register(@RequestParam name: String, @RequestParam pass: String, @RequestParam @Email email: String): Any fun register(@RequestParam name: String, @RequestParam pass: String, @RequestParam @Email email: String): Any
{ {
// Check username length // Check name length
if (name.length !in 3..32) return bad("Username length not in range 3 to 32") if (name.length !in 1..32) return bad("Name length not in range 1 to 32")
// Check if username exists // Check if email exists
val user = User(name, email, pass) val user = User(name, email, pass)
if (repo.exists(Example.of(user, em))) return bad("Username has already been used") if (repo.exists(Example.of(user, em))) return bad("Email is already registered")
// Check password strength // Check password strength
if (pass.length < 8) return bad("Password must be longer than 8 chars") if (pass.length < 8) return bad("Password must be longer than 8 chars")