Skip to content

Instantly share code, notes, and snippets.

@AdelinGhanaem
Last active August 29, 2015 14:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AdelinGhanaem/b80729a3b3075b1addba to your computer and use it in GitHub Desktop.
Save AdelinGhanaem/b80729a3b3075b1addba to your computer and use it in GitHub Desktop.
Spring MVC login
@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 !
}
}
@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 !!!!
}
}
/**
* 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