Skip to content

Instantly share code, notes, and snippets.

@tyama
Forked from uehaj/AppEngineTagLib.groovy
Created December 25, 2009 13:23
Show Gist options
  • Save tyama/263630 to your computer and use it in GitHub Desktop.
Save tyama/263630 to your computer and use it in GitHub Desktop.
import com.google.appengine.api.users.User;
import com.google.appengine.api.users.UserService;
import com.google.appengine.api.users.UserServiceFactory;
class AppEngineTagLib {
static namespace = "appengine"
def ifLoggedIn = { attrs, body ->
def userService = UserServiceFactory.getUserService()
if (userService.isUserLoggedIn()) {
out << body()
}
}
def ifNotLoggedIn = { attrs, body ->
def userService = UserServiceFactory.getUserService()
if (!userService.isUserLoggedIn()) {
out << body()
}
}
def ifAdminLoggedIn = { attrs, body ->
def userService = UserServiceFactory.getUserService()
if (userService.isUserLoggedIn() && userService.isUserAdmin()) {
out << body()
}
}
def ifAdminNotLoggedIn = { attrs, body ->
def userService = UserServiceFactory.getUserService()
if (userService.isUserLoggedIn() &&!userService.isUserAdmin()) {
out << body()
}
}
def loginUrl = { attrs, body ->
def userService = UserServiceFactory.getUserService()
out << userService.createLoginURL(request.getRequestURI())
}
def logoutUrl = { attrs, body ->
def userService = UserServiceFactory.getUserService()
out << userService.createLogoutURL(request.getRequestURI())
}
def userNickname = { attrs, body ->
def userService = UserServiceFactory.getUserService()
def user = userService.getCurrentUser()
if(user!=null){
out << user.getNickname()
}else{
out<<"Guest"
}
}
def userAuthDomain = { attrs, body ->
def userService = UserServiceFactory.getUserService()
def user = userService.getCurrentUser()
if(user!=null){
out << user.getAuthDomain()
}else{
out<<""
}
}
def userEmail = { attrs, body ->
def userService = UserServiceFactory.getUserService()
def user = userService.getCurrentUser()
if(user!=null){
out << user.getEmail()
}else{
out<<""
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment