mirror of
https://github.com/st-tu-dresden-praktikum/swt23w23
synced 2024-07-19 21:04:36 +02:00
parent
60644a74b3
commit
56cf10af8c
|
@ -35,12 +35,18 @@ public class UserController {
|
|||
}
|
||||
|
||||
@PostMapping("/register")
|
||||
String register(@Valid RegistrationForm form, Errors result) {
|
||||
String register(@Valid RegistrationForm form, Errors result, Model model) {
|
||||
if (result.hasErrors()){
|
||||
return "register";
|
||||
}
|
||||
userManagement.createCustomer(form.getUsername(),form.getAddress(),form.getPassword());
|
||||
return "redirect:/login";
|
||||
if (userManagement.userNameExists(form.getUsername())) {
|
||||
model.addAttribute("userNameExists",true);
|
||||
return "register";
|
||||
} else {
|
||||
model.addAttribute("userNameExists",false);
|
||||
userManagement.createCustomer(form.getUsername(),form.getAddress(),form.getPassword());
|
||||
return "redirect:/login";
|
||||
}
|
||||
}
|
||||
|
||||
@GetMapping("/login")
|
||||
|
|
|
@ -51,4 +51,12 @@ public class UserManagement {
|
|||
public Optional<User> getUserByAccount(UserAccount userAccount) {
|
||||
return users.findAll().stream().filter(u -> u.getUserAccount().equals(userAccount)).findFirst();
|
||||
}
|
||||
|
||||
public boolean userNameExists(String username){
|
||||
return !users.findAll().stream()
|
||||
.filter(u -> u.getUsername().equals(username))
|
||||
.toList()
|
||||
.isEmpty();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -9,6 +9,7 @@
|
|||
<div class="mb-3">
|
||||
<label class="form-label" for="username">Nutzername</label>
|
||||
<input class="form-control" name="username" type="text" required>
|
||||
<p th:if="${userNameExists}">Nutzername vergeben</p>
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label class="form-label" for="password">Passwort</label>
|
||||
|
|
Loading…
Reference in a new issue