6
import play.data.validation._
7
import play.db.jpa.QueryFunctions._
11
@With(Array(classOf[Secure]))
12
object Admin extends Actions with Defaults {
15
private def setConnectedUser{
16
if(Secure.Security.isConnected()) {
17
val user = find[User]("byEmail", Secure.Security.connected()).first
18
renderArgs += "user" -> user.fullname
23
val posts = find[Post]("author.email", Secure.Security.connected()).fetch
29
val post = findById[Post](id)
35
def save(id: Long, title: String, content: String, tags: String) {
39
val author = find[User]("byEmail", Secure.Security.connected()).first;
40
post = new Post(author, title, content)
43
post = findById[Post](id)
45
post.content = content
49
tags.split("""\s+""") foreach { tag: String =>
50
if(tag.trim().length > 0) {
51
post.tags add Tag.findOrCreateByName(tag)
55
validation.valid(post)
56
if(Validation.hasErrors()) {
68
object Security extends Secure.Security {
70
private def authentify(username: String, password: String) = {
71
User.connect(username, password) != null
74
private def check(profile: String) = {
76
case "admin" => find[User]("byEmail", Secure.Security.connected).first.isAdmin
81
private def onDisconnected = Application.index
83
private def onAuthenticated = Admin.index
89
@Check(Array("admin")) @With(Array(classOf[Secure])) object Comments extends CRUD
90
@Check(Array("admin")) @With(Array(classOf[Secure])) object Posts extends CRUD
91
@Check(Array("admin")) @With(Array(classOf[Secure])) object Tags extends CRUD
92
@Check(Array("admin")) @With(Array(classOf[Secure])) object Users extends CRUD