Skip to content
Snippets Groups Projects
Commit 485c0684 authored by Gabriel Copat's avatar Gabriel Copat
Browse files

Bugfixed

parent 1a795df1
No related branches found
No related tags found
1 merge request!36Resolve "As a user I want to be able to use the application on any device e.g. iPhone, iPad, Laptop"
......@@ -43,7 +43,7 @@ public class UserController {
// return mav;
// }
@PostMapping("/login/register")
@PostMapping("/register")
public ModelAndView registerUser(@Valid @ModelAttribute("user") NewUser user, BindingResult bindingResult, Model model) {
ModelAndView mav = new ModelAndView("users/login", model.asMap());
// TODO VALIDATE EMAIL INPUT
......@@ -51,19 +51,12 @@ public class UserController {
if (bindingResult.hasErrors()) {
ModelAndView modelAndView = new ModelAndView("users/login");
modelAndView.addObject("errors", bindingResult);
modelAndView.addObject("error", "");
return modelAndView;
}
if ( userRepository.doesUserExist(user.getEmail()) ) {
mav.addObject("errors", "Email already in use");
return mav;
}
try {
userRepository.addUser(user.name, user.email, user.password);
mav.addObject("error", "");
//TODO return user creation success
return mav;
return new ModelAndView("redirect:/login?register");
} catch (DataAccessException e) {
mav.addObject("error", "User exists");
}
......@@ -83,6 +76,7 @@ public class UserController {
}
/* USER MAPPING & FUNCTIONS */
@GetMapping("/profile/{username}")
public ModelAndView getUserPage(@PathVariable String username) {
......
spring.datasource.url=jdbc:mariadb://localhost:3306/towns
spring.datasource.url=jdbc:mariadb://localhost:3306/
spring.datasource.username=root
spring.datasource.password=comsc
......
......@@ -19,8 +19,9 @@
<div class="container" th:classappend="${status}" id="container">
<div class="form-container sign-up">
<h1 class="form-title">Create Account</h1>
<form th:object="${user}" action="#" th:action="@{/login/register}" th:method="POST" onsubmit="return registerFormValidation()">
<form th:object="${user}" action="#" th:action="@{/register}" th:method="POST" onsubmit="return registerFormValidation()">
<div th:if="${error.equals('User exists')}" class="alert alert-error">User already exist</div>
<div th:text="${errors}" class="alert alert-error"></div>
<label>
<input class="input" th:field="*{name}" id="register-username" type="text" placeholder="Name">
</label>
......@@ -38,6 +39,7 @@
<form name="f" th:action="@{/login}" th:method="POST">
<div th:if="${param.error}" class="alert alert-error">Invalid Username or Password</div>
<div th:if="${param.logout}" class="alert alert-success">Successfully Logged out</div>
<div th:if="${param.register}" class="alert alert-success">Account Created Successfully</div>
<label>
<input class="input" id="username" type="text" name="username" placeholder="Email">
</label>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment