From 429d7ae33bc4ffed649af9a4ad05ecb92f6c7377 Mon Sep 17 00:00:00 2001 From: JP Date: Tue, 28 Feb 2012 13:50:49 +0100 Subject: [PATCH] Finished authentication tutorial page --- app/controllers/Partys.java | 1 + app/controllers/Security.java | 17 ++++++- app/controllers/Users.java | 2 +- app/views/CRUD/layout.html | 24 +++++++++ app/views/admin.html | 14 ++++++ conf/messages | 4 ++ public/stylesheets/secure.css | 94 +++++++++++++++++++++++++++++++++++ 7 files changed, 154 insertions(+), 2 deletions(-) create mode 100644 app/views/CRUD/layout.html create mode 100644 public/stylesheets/secure.css diff --git a/app/controllers/Partys.java b/app/controllers/Partys.java index 5e06fdd..2ba4b80 100644 --- a/app/controllers/Partys.java +++ b/app/controllers/Partys.java @@ -3,6 +3,7 @@ package controllers; import play.*; import play.mvc.*; +@Check("admin") @With(Secure.class) public class Partys extends CRUD { } diff --git a/app/controllers/Security.java b/app/controllers/Security.java index f3224f6..cd39d04 100644 --- a/app/controllers/Security.java +++ b/app/controllers/Security.java @@ -7,5 +7,20 @@ public class Security extends Secure.Security { static boolean authenticate(String username, String password) { return User.connect(username, password) != null; } - + + static void onDisconnected() { + Application.index(); + } + + static void onAuthenticated() { + Admin.index(); + } + + static boolean check(String profile) { + if("admin".equals(profile)) { + return User.find("byEmail", connected()).first().isAdmin; + } + return false; + } + } diff --git a/app/controllers/Users.java b/app/controllers/Users.java index 907e997..a0cdc46 100644 --- a/app/controllers/Users.java +++ b/app/controllers/Users.java @@ -3,7 +3,7 @@ package controllers; import play.*; import play.mvc.*; - +@Check("admin") @With(Secure.class) public class Users extends CRUD { } diff --git a/app/views/CRUD/layout.html b/app/views/CRUD/layout.html new file mode 100644 index 0000000..ca0e021 --- /dev/null +++ b/app/views/CRUD/layout.html @@ -0,0 +1,24 @@ +#{extends 'admin.html' /} +#{set 'moreStyles'} + +#{/set} + +
+ + #{if flash.success} +
+ ${flash.success} +
+ #{/if} + #{if flash.error || error} +
+ ${error ?: flash.error} +
+ #{/if} + +
+ #{doLayout /} +
+ +
diff --git a/app/views/admin.html b/app/views/admin.html index 0967ac8..1cffbf8 100644 --- a/app/views/admin.html +++ b/app/views/admin.html @@ -24,6 +24,20 @@
+ + #{doLayout /}
diff --git a/conf/messages b/conf/messages index 0e07937..ed81311 100644 --- a/conf/messages +++ b/conf/messages @@ -2,3 +2,7 @@ # For example, for French create a messages.fr file # Partys=Parties + +secure.username=Your email: +secure.password=Your password: +secure.signin=Log in now diff --git a/public/stylesheets/secure.css b/public/stylesheets/secure.css new file mode 100644 index 0000000..cde55d7 --- /dev/null +++ b/public/stylesheets/secure.css @@ -0,0 +1,94 @@ +@import url(main.css); + +html, body { + background: #F0F0F0; + font-family: 'Lucida grande', verdana, sans-serif; +} + +#login { + width: 500px; + margin: 50px auto; + text-align: center; +} + +#login h1 { + font-weight: bold; + color: #111; +} + +#login form { + border: 10px solid #ccc; + background: #fff; + padding: 10px; + text-align: left; +} + +#login form p { + margin: 3px; +} + +#username-field label, #password-field label { + display: block; + width: 150px; + float: left; + text-align: right; + margin-right: 5px; + color: #333; + font-size: 15px; +} + +#username-field input { + width: 200px; + font-size: 13px; +} + +#password-field input { + width: 150px; + font-size: 13px; +} + +#remember-field input { + float: left; + margin-left: 155px; +} + +#remember-field label { + float: left; + padding-left: 3px; +} + +#username-field { + margin-top: 10px !important; +} + +#password-field { + margin-top: 10px !important; +} + +#remember-field { + margin-top: 10px !important; + font-size: 12px; + color: #666; + display: block; +} + +#signin-field input { + margin-left: 155px; + margin-top: 10px; +} + +#login .error, #login .success { + color: #fff; + font-size: 12px; + text-align: center; + margin-bottom: 10px; + padding: 5px; +} + +#login .error { + background: #c00 !important; +} + +#login .success { + background: #008800 !important; +} -- 2.39.5