Created
August 26, 2011 22:44
-
-
Save jeantil/1174611 to your computer and use it in GitHub Desktop.
Play Scala adventures : WTF edition
This file contains 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
package controllers | |
import play._ | |
import libs.OpenID | |
import play.mvc._ | |
object Application extends Controller { | |
import views.Application._ | |
@Before(unless=Array("login","authenticate")) | |
def checkAuthenticated() = { | |
session("user") match { | |
case Some(user) => Continue | |
//case _ => login() <= compile error Application.this.login of type play.templates.Html does not take parameters | |
case _ => login //<= this works | |
} | |
} | |
def index = { | |
html.index("Your Scala application is ready!", session("user").getOrElse("")) | |
} | |
def login = { | |
//html.login <= this doesn't work, returns BaseScalaTemplate(play.templates.HtmlFormat$@60e07ad7) | |
html.login() //<= this works | |
} | |
def authenticate = { | |
val user = params.get("user") | |
if (OpenID.isAuthenticationResponse ) { | |
val verifiedUser = OpenID.getVerifiedID | |
if (verifiedUser == null) { | |
flash += ("error", "Oops. Authentication has failed") | |
login | |
} | |
session.put("user", verifiedUser.id) | |
flash += ("success", "You have logged in successfully") | |
index | |
} else { | |
if(! OpenID.id(user).verify()){ | |
flash += ("error", "Oops. Authentication has failed") | |
login | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
interesting...