Skip to content

Commit ca60f48

Browse files
committed
UserServiceを使ったログイン処理。
Signed-off-by: Takuya UESHIN <ueshin@happy-camper.st>
1 parent 420bdc2 commit ca60f48

5 files changed

Lines changed: 37 additions & 11 deletions

File tree

app/controllers.scala

Lines changed: 0 additions & 10 deletions
This file was deleted.

app/controllers/Application.scala

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package controllers
2+
3+
import _root_.play._
4+
import _root_.play.mvc._
5+
import _root_.play.modules.gae._
6+
7+
object Application extends Controller with Defaults {
8+
9+
def index = Template
10+
11+
def login = GAE.login("Application.index")
12+
13+
def logout = GAE.logout("Application.index")
14+
}

app/controllers/Defaults.scala

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package controllers
2+
3+
import _root_.play._
4+
import _root_.play.mvc._
5+
import _root_.play.modules.gae._
6+
7+
trait Defaults extends Controller {
8+
9+
@Before
10+
def check = {
11+
Option(GAE.getUser) match {
12+
case Some(user) => {
13+
renderArgs += "user" -> user
14+
}
15+
case None =>
16+
}
17+
}
18+
}

app/views/Application/index.html

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
#{extends 'main.html' /}
22
#{set title:'Home' /}
33

4-
#{welcome /}
4+
Welcome #{if user}${user.email}#{/if}#{else}Guest#{/else}!
5+
6+
#{if user}<a href="@{Application.logout}">Logout</a>#{/if}#{else}<a href="@{Application.login}">Login</a>#{/else}

conf/routes

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
# Home page
66
GET / Application.index
7+
GET /login Application.login
8+
GET /logout Application.logout
79

810
# Map static resources from the /app/public folder to the /public path
911
GET /public/ staticDir:public

0 commit comments

Comments
 (0)