Advertisement
Guest User

Untitled

a guest
Sep 7th, 2015
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.03 KB | None | 0 0
  1. package controllers;
  2.  
  3.  
  4. import models.User;
  5. import play.data.Form;
  6. import play.mvc.*;
  7. import views.html.*;
  8.  
  9. import java.util.List;
  10.  
  11. import static play.data.Form.*;
  12.  
  13.  
  14.  
  15. public class Application extends Controller {
  16.  
  17.  
  18. public static Result show()
  19. {
  20. return ok ();
  21. }
  22.  
  23. public static Result index() {
  24. return ok("Welcome to Play");
  25. }
  26.  
  27.  
  28. public static Result login() {
  29. return ok (login.render(form(Login.class)));
  30. }
  31.  
  32.  
  33.  
  34. public static class Login {
  35.  
  36. public String email;
  37.  
  38. public String getPassword() {
  39. return password;
  40. }
  41.  
  42. public void setPassword(String password) {
  43. this.password = password;
  44. }
  45.  
  46. public String getEmail() {
  47. return email;
  48. }
  49.  
  50. public void setEmail(String email) {
  51. this.email = email;
  52. }
  53.  
  54. public String password;
  55.  
  56.  
  57. }
  58.  
  59. public static Result authenticate() {
  60. // new User("amir.afroozeh@gmail.com", "1234").save();
  61. // List<User> users= User.find.all();
  62. // System.out.println(1111111);
  63. // User bob = User.find("byEmail", "bob@gmail.com").first();
  64. Form<Login> loginForm = form(Login.class).bindFromRequest();
  65. Login data = loginForm.get();
  66.  
  67. if (loginForm.hasErrors()) {
  68. return badRequest(login.render(loginForm));
  69. } else
  70. {
  71. boolean result = Application.check(data.email,data.password);
  72. if (result == true) {
  73. return ok("Correct");
  74. } else
  75. return ok("NotCorrect");
  76. }
  77.  
  78. }
  79.  
  80. public String validate() {
  81.  
  82. // ApplicationContext ctx = AppContextUtils.appContext();
  83. // AuthenticationService authService = (AuthenticationService) ctx.getBean((Class) AuthenticationService.class);
  84. //
  85. // User user = authService.authenticate(email, password);
  86. //
  87. // if (user == null) {
  88. // return Messages.get("unsuccessful.authentication");
  89. // }
  90. //// else if (!user.validated) {
  91. //// return Messages.get("account.not.validated.check.mail");
  92. //// }
  93. return null;
  94. }
  95.  
  96. public User authenticate(String email, String clearPassword) {
  97.  
  98. // get the user with email only to keep the salt password
  99. // User user = userRepository.findByEmail(email);
  100. //
  101. // if (user != null && passwordMatches(clearPassword, user)) {
  102. // // get the hash password from the salt + clear password
  103. //
  104. // if (userIsAuthorizedOnChannel(email, cid)) {
  105. // logger.info("User authenticated: email:{} cid: {} ", email, cid);
  106. // return user;
  107. // }
  108. // }
  109. // logger.warn("User not authenticated: email:{} cid: {} ", email, cid);
  110. // return null;
  111. // }
  112. return null;
  113. }
  114.  
  115. public static boolean check (String s, String password)
  116. {
  117. User user = User.find.where().eq("email", s);
  118. if(user==null) return false;
  119. else if(user.password==password) {return true;}
  120. else return false;
  121. }
  122. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement