Last active
August 29, 2015 14:18
-
-
Save AdelinGhanaem/b80729a3b3075b1addba to your computer and use it in GitHub Desktop.
Spring MVC login
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Controller | |
@RequestMapping("/") | |
public class CorrectLogin { | |
@RequestMapping(method = RequestMethod.POST, value = "loginForm") | |
public String login(@ModelAttribute LoginCredentials loginCredentials) { | |
SessionDTO sessionDTO = usersService.login(loginCredentials); | |
if (sessionDTO == null) { | |
return "/login"; | |
} | |
return "redirect:index.html"; // this is how you send send a redirect response ! | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Controller | |
@RequestMapping("/") | |
public class Login { | |
@RequestMapping(method = RequestMethod.POST, value = "loginForm") | |
public String login(@ModelAttribute LoginCredentials loginCredentials) { | |
SessionDTO sessionDTO = usersService.login(loginCredentials); | |
if (sessionDTO == null) { | |
return "/login"; | |
} | |
return "index.html"; //forwards to index.html !!!! | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Created by adelin.ghanayem@gmail.com | |
*/ | |
@Configuration | |
@EnableWebMvc | |
@ComponentScan(basePackages = "com.tgallery.web") | |
public class WebConfiguration extends WebMvcConfigurerAdapter { | |
@Autowired | |
private SessionsService sessionsService; | |
@Override | |
public void addResourceHandlers(ResourceHandlerRegistry registry) { | |
registry.addResourceHandler("/resources/**").addResourceLocations("/resources/"); | |
//index.html is contained in /resources/ folder in root directory! | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment