Created
April 1, 2011 21:14
-
-
Save craigmartin/898870 to your computer and use it in GitHub Desktop.
monsoc.rb - (app file) with @user.update_or_create changed to User.update_or_create
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
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 | |
%w(pages friends photos messages events groups comments user helpers).each {|feature| load "#{feature}.rb"} | |
error NoMethodError do | |
session[:userid] = nil | |
redirect "/" | |
end | |
before do | |
@user = User.get(session[:userid]) if session[:userid] | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment