diff --git a/lib/jam_ruby.rb b/lib/jam_ruby.rb index c64f8a058..ffc6e2062 100644 --- a/lib/jam_ruby.rb +++ b/lib/jam_ruby.rb @@ -22,6 +22,7 @@ require "jam_ruby/tire_tasks" require "jam_ruby/message_factory" require "jam_ruby/models/genre" require "jam_ruby/models/user" +require "jam_ruby/models/user_authorization" require "jam_ruby/models/band" require "jam_ruby/models/connection" require "jam_ruby/models/friendship" diff --git a/lib/jam_ruby/models/user.rb b/lib/jam_ruby/models/user.rb index 263405615..fa50040d5 100644 --- a/lib/jam_ruby/models/user.rb +++ b/lib/jam_ruby/models/user.rb @@ -7,6 +7,9 @@ module JamRuby self.primary_key = 'id' + # authorizations (for facebook, etc -- omniauth) + has_many :user_authorizations, :class_name => "JamRuby::UserAuthorization" + # account belongs_to :account, :class_name => "JamRuby::Account" @@ -234,8 +237,18 @@ module JamRuby user.first_name = first_name user.last_name = last_name user.email = email - user.password = password - user.password_confirmation = password_confirmation + + #FIXME: Setting random password for social network logins. This + # is because we have validations all over the place on this. + # The right thing would be to have this null + if password.nil? + user.password = "blahblahblah" + user.password_confirmation = "blahblahblah" + else + user.password = password + user.password_confirmation = password_confirmation + end + user.admin = false user.email_confirmed = false user.city = city @@ -260,9 +273,13 @@ module JamRuby if user.errors.any? raise ActiveRecord::Rollback else + # FIXME: + # It's not standard to require a confirmation when a user signs up with Facebook. + # We should stop asking for it. + # # any errors here should also rollback the transaction; that's OK. If emails aren't going to be delivered, # it's already a really bad situation; make user signup again - UserMailer.welcome_message(user, signup_confirm_url + "/" + user.signup_token).deliver + UserMailer.welcome_message(user, signup_confirm_url.nil? ? nil : (signup_confirm_url + "/" + user.signup_token) ).deliver end end diff --git a/lib/jam_ruby/models/user_authorization.rb b/lib/jam_ruby/models/user_authorization.rb new file mode 100644 index 000000000..5f7c97e25 --- /dev/null +++ b/lib/jam_ruby/models/user_authorization.rb @@ -0,0 +1,16 @@ +module JamRuby + class UserAuthorization < ActiveRecord::Base + + attr_accessible :provider, :uid, :token, :token_expiration + + self.table_name = "user_authorizations" + + self.primary_key = 'id' + + belongs_to :user, :class_name => "JamRuby::User", :foreign_key => "user_id" + validates :provider, :uid, :presence => true + + # token and token_expiration can be missing + + end +end