Advertisement
Guest User

Untitled

a guest
Mar 14th, 2017
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.83 KB | None | 0 0
  1. GET / controllers.Application.index
  2. GET /login controllers.Application.login
  3. POST /login controllers.Application.auth
  4.  
  5. <body>
  6. <h1>Play! Login Sample - Login</h1>
  7. <p>Please provide your credentials.</p>
  8. <p><input type="email" name="email" placeholder="Email" id="email"></p>
  9. <p>
  10. <input type="password" name="password" id="password" placeholder="Password">
  11. </p>
  12. <p>
  13. <button type="submit" id="loginbutton" onclick="auth();return false">Login</button>
  14. </p>
  15. <script>
  16. function auth( ){
  17. var user = $("input[name=email]").val();
  18. var pass = $("input[name=password]").val();
  19. console.log(user+" "+pass)
  20. xhr = new XMLHttpRequest();
  21. var url = "/login";
  22. xhr.open("POST", url, true);
  23. xhr.setRequestHeader("Content-type", "text/json");
  24. var data = JSON.stringify({"name":user, "pass":pass});
  25. xhr.send(data);
  26. console.log(xhr.status)
  27. }
  28. </script>
  29. </body>
  30.  
  31. object Application extends Controller {
  32.  
  33. def index = Action {
  34. Ok(views.html.index("Your new application is ready."))
  35. }
  36. def login = Action{
  37. Ok(views.html.login("Some Message"))
  38. }
  39.  
  40. def auth =Action{
  41. implicit request =>
  42. request.body.asJson.map { json =>
  43. (json "name").asOpt[String].map { name =>
  44. if (name =="some_name "){
  45. Redirect(routes.Application.index())
  46. }
  47. else NoContent
  48. }.getOrElse {
  49. BadRequest("Missing parameter [name]")
  50. }
  51. }.getOrElse {
  52. BadRequest("Expecting Json data")
  53. }
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement