Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- GET / controllers.Application.index
- GET /login controllers.Application.login
- POST /login controllers.Application.auth
- <body>
- <h1>Play! Login Sample - Login</h1>
- <p>Please provide your credentials.</p>
- <p><input type="email" name="email" placeholder="Email" id="email"></p>
- <p>
- <input type="password" name="password" id="password" placeholder="Password">
- </p>
- <p>
- <button type="submit" id="loginbutton" onclick="auth();return false">Login</button>
- </p>
- <script>
- function auth( ){
- var user = $("input[name=email]").val();
- var pass = $("input[name=password]").val();
- console.log(user+" "+pass)
- xhr = new XMLHttpRequest();
- var url = "/login";
- xhr.open("POST", url, true);
- xhr.setRequestHeader("Content-type", "text/json");
- var data = JSON.stringify({"name":user, "pass":pass});
- xhr.send(data);
- console.log(xhr.status)
- }
- </script>
- </body>
- object Application extends Controller {
- def index = Action {
- Ok(views.html.index("Your new application is ready."))
- }
- def login = Action{
- Ok(views.html.login("Some Message"))
- }
- def auth =Action{
- implicit request =>
- request.body.asJson.map { json =>
- (json "name").asOpt[String].map { name =>
- if (name =="some_name "){
- Redirect(routes.Application.index())
- }
- else NoContent
- }.getOrElse {
- BadRequest("Missing parameter [name]")
- }
- }.getOrElse {
- BadRequest("Expecting Json data")
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement