Created
October 25, 2011 02:22
-
-
Save zuk/1311132 to your computer and use it in GitHub Desktop.
Logging in to Rollcall using Java in Play Framework
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // authenticate with rollcall | |
| String rollcallUrl = Play.configuration.getProperty("sail.rollcall.url"); | |
| WSRequest req = WS.url(rollcallUrl+"/login.json"); | |
| req.setParameter("session[login]", username); | |
| req.setParameter("session[password]", password); | |
| WS.HttpResponse res = req.post(); | |
| JsonElement json = res.getJson(); | |
| if (res.getStatus() == 201) { // session created successfully | |
| JsonObject session = json.getAsJsonObject().getAsJsonObject("session"); | |
| JsonObject account = session.getAsJsonObject("account"); | |
| String token = session.get("token").getAsString(); | |
| String encryptedPassword = account.get("encrypted_password").getAsString(); | |
| // now check if we already have this user in the local database | |
| } else { // some error during session creation | |
| flash.put("error", "Rollcall authentication failed: "+json.toString()); | |
| return false; | |
| } | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment