Skip to content

Commit

Permalink
#116 - redirect to /admin if the user is already logged in
Browse files Browse the repository at this point in the history
(cherry picked from commit d96e7e2)
  • Loading branch information
cbellone committed Apr 7, 2016
1 parent feb2957 commit d10573c
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/main/java/alfio/config/WebSecurityConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ protected void configure(HttpSecurity http) throws Exception {
.and()
.formLogin()
.loginPage("/authentication")
.loginProcessingUrl("/authentication")
.loginProcessingUrl("/authenticate")
.failureUrl("/authentication?failed");
}
}
Expand Down
13 changes: 10 additions & 3 deletions src/main/java/alfio/controller/LoginController.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,25 @@
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;

import java.security.Principal;

@Controller
public class LoginController {

private static final String REDIRECT_ADMIN = "redirect:/admin/";

@RequestMapping(value="/authentication", method = RequestMethod.GET)
public String getLoginPage(@RequestParam(value="failed", required = false) String failed, Model model) {
public String getLoginPage(@RequestParam(value="failed", required = false) String failed, Model model, Principal principal) {
if(principal != null) {
return REDIRECT_ADMIN;
}
model.addAttribute("failed", failed != null);
return "/login/login";
}

@RequestMapping(value="/authentication", method = RequestMethod.POST)
@RequestMapping(value="/authenticate", method = RequestMethod.POST)
public String doLogin() {
return "redirect:/admin/";
return REDIRECT_ADMIN;
}

}
2 changes: 1 addition & 1 deletion src/main/webapp/WEB-INF/templates/login/login.ms
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<div class="container">
<div class="row">
<div class="col-sm-10 col-sm-push-1 col-xs-12 col-md-6 col-md-push-3">
<form role="form" name="loginForm" action="{{request.contextPath}}/authentication" method="post">
<form role="form" name="loginForm" action="{{request.contextPath}}/authenticate" method="post">
<input name="_csrf" type="hidden" value="{{_csrf.token}}" />
<div class="page-header">
<h2>Authentication requested</h2>
Expand Down

0 comments on commit d10573c

Please sign in to comment.