Commit 785d6f6d authored by s7_spruge_k's avatar s7_spruge_k
Browse files

Fixed login issue, removed welcome screen

parent 71d71d65
......@@ -25,8 +25,20 @@ public class UserController {
@GetMapping("/registration")
public String registration(Model model) {
model.addAttribute("userForm", new User());
Object principal = SecurityContextHolder.getContext().getAuthentication().getPrincipal();
String username = "";
if (principal instanceof UserDetails) {
username = ((UserDetails)principal).getUsername();
} else {
username = principal.toString();
}
if(username != "anonymousUser")
return "redirect:/calendar";
model.addAttribute("userForm", new User());
return "registration";
}
......@@ -41,11 +53,24 @@ public class UserController {
userService.save(userForm);
securityService.autoLogin(userForm.getUsername(), userForm.getPasswordConfirm());
return "redirect:/welcome";
return "redirect:/calendar";
}
@GetMapping("/login")
public String login(Model model, String error, String logout) {
Object principal = SecurityContextHolder.getContext().getAuthentication().getPrincipal();
String username = "";
if (principal instanceof UserDetails) {
username = ((UserDetails)principal).getUsername();
} else {
username = principal.toString();
}
if(username != "anonymousUser")
return "redirect:/calendar";
if (error != null)
model.addAttribute("error", "Your username and password is invalid.");
......@@ -55,18 +80,4 @@ public class UserController {
return "login";
}///login POST controller is provided by Spring Security
@GetMapping({"/", "/welcome"})
public String welcome(Model model) {
Object principal = SecurityContextHolder.getContext().getAuthentication().getPrincipal();
if (principal instanceof UserDetails) {
String username = ((UserDetails)principal).getUsername();
System.out.println(username);
} else {
String username = principal.toString();
System.out.println(username);
}
return "welcome";
}
}
\ No newline at end of file
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Create an account</title>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
</head>
<body>
<div class="container">
<form id="logoutForm" action="#" method="POST" th:action="@{/logout}">
<input type="hidden" name="${_csrf.parameterName}" value="${_csrf.token}"/>
</form>
<h2> Welcome, <span th:text="${#request.userPrincipal.name}"></span> | <a onclick="document.forms['logoutForm'].submit()">Logout</a></h2>
<p >
</div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
<script src="@{/resources/js/bootstrap.min.js}"></script>
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js" integrity="sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js" integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM" crossorigin="anonymous"></script>
</body>
</html>
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment