Created
April 9, 2009 16:41
-
-
Save 3to8-decoder/92566 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#UserService for GoogleAppEngine JRuby Sinatra apps | |
#Based on Ola Bini's Beeu | |
require 'java' | |
module US | |
import com.google.appengine.api.users.UserServiceFactory | |
Service = UserServiceFactory.user_service | |
end | |
def current_user | |
if US::Service.user_logged_in? | |
return US::Service.current_user | |
else | |
return false | |
end | |
end | |
def logged_in? | |
US::Service.user_logged_in? | |
end | |
def admin_logged_in? | |
US::Service.user_logged_in? && US::Service.user_admin? | |
end | |
def login_url url=request.path_info | |
US::Service.create_login_url(url) | |
end | |
def logout_url url=request.path_info | |
US::Service.create_logout_url(url) | |
end | |
def require_login | |
redirect US::Service.create_login_url(request.path_info) unless US::Service.user_logged_in? | |
end | |
def require_admin | |
redirect US::Service.create_login_url(request.path_info) unless US::Service.user_logged_in? && US::Service.user_admin? | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
get '/secret' do | |
require_login | |
"hehe, you are logged in for this!" | |
end | |
get '/user_profile' do | |
require_login | |
@user = current_user | |
"Hello There "+ @user.getNickname + " with email " + @user.getEmail | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment