* VRFS-378: allow user to be logged in right after signup, also supporting user signing up as a fan
This commit is contained in:
parent
80b23f7efe
commit
bd0b42533c
|
|
@ -116,17 +116,21 @@ module JamRuby
|
|||
validates :update_email, presence: true, format: {with: VALID_EMAIL_REGEX},
|
||||
uniqueness: {case_sensitive: false}, :if => :updating_email
|
||||
|
||||
|
||||
validates_length_of :password, minimum: 6, maximum: 100, :if => :should_validate_password?
|
||||
validates_presence_of :password_confirmation, :if => :should_validate_password?
|
||||
validates_confirmation_of :password, :if => :should_validate_password?
|
||||
|
||||
validates :terms_of_service, :acceptance => {:accept => true, :on => :create, :allow_nil => false }
|
||||
validates :subscribe_email, :inclusion => {:in => [nil, true, false]}
|
||||
validates :musician, :inclusion => {:in => [true, false]}
|
||||
|
||||
|
||||
validate :validate_musician_instruments
|
||||
validate :validate_current_password
|
||||
validate :validate_update_email
|
||||
|
||||
|
||||
validate :validate_avatar_info
|
||||
|
||||
def validate_musician_instruments
|
||||
|
|
@ -597,7 +601,7 @@ module JamRuby
|
|||
# throws ActiveRecord::RecordNotFound if instrument is invalid
|
||||
# throws an email delivery error if unable to connect out to SMTP
|
||||
def self.signup(first_name, last_name, email, password, password_confirmation, terms_of_service, subscribe_email,
|
||||
location, instruments, birth_date, photo_url, invited_user, signup_confirm_url)
|
||||
location, instruments, birth_date, musician, photo_url, invited_user, signup_confirm_url)
|
||||
user = User.new
|
||||
|
||||
UserManager.active_record_transaction do |user_manager|
|
||||
|
|
@ -606,6 +610,7 @@ module JamRuby
|
|||
user.email = email
|
||||
user.subscribe_email = subscribe_email
|
||||
user.terms_of_service = terms_of_service
|
||||
user.musician = musician
|
||||
|
||||
# FIXME: Setting random password for social network logins. This
|
||||
# is because we have validations all over the place on this.
|
||||
|
|
@ -621,21 +626,22 @@ module JamRuby
|
|||
end
|
||||
|
||||
user.admin = false
|
||||
user.musician = true
|
||||
user.city = location[:city]
|
||||
user.state = location[:state]
|
||||
user.country = location[:country]
|
||||
user.birth_date = birth_date
|
||||
|
||||
unless instruments.nil?
|
||||
instruments.each do |musician_instrument_param|
|
||||
instrument = Instrument.find(musician_instrument_param[:instrument_id])
|
||||
musician_instrument = MusicianInstrument.new
|
||||
musician_instrument.user = user
|
||||
musician_instrument.instrument = instrument
|
||||
musician_instrument.proficiency_level = musician_instrument_param[:proficiency_level]
|
||||
musician_instrument.priority = musician_instrument_param[:priority]
|
||||
user.musician_instruments << musician_instrument
|
||||
if user.musician # only update instruments if the user is a musician
|
||||
unless instruments.nil?
|
||||
instruments.each do |musician_instrument_param|
|
||||
instrument = Instrument.find(musician_instrument_param[:instrument_id])
|
||||
musician_instrument = MusicianInstrument.new
|
||||
musician_instrument.user = user
|
||||
musician_instrument.instrument = instrument
|
||||
musician_instrument.proficiency_level = musician_instrument_param[:proficiency_level]
|
||||
musician_instrument.priority = musician_instrument_param[:priority]
|
||||
user.musician_instruments << musician_instrument
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
|
@ -822,8 +828,12 @@ module JamRuby
|
|||
# if valid credentials are supplied for an 'active' user, returns the user
|
||||
# if not authenticated, returns nil
|
||||
def self.authenticate(email, password)
|
||||
# remove email_confirmed restriction due to VRFS-378
|
||||
|
||||
# we only allow users that have confirmed email to authenticate
|
||||
user = User.where('email_confirmed=true').find_by_email(email)
|
||||
# user = User.where('email_confirmed=true').find_by_email(email)
|
||||
|
||||
user = User.find_by_email(email)
|
||||
|
||||
if user && user.valid_password?(password)
|
||||
return user
|
||||
|
|
@ -849,9 +859,12 @@ module JamRuby
|
|||
return []
|
||||
end
|
||||
|
||||
# remove email_confirmed restriction due to VRFS-378
|
||||
# .where("email_confirmed = true AND (name_tsv @@ to_tsquery('jamenglish', ?) OR users.id in (select user_id from musicians_instruments where instrument_id like '%#{search_criteria.downcase}%'))", query)
|
||||
|
||||
return query = User
|
||||
.where("email_confirmed = true AND (name_tsv @@ to_tsquery('jamenglish', ?) OR users.id in (select user_id from musicians_instruments where instrument_id like '%#{search_criteria.downcase}%'))", query)
|
||||
.limit(options[:limit])
|
||||
.where("(name_tsv @@ to_tsquery('jamenglish', ?) OR users.id in (select user_id from musicians_instruments where instrument_id like '%#{search_criteria.downcase}%'))", query)
|
||||
.limit(options[:limit])
|
||||
end
|
||||
|
||||
# devise compatibility
|
||||
|
|
|
|||
|
|
@ -61,12 +61,12 @@ describe User do
|
|||
user_result.id.should == @user2.id
|
||||
end
|
||||
|
||||
it "users who have signed up, but not confirmed should not show up in search index" do
|
||||
it "users who have signed up, but not confirmed should show up in search index due to VRFS-378" do
|
||||
@user3 = FactoryGirl.create(:user, first_name: "unconfirmed", last_name: "unconfirmed", email: "unconfirmed@example.com",
|
||||
password: "foobar", password_confirmation: "foobar", musician: true, email_confirmed: false,
|
||||
city: "Apex", state: "NC", country: "USA")
|
||||
ws = User.search("unconfirmed")
|
||||
ws.length.should == 0
|
||||
ws.length.should == 1
|
||||
|
||||
# Ok, confirm the user, and see them show up
|
||||
@user3.email_confirmed = true
|
||||
|
|
|
|||
Loading…
Reference in New Issue