Skip to content

Commit

Permalink
UserServiceを使ったログイン処理。
Browse files Browse the repository at this point in the history
Signed-off-by: Takuya UESHIN <ueshin@happy-camper.st>
  • Loading branch information
ueshin committed Dec 6, 2010
1 parent 420bdc2 commit ca60f48
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 11 deletions.
10 changes: 0 additions & 10 deletions app/controllers.scala

This file was deleted.

14 changes: 14 additions & 0 deletions app/controllers/Application.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package controllers

import _root_.play._
import _root_.play.mvc._
import _root_.play.modules.gae._

object Application extends Controller with Defaults {

def index = Template

def login = GAE.login("Application.index")

def logout = GAE.logout("Application.index")
}
18 changes: 18 additions & 0 deletions app/controllers/Defaults.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package controllers

import _root_.play._
import _root_.play.mvc._
import _root_.play.modules.gae._

trait Defaults extends Controller {

@Before
def check = {
Option(GAE.getUser) match {
case Some(user) => {
renderArgs += "user" -> user
}
case None =>
}
}
}
4 changes: 3 additions & 1 deletion app/views/Application/index.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
#{extends 'main.html' /}
#{set title:'Home' /}

#{welcome /}
Welcome #{if user}${user.email}#{/if}#{else}Guest#{/else}!

#{if user}<a href="@{Application.logout}">Logout</a>#{/if}#{else}<a href="@{Application.login}">Login</a>#{/else}
2 changes: 2 additions & 0 deletions conf/routes
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

# Home page
GET / Application.index
GET /login Application.login
GET /logout Application.logout

# Map static resources from the /app/public folder to the /public path
GET /public/ staticDir:public
Expand Down

0 comments on commit ca60f48

Please sign in to comment.