package controllers;

import models.User;
import play.api.data.FormError;
import play.data.Form;
import play.mvc.*;
import play.data.FormFactory;

import views.html.*;

import javax.inject.Inject;

public class LoginController extends Controller {

  @Inject
  FormFactory formFactory;

  public Result login() {
    Form<User> loginForm = formFactory.form(User.class);
    return ok(login.render(loginForm, "login"));
  }

  public Result auth(){
    Form<User> loginForm = formFactory.form(User.class).bindFromRequest();
    if(loginForm.hasErrors()){
      return badRequest(login.render(loginForm, "login"));
    }
    session().clear();
    session("name", loginForm.get().name);
    session("login", "true");
    return redirect(routes.ArticleController.index());


  }
}

@@ -612,16 +612,167 @@
 ;%0A    %7D%0A
+    try %7B%0A      User result = User.authenticate(loginForm.get().getName(), loginForm.get().getPassword());%0A      if(!result.getName().isEmpty()) %7B%0A    
     sess
@@ -786,24 +786,28 @@
 lear();%0A    
+   
+ 
 session(%22nam
@@ -833,16 +833,20 @@
 .name);%0A
+    
     sess
@@ -867,16 +867,103 @@
 true%22);%0A
+      %7D%0A    %7D catch (java.lang.NullPointerException e)%7B%0A      session().clear();%0A    %7D%0A
     retu

Use DB user auth