Advertisement
Guest User

Untitled

a guest
Apr 3rd, 2017
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.13 KB | None | 0 0
  1. "Type Login is not a member of Object controller.Application".
  2.  
  3. Error:(24, 196) type Login is not a member of object controllers.Application
  4. class login extends BaseScalaTemplate[play.twirl.api.HtmlFormat.Appendable,Format[play.twirl.api.HtmlFormat.Appendable]](play.twirl.api.HtmlFormat) with play.twirl.api.Template1[Form[Application.Login],play.twirl.api.HtmlFormat.Appendable] {
  5. Error:(27, 43) type Login is not a member of object controllers.Application
  6. def apply/*1.2*/(form: Form[Application.Login]):play.twirl.api.HtmlFormat.Appendable = {
  7. Error:(71, 36) type Login is not a member of object controllers.Application
  8. def render(form:Form[Application.Login]): play.twirl.api.HtmlFormat.Appendable = apply(form)
  9. Error:(73, 28) type Login is not a member of object controllers.Application
  10. def f:((Form[Application.Login]) => play.twirl.api.HtmlFormat.Appendable) = (form) => apply(form)
  11.  
  12. package models;
  13.  
  14. import com.avaje.ebean.Model;
  15.  
  16. import javax.persistence.Entity;
  17. import javax.persistence.Id;
  18.  
  19. @Entity
  20. public class User extends Model {
  21.  
  22. @Id
  23. public String email;
  24. public String name;
  25. public String password;
  26.  
  27. public User(String email, String name, String password) {
  28. this.email = email;
  29. this.name = name;
  30. this.password = password;
  31. }
  32.  
  33. public Finder<String,User> find = new Finder<String,User>(
  34. String.class, User.class
  35. );
  36.  
  37. public User authenticate(String email, String password) {
  38. return find.where().eq("email", email)
  39. .eq("password", password).findUnique();
  40. }
  41. }
  42.  
  43. package controllers;
  44.  
  45. import models.User;
  46. import play.data.Form;
  47. import play.mvc.Controller;
  48. import play.mvc.Result;
  49. import views.html.index;
  50. import views.html.login;
  51.  
  52. public class Application extends Controller {
  53.  
  54. public Result index() {
  55. return ok(index.render("hello"));
  56. }
  57.  
  58. public Result login() {
  59. return ok(login.render(form(Login.class)));
  60. }
  61.  
  62. public Result authenticate() {
  63. Form<User> loginForm = Form.form(User.class).bindFromRequest();
  64. if (loginForm.hasErrors()) {
  65. return badRequest(login.render(loginForm));
  66. } else {
  67. session().clear();
  68. session("email", loginForm.get().email);
  69. return redirect(
  70. routes.Application.index()
  71. );
  72. }
  73. }
  74.  
  75. public class Login {
  76. public String email;
  77. public String password;
  78. public User user;
  79.  
  80. public String validate() {
  81. user.authenticate(email, password);
  82. if (user == null) {
  83. return "Invalid user or password";
  84. }
  85. return null;
  86. }
  87. }
  88. }
  89.  
  90. @(form: Form[Application.Login])
  91. <html>
  92. <head>
  93. <title>Zentasks</title>
  94. <link rel="shortcut icon" type="image/png" href="@routes.Assets.at("images/favicon.png")">
  95. <link rel="stylesheet" type="text/css" media="screen" href="@routes.Assets.at("stylesheets/login.css")">
  96. </head>
  97. <body>
  98. <header>
  99. <a href="@routes.Application.index" id="logo"><span>Zen</span>tasks</a>
  100. </header>
  101.  
  102. @helper.form(routes.Application.authenticate) {
  103. <h1>Sign in</h1>
  104. @if(form.hasGlobalErrors) {
  105. <p class="error">
  106. @form.globalError.message
  107. </p>
  108. }
  109.  
  110. <p>
  111. <input type="email" name="email" placeholder="Email" value="@form("email").value">
  112. </p>
  113. <p>
  114. <input type="password" name="password" placeholder="Password">
  115. </p>
  116. <p>
  117. <button type="submit">Login</button>
  118. </p>
  119. }
  120.  
  121. </body>
  122. </html>
  123.  
  124. # Routes
  125. # This file defines all application routes (Higher priority routes first)
  126. # ~~~~
  127.  
  128. # Home page
  129. GET / controllers.Application.index()
  130. GET /login controllers.Application.login()
  131. POST /login controllers.Application.authenticate()
  132.  
  133. # Map static resources from the /public folder to the /assets URL path
  134. GET /assets/*file controllers.Assets.at(path="/public", file)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement