Skip to content

Instantly share code, notes, and snippets.

@3to8-decoder
Created April 9, 2009 16:41
Show Gist options
  • Save 3to8-decoder/92566 to your computer and use it in GitHub Desktop.
Save 3to8-decoder/92566 to your computer and use it in GitHub Desktop.
#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
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