Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package controllers;
- import models.User;
- import play.data.Form;
- import play.mvc.*;
- import views.html.*;
- import java.util.List;
- import static play.data.Form.*;
- public class Application extends Controller {
- public static Result show()
- {
- return ok ();
- }
- public static Result index() {
- return ok("Welcome to Play");
- }
- public static Result login() {
- return ok (login.render(form(Login.class)));
- }
- public static class Login {
- public String email;
- public String getPassword() {
- return password;
- }
- public void setPassword(String password) {
- this.password = password;
- }
- public String getEmail() {
- return email;
- }
- public void setEmail(String email) {
- this.email = email;
- }
- public String password;
- }
- public static Result authenticate() {
- // new User("amir.afroozeh@gmail.com", "1234").save();
- // List<User> users= User.find.all();
- // System.out.println(1111111);
- // User bob = User.find("byEmail", "bob@gmail.com").first();
- Form<Login> loginForm = form(Login.class).bindFromRequest();
- Login data = loginForm.get();
- if (loginForm.hasErrors()) {
- return badRequest(login.render(loginForm));
- } else
- {
- boolean result = Application.check(data.email,data.password);
- if (result == true) {
- return ok("Correct");
- } else
- return ok("NotCorrect");
- }
- }
- public String validate() {
- // ApplicationContext ctx = AppContextUtils.appContext();
- // AuthenticationService authService = (AuthenticationService) ctx.getBean((Class) AuthenticationService.class);
- //
- // User user = authService.authenticate(email, password);
- //
- // if (user == null) {
- // return Messages.get("unsuccessful.authentication");
- // }
- //// else if (!user.validated) {
- //// return Messages.get("account.not.validated.check.mail");
- //// }
- return null;
- }
- public User authenticate(String email, String clearPassword) {
- // get the user with email only to keep the salt password
- // User user = userRepository.findByEmail(email);
- //
- // if (user != null && passwordMatches(clearPassword, user)) {
- // // get the hash password from the salt + clear password
- //
- // if (userIsAuthorizedOnChannel(email, cid)) {
- // logger.info("User authenticated: email:{} cid: {} ", email, cid);
- // return user;
- // }
- // }
- // logger.warn("User not authenticated: email:{} cid: {} ", email, cid);
- // return null;
- // }
- return null;
- }
- public static boolean check (String s, String password)
- {
- User user = User.find.where().eq("email", s);
- if(user==null) return false;
- else if(user.password==password) {return true;}
- else return false;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement