Skip to content

Instantly share code, notes, and snippets.

@conikeec
Forked from jeantil/controllers.scala
Created August 27, 2011 06:43
Show Gist options
  • Save conikeec/1175075 to your computer and use it in GitHub Desktop.
Save conikeec/1175075 to your computer and use it in GitHub Desktop.
Play Scala adventures : WTF edition
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