Skip to content

Instantly share code, notes, and snippets.

@craigmartin
Created April 1, 2011 20:09
Show Gist options
  • Save craigmartin/898759 to your computer and use it in GitHub Desktop.
Save craigmartin/898759 to your computer and use it in GitHub Desktop.
I changed the unless to unless user.update_or_create (no cap, so its calling the instance not the User model right?)
require 'rubygems'
#require 'ruby-debug'; debugger;
gem 'rest-client', '=1.6.1'
%w(./config haml sinatra digest/md5 rack rack-flash json rest-client ./models).each { |lib| require lib}
set :sessions, true
set :show_exceptions, true
set :environment, :development
use Rack::Flash
get "/" do
if session[:userid].nil? then
@token = "http://#{env["HTTP_HOST"]}/after_login"
haml :login
else
# @user = User.get(session[:userid])
@all = @user.feed
haml :landing
end
end
get "/logout" do
session[:userid] = nil
redirect "/"
end
# called by RPX after the login completes
post "/after_login" do
profile = get_user_profile_with params[:token]
user = User.find(profile["identifier"])
if user.new?
photo = profile ["email"] ? "http://www.gravatar.com/avatar/#{Digest::MD5.hexdigest(profile["email"])}" : profile["photo"]
unless user.update_or_create({ :nickname => profile["identifier"].hash.to_s(36), :email => profile["email"], :photo_url => photo, :provider => profile["provider"]})
flash[:error] = user.errors.values.join(",")
redirect "/"
end
session[:userid] = user.id
redirect "/user/profile/change"
else
session[:userid] = user.id
redirect "/"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment