Skip to content

Instantly share code, notes, and snippets.

@uehaj
Created June 7, 2009 11:58
Show Gist options
  • Save uehaj/125301 to your computer and use it in GitHub Desktop.
Save uehaj/125301 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 {
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.isUserAdmin()) {
out << body()
}
}
def ifAdminNotLoggedIn = { attrs, body ->
def userService = UserServiceFactory.getUserService()
if (!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()
out << user.getNickname()
}
def userAuthDomain = { attrs, body ->
def userService = UserServiceFactory.getUserService()
def user = userService.getCurrentUser()
out << user.getAuthDomain()
}
def userEmail = { attrs, body ->
def userService = UserServiceFactory.getUserService()
def user = userService.getCurrentUser()
out << user.getEmail()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment