]> www.vanbest.org Git - lootjes-play/commitdiff
Finished authentication tutorial page
authorJP <jp@here>
Tue, 28 Feb 2012 12:50:49 +0000 (13:50 +0100)
committerJP <jp@here>
Tue, 28 Feb 2012 12:50:49 +0000 (13:50 +0100)
app/controllers/Partys.java
app/controllers/Security.java
app/controllers/Users.java
app/views/CRUD/layout.html [new file with mode: 0644]
app/views/admin.html
conf/messages
public/stylesheets/secure.css [new file with mode: 0644]

index 5e06fdd8237e954516094609bd5b1532a081ce3d..2ba4b8085dd238bce2465f87e85d09aa93a49972 100644 (file)
@@ -3,6 +3,7 @@ package controllers;
 import play.*;
 import play.mvc.*;
 
+@Check("admin")
 @With(Secure.class) 
 public class Partys extends CRUD {    
 }
index f3224f6091a3799880f9df45b3ad7fbbc0383016..cd39d044304b4297b34650b80e976d0903700e95 100644 (file)
@@ -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()).<User>first().isAdmin;
+        }
+        return false;
+    }
+
 }
index 907e997e570e2c03fff0edfd2b3e30db8e9a3f87..a0cdc46561035d2b13364e729e85863b04925dbb 100644 (file)
@@ -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 (file)
index 0000000..ca0e021
--- /dev/null
@@ -0,0 +1,24 @@
+#{extends 'admin.html' /}
+#{set 'moreStyles'}
+    <link rel="stylesheet" type="text/css" media="screen" 
+        href="@{'/public/stylesheets/crud.css'}" />
+#{/set}
+<div id="crud">
+    #{if flash.success}
+        <div class="crudFlash flashSuccess">
+                ${flash.success}
+        </div>
+    #{/if}
+    #{if flash.error || error}
+        <div class="crudFlash flashError">
+                ${error ?: flash.error}
+        </div>
+    #{/if}
+    <div id="crudContent">
+        #{doLayout /}
+    </div>
+</div>
index 0967ac8b0a1547e58bb1d0443563b0833b99dc2b..1cffbf8d7b3209ad7b407983baed8e40dda5229b 100644 (file)
         </div>
         
         <div id="main">
+
+            <ul id="adminMenu">
+                <li class="${request.controller == 'Admin' ? 'selected' : ''}">
+                    <a href="@{Admin.index()}">My posts</a>
+                </li>
+                #{secure.check 'admin'}
+                    <li class="${request.controller == 'Posts' ? 'selected' : ''}">
+                        <a href="@{Partys.list()}">Parties</a>
+                    </li>
+                    <li class="${request.controller == 'Users' ? 'selected' : ''}">
+                        <a href="@{Users.list()}">Users</a>
+                    </li>
+                #{/secure.check}
+            </ul>
             #{doLayout /} 
         </div>
         
index 0e07937bcb3dd1f1a51998d7ff7f28607ed4cc75..ed81311c1f2643fee93bc021e903c5688116f101 100644 (file)
@@ -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 (file)
index 0000000..cde55d7
--- /dev/null
@@ -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;
+}