diff --git a/Gemfile b/Gemfile index 23f73e8bd..c09c6750c 100644 --- a/Gemfile +++ b/Gemfile @@ -25,6 +25,10 @@ gem 'eventmachine' gem 'amqp' gem 'logging-rails', :require => 'logging/rails' gem 'tire' +gem 'rb-readline' +gem 'omniauth' +gem 'omniauth-facebook' +gem 'fb_graph' gem 'sendgrid' gem 'recaptcha' diff --git a/app/controllers/api_users_controller.rb b/app/controllers/api_users_controller.rb index 9a5d40e63..521a9038f 100644 --- a/app/controllers/api_users_controller.rb +++ b/app/controllers/api_users_controller.rb @@ -22,7 +22,8 @@ class ApiUsersController < ApiController # if someone wants to use it, please add in captcha or some other bot-protector def create # sends email to email account for confirmation - @user = UserManager.new.signup(params[:name], + @user = UserManager.new.signup(params[:first_name], + params[:last_name], params[:email], params[:password], params[:password_confirmation], diff --git a/app/controllers/sessions_controller.rb b/app/controllers/sessions_controller.rb index 4da64de94..e5e5f6b6f 100644 --- a/app/controllers/sessions_controller.rb +++ b/app/controllers/sessions_controller.rb @@ -4,6 +4,7 @@ class SessionsController < ApplicationController def new end + def create user = User.authenticate(params[:session][:email], params[:session][:password]) @@ -11,13 +12,62 @@ class SessionsController < ApplicationController flash.now[:error] = 'Invalid email/password combination' render 'new' else - sign_in user - redirect_back_or music_sessions_url + complete_sign_in user end end +# OAuth docs +# http://net.tutsplus.com/tutorials/ruby/how-to-use-omniauth-to-authenticate-your-users/ + def create_oauth + auth_hash = request.env['omniauth.auth'] + authorization = UserAuthorization.find_by_provider_and_uid(auth_hash["provider"], auth_hash["uid"]) + if authorization + # Sign in for a user who has already registered. + complete_sign_in authorization.user + else + # Sign up for a completely new user. + # First/last name: auth_hash["info"]["first_name"] and auth_hash["info"]["last_name"] + # token: auth_hash["credentials"]["token"] -- "expires_at" + # + # For debugging - to see what all is there: + # render :text => auth_hash.to_yaml + #FbGraph.debug! + #app = FbGraph::Application.new '468555793186398', :secret => '546a5b253972f3e2e8b36d9a3dd5a06e' + token = auth_hash[:credentials][:token] + + # FIXME: + # This should probably be in a transaction somehow, meaning the user + # create and the authorization create. Concern is UserManager.new.signup sends + # an email and whatnot. + user = UserManager.new.signup(auth_hash[:info][:first_name], + auth_hash[:info][:last_name], + auth_hash[:info][:email], + nil, + nil, + auth_hash[:info][:location], + nil, # state + nil, # @country + nil, + nil) + auth = user.user_authorizations.build :provider => auth_hash[:provider], :uid => auth_hash[:uid], + :token => auth_hash[:credentials][:token], :token_expiration => Time.at(auth_hash[:credentials][:expires_at]) + user.save + auth.save + complete_sign_in user + end + end + + def complete_sign_in(user) + sign_in user + redirect_back_or music_sessions_url + end + def destroy sign_out redirect_to root_url end -end \ No newline at end of file + + def failure + + end +end diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 4666aee45..40ee063fb 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -18,8 +18,6 @@ class UsersController < ApplicationController end def create - - @user = User.new # check recaptcha; if any errors seen, contribute it to the model diff --git a/app/helpers/users_helper.rb b/app/helpers/users_helper.rb index cf892e07f..b3edd0a32 100644 --- a/app/helpers/users_helper.rb +++ b/app/helpers/users_helper.rb @@ -7,6 +7,6 @@ module UsersHelper hclass = options[:hclass] gravatar = gravatar_url = "https://secure.gravatar.com/avatar/#{gravatar_id}?s=#{size}" - image_tag(gravatar_url, alt: user.name, class: "#{hclass}") + image_tag(gravatar_url, alt: "#{user.first_name} #{user.last_name}", class: "#{hclass}") end end diff --git a/app/models/.gitkeep b/app/models/.gitkeep deleted file mode 100644 index e69de29bb..000000000 diff --git a/app/views/api_bands/follower_index.rabl b/app/views/api_bands/follower_index.rabl index fb957fa93..c58c0c9ab 100644 --- a/app/views/api_bands/follower_index.rabl +++ b/app/views/api_bands/follower_index.rabl @@ -10,10 +10,6 @@ node :last_name do |follower| follower.user.last_name end -node :name do |follower| - follower.user.name -end - node :city do |follower| follower.user.city end diff --git a/app/views/api_bands/show.rabl b/app/views/api_bands/show.rabl index 6b7864cbf..1091dfd88 100644 --- a/app/views/api_bands/show.rabl +++ b/app/views/api_bands/show.rabl @@ -4,7 +4,7 @@ attributes :id, :name, :city, :state, :country, :website, :biography, :photo_url unless @band.users.nil? || @band.users.size == 0 child :users => :musicians do - attributes :id, :first_name, :last_name, :name, :photo_url + attributes :id, :first_name, :last_name, :photo_url # TODO: figure out how to omit empty arrays node :instruments do |user| diff --git a/app/views/api_users/follower_index.rabl b/app/views/api_users/follower_index.rabl index 7b7b7b985..0d82e3b56 100644 --- a/app/views/api_users/follower_index.rabl +++ b/app/views/api_users/follower_index.rabl @@ -10,10 +10,6 @@ node :last_name do |follower| follower.user.last_name end -node :name do |follower| - follower.user.name -end - node :city do |follower| follower.user.city end diff --git a/app/views/api_users/following_index.rabl b/app/views/api_users/following_index.rabl index 60a776fac..12afb07f4 100644 --- a/app/views/api_users/following_index.rabl +++ b/app/views/api_users/following_index.rabl @@ -10,10 +10,6 @@ node :last_name do |following| following.user.last_name end -node :name do |follower| - follower.user.name -end - node :city do |following| following.user.city end diff --git a/app/views/api_users/friend_index.rabl b/app/views/api_users/friend_index.rabl index 47bbd619b..9a2f27e74 100644 --- a/app/views/api_users/friend_index.rabl +++ b/app/views/api_users/friend_index.rabl @@ -1,3 +1,3 @@ object @user.friends -attributes :id, :first_name, :last_name, :name, :city, :state, :country, :email, :online \ No newline at end of file +attributes :id, :first_name, :last_name, :city, :state, :country, :email, :online \ No newline at end of file diff --git a/app/views/api_users/index.rabl b/app/views/api_users/index.rabl index 8f9bbf9a7..3064a1366 100644 --- a/app/views/api_users/index.rabl +++ b/app/views/api_users/index.rabl @@ -1,4 +1,4 @@ collection @users # do not retrieve all child collections when showing a list of users -attributes :id, :first_name, :last_name, :name, :city, :state, :country, :email, :online, :musician, :photo_url \ No newline at end of file +attributes :id, :first_name, :last_name, :city, :state, :country, :email, :online, :musician, :photo_url \ No newline at end of file diff --git a/app/views/api_users/show.rabl b/app/views/api_users/show.rabl index 15a6a4360..5f076c2df 100644 --- a/app/views/api_users/show.rabl +++ b/app/views/api_users/show.rabl @@ -1,10 +1,10 @@ object @user -attributes :id, :first_name, :last_name, :name, :city, :state, :country, :online, :photo_url, :gender, :birth_date, :internet_service_provider, :friend_count, :follower_count, :following_count +attributes :id, :first_name, :last_name, :city, :state, :country, :online, :photo_url, :gender, :birth_date, :internet_service_provider, :friend_count, :follower_count, :following_count unless @user.friends.nil? || @user.friends.size == 0 child :friends => :friends do - attributes :id, :first_name, :last_name, :name, :online + attributes :id, :first_name, :last_name, :online end end diff --git a/app/views/clients/index.html.erb b/app/views/clients/index.html.erb index debe69e50..b52d70c06 100644 --- a/app/views/clients/index.html.erb +++ b/app/views/clients/index.html.erb @@ -21,7 +21,7 @@
New user? <%= link_to "Sign up now!", signup_path %>