Advertisement
Guest User

Untitled

a guest
Jan 12th, 2016
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.21 KB | None | 0 0
  1. Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
  2.  
  3. if (!(authentication instanceof AnonymousAuthenticationToken)) {
  4. String currentUserName = authentication.getName(); return currentUserName;
  5. }
  6.  
  7. public class UserController extends Controller {
  8.  
  9. protected static String COOKIE_NAME = "user";
  10.  
  11. public static Result login() {
  12. //Считываем значения из формы:
  13. DynamicForm requestData = Form.form().bindFromRequest();
  14. String login = requestData.get("login");
  15. String password = requestData.get("password");
  16.  
  17. if(userExists(login, password)){
  18. session(COOKIE_NAME, login);
  19. Logger.info("User found");
  20. }else{
  21. Logger.info("User not found");
  22. }
  23.  
  24. return redirect(package.Application.index());
  25. }
  26.  
  27. public static Result logout() {
  28. session().remove(COOKIE_NAME);
  29. return redirect(package.Application.index());
  30. }
  31.  
  32. public static boolean isLoggedIn() {
  33. return session(COOKIE_NAME) != null;
  34. }
  35.  
  36. public static String getSession() {
  37. return session(COOKIE_NAME);
  38. }
  39. }
  40.  
  41. POST /login package.UserController.login()
  42. GET /logout package.UserController.logout()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement