0

I am testing Play framework 2.2.2. There is a helper for user authentication and seems to be simple to implement it. But if I need to hide some menus or other content from unregistered users - how can I do it?

I am thinking about if-blocks:

@if(...) {
  <h1>Content for registered users only</h1>
} else {
  <h1>Register to see this content</h1>
}

but what will be in the condition block? Have anybody an example?

biesior
  • 55,576
  • 10
  • 125
  • 182
gooamoko
  • 658
  • 12
  • 32

1 Answers1

1

Consider using Deadbolt-2 it's dedicated for this job, it allows to show (or hide) content in views depending on logging state but also by roles and permitions. Also incorporates access control for controller and/or actions.

Optionally you can also look at Play Authnticate it's full authorization/authentication stack - it also uses Deadbolt for mentioned reasons.

biesior
  • 55,576
  • 10
  • 125
  • 182
  • But how can I add `deadbolt-2` libraries into my project? In the https://github.com/schaloner/deadbolt-2#play-22 I have read about `Build.scala`, but I have `build.sbt` in my project root. – gooamoko May 01 '14 at 14:11
  • Just add what's required to `libraryDependencies` in build file – biesior May 01 '14 at 15:52
  • 1
    Thanks. I have read posts http://stackoverflow.com/questions/19928495/unresolved-dependencies-installing-deadbolt-on-play-framework-2-2-1 and http://stackoverflow.com/questions/19952470/questions-about-installing-deadbolt-on-play-2-2-1. So, I add required lines into `build.sbt` (that is replased Build.scala in new versions of Play) and create `/conf/play.plugins` file with line acording https://github.com/schaloner/deadbolt-2-guide/blob/master/04-deadbolt-java-hooks.markdown#the-deadbolt-plugin – gooamoko May 01 '14 at 16:10