|
|
|
|
@ -1,3 +1,4 @@
|
|
|
|
|
require 'kickbox'
|
|
|
|
|
include Devise::Models
|
|
|
|
|
|
|
|
|
|
module JamRuby
|
|
|
|
|
@ -44,7 +45,7 @@ module JamRuby
|
|
|
|
|
|
|
|
|
|
belongs_to :icecast_server_group, class_name: "JamRuby::IcecastServerGroup", inverse_of: :users, foreign_key: 'icecast_server_group_id'
|
|
|
|
|
|
|
|
|
|
has_many :controlled_sessions, :class_name=> "JamRuby::MusicSession", inverse_of: :session_controller, foreign_key: :session_controller_id
|
|
|
|
|
has_many :controlled_sessions, :class_name => "JamRuby::MusicSession", inverse_of: :session_controller, foreign_key: :session_controller_id
|
|
|
|
|
|
|
|
|
|
# authorizations (for facebook, etc -- omniauth)
|
|
|
|
|
has_many :user_authorizations, :class_name => "JamRuby::UserAuthorization"
|
|
|
|
|
@ -60,7 +61,7 @@ module JamRuby
|
|
|
|
|
has_many :received_friend_requests, :class_name => "JamRuby::FriendRequest", :foreign_key => 'friend_id'
|
|
|
|
|
|
|
|
|
|
# instruments
|
|
|
|
|
has_many :musician_instruments, :class_name => "JamRuby::MusicianInstrument", :foreign_key=> 'player_id'
|
|
|
|
|
has_many :musician_instruments, :class_name => "JamRuby::MusicianInstrument", :foreign_key => 'player_id'
|
|
|
|
|
has_many :instruments, :through => :musician_instruments, :class_name => "JamRuby::Instrument"
|
|
|
|
|
|
|
|
|
|
# bands
|
|
|
|
|
@ -151,8 +152,8 @@ module JamRuby
|
|
|
|
|
has_many :event_sessions, :class_name => "JamRuby::EventSession"
|
|
|
|
|
|
|
|
|
|
# gift cards
|
|
|
|
|
has_many :gift_cards, :class_name=> "JamRuby::GiftCard"
|
|
|
|
|
has_many :gift_card_purchases, :class_name=> "JamRuby::GiftCardPurchase"
|
|
|
|
|
has_many :gift_cards, :class_name => "JamRuby::GiftCard"
|
|
|
|
|
has_many :gift_card_purchases, :class_name => "JamRuby::GiftCardPurchase"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# affiliate_partner
|
|
|
|
|
@ -161,7 +162,7 @@ module JamRuby
|
|
|
|
|
# diagnostics
|
|
|
|
|
has_many :diagnostics, :class_name => "JamRuby::Diagnostic"
|
|
|
|
|
|
|
|
|
|
# jam_tracks
|
|
|
|
|
# jam_tracks
|
|
|
|
|
has_many :jam_track_rights, :class_name => "JamRuby::JamTrackRight", :foreign_key => "user_id"
|
|
|
|
|
has_many :purchased_jam_tracks, :through => :jam_track_rights, :class_name => "JamRuby::JamTrack", :source => :jam_track, :order => :created_at
|
|
|
|
|
|
|
|
|
|
@ -177,8 +178,8 @@ module JamRuby
|
|
|
|
|
# This causes the authenticate method to be generated (among other stuff)
|
|
|
|
|
#has_secure_password
|
|
|
|
|
|
|
|
|
|
has_many :online_presences, :class_name => "JamRuby::OnlinePresence", :foreign_key=> 'player_id'
|
|
|
|
|
has_many :performance_samples, :class_name => "JamRuby::PerformanceSample", :foreign_key=> 'player_id'
|
|
|
|
|
has_many :online_presences, :class_name => "JamRuby::OnlinePresence", :foreign_key => 'player_id'
|
|
|
|
|
has_many :performance_samples, :class_name => "JamRuby::PerformanceSample", :foreign_key => 'player_id'
|
|
|
|
|
|
|
|
|
|
has_one :musician_search, :class_name => 'JamRuby::MusicianSearch'
|
|
|
|
|
has_one :band_search, :class_name => 'JamRuby::BandSearch'
|
|
|
|
|
@ -187,9 +188,9 @@ module JamRuby
|
|
|
|
|
|
|
|
|
|
before_save :default_anonymous_names
|
|
|
|
|
before_save :create_remember_token, :if => :should_validate_password?
|
|
|
|
|
before_save :stringify_avatar_info , :if => :updating_avatar
|
|
|
|
|
before_save :stringify_avatar_info, :if => :updating_avatar
|
|
|
|
|
|
|
|
|
|
validates :first_name, length: {maximum: 50}, no_profanity: true
|
|
|
|
|
validates :first_name, length: {maximum: 50}, no_profanity: true
|
|
|
|
|
validates :last_name, length: {maximum: 50}, no_profanity: true
|
|
|
|
|
validates :last_name, length: {maximum: 50}, no_profanity: true
|
|
|
|
|
validates :biography, length: {maximum: 4000}, no_profanity: true
|
|
|
|
|
@ -200,21 +201,21 @@ module JamRuby
|
|
|
|
|
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 :terms_of_service, :acceptance => {:accept => true, :on => :create, :allow_nil => false}
|
|
|
|
|
validates :reuse_card, :inclusion => {:in => [true, false]}
|
|
|
|
|
validates :has_redeemable_jamtrack, :inclusion => {:in => [true, false]}
|
|
|
|
|
validates :gifted_jamtracks, presence: true, :numericality => { :less_than_or_equal_to => 100 }
|
|
|
|
|
validates :gifted_jamtracks, presence: true, :numericality => {:less_than_or_equal_to => 100}
|
|
|
|
|
validates :subscribe_email, :inclusion => {:in => [nil, true, false]}
|
|
|
|
|
validates :musician, :inclusion => {:in => [true, false]}
|
|
|
|
|
validates :show_whats_next, :inclusion => {:in => [nil, true, false]}
|
|
|
|
|
validates :mods, json: true
|
|
|
|
|
validates_numericality_of :last_jam_audio_latency, greater_than:MINIMUM_AUDIO_LATENCY, less_than:MAXIMUM_AUDIO_LATENCY, :allow_nil => true
|
|
|
|
|
validates :last_jam_updated_reason, :inclusion => {:in => [nil, JAM_REASON_REGISTRATION, JAM_REASON_NETWORK_TEST, JAM_REASON_FTUE, JAM_REASON_JOIN, JAM_REASON_IMPORT, JAM_REASON_LOGIN] }
|
|
|
|
|
validates_numericality_of :last_jam_audio_latency, greater_than: MINIMUM_AUDIO_LATENCY, less_than: MAXIMUM_AUDIO_LATENCY, :allow_nil => true
|
|
|
|
|
validates :last_jam_updated_reason, :inclusion => {:in => [nil, JAM_REASON_REGISTRATION, JAM_REASON_NETWORK_TEST, JAM_REASON_FTUE, JAM_REASON_JOIN, JAM_REASON_IMPORT, JAM_REASON_LOGIN]}
|
|
|
|
|
|
|
|
|
|
# stored in cents
|
|
|
|
|
validates_numericality_of :paid_sessions_hourly_rate, greater_than:0, less_than:200000, :if => :paid_sessions
|
|
|
|
|
validates_numericality_of :paid_sessions_hourly_rate, greater_than: 0, less_than: 200000, :if => :paid_sessions
|
|
|
|
|
# stored in cents
|
|
|
|
|
validates_numericality_of :paid_sessions_daily_rate, greater_than:0, less_than:5000000, :if => :paid_sessions
|
|
|
|
|
validates_numericality_of :paid_sessions_daily_rate, greater_than: 0, less_than: 5000000, :if => :paid_sessions
|
|
|
|
|
|
|
|
|
|
# custom validators
|
|
|
|
|
validate :validate_musician_instruments
|
|
|
|
|
@ -233,7 +234,7 @@ module JamRuby
|
|
|
|
|
scope :email_opt_in, where(:subscribe_email => true)
|
|
|
|
|
|
|
|
|
|
def user_progression_fields
|
|
|
|
|
@user_progression_fields ||= Set.new ["first_downloaded_client_at", "first_ran_client_at", "first_music_session_at", "first_real_music_session_at", "first_good_music_session_at", "first_certified_gear_at", "first_invited_at", "first_friended_at", "first_recording_at", "first_social_promoted_at", "first_played_jamtrack_at" ]
|
|
|
|
|
@user_progression_fields ||= Set.new ["first_downloaded_client_at", "first_ran_client_at", "first_music_session_at", "first_real_music_session_at", "first_good_music_session_at", "first_certified_gear_at", "first_invited_at", "first_friended_at", "first_recording_at", "first_social_promoted_at", "first_played_jamtrack_at"]
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def update_progression_field(field_name, time = DateTime.now)
|
|
|
|
|
@ -414,7 +415,7 @@ module JamRuby
|
|
|
|
|
|
|
|
|
|
def age
|
|
|
|
|
now = Time.now.utc.to_date
|
|
|
|
|
self.birth_date.nil? ? "" : now.year - self.birth_date.year - (self.birth_date.to_date.change(:year => now.year) > now ? 1 : 0)
|
|
|
|
|
self.birth_date.nil? ? "" : now.year - self.birth_date.year - (self.birth_date.to_date.change(:year => now.year) > now ? 1 : 0)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def session_count
|
|
|
|
|
@ -463,6 +464,7 @@ module JamRuby
|
|
|
|
|
a = read_attribute(:audio_latency)
|
|
|
|
|
a.nil? ? nil : a.to_i
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
# ====== END ARTIFICAL ATTRIBUTES
|
|
|
|
|
|
|
|
|
|
def score_info(destination_user)
|
|
|
|
|
@ -534,25 +536,25 @@ module JamRuby
|
|
|
|
|
# used to exclude currently viewed recording
|
|
|
|
|
recording_exclusion = "claimed_recordings.id != '#{claimed_recording_id}'" if claimed_recording_id
|
|
|
|
|
recordings = Recording
|
|
|
|
|
.joins(:claimed_recordings)
|
|
|
|
|
.where(:owner_id => self.id)
|
|
|
|
|
.where("claimed_recordings.user_id = '#{self.id}'")
|
|
|
|
|
.where('claimed_recordings.is_public=true')
|
|
|
|
|
.where(recording_exclusion)
|
|
|
|
|
.order('created_at DESC')
|
|
|
|
|
.limit(10)
|
|
|
|
|
.joins(:claimed_recordings)
|
|
|
|
|
.where(:owner_id => self.id)
|
|
|
|
|
.where("claimed_recordings.user_id = '#{self.id}'")
|
|
|
|
|
.where('claimed_recordings.is_public=true')
|
|
|
|
|
.where(recording_exclusion)
|
|
|
|
|
.order('created_at DESC')
|
|
|
|
|
.limit(10)
|
|
|
|
|
|
|
|
|
|
# used to exclude currently viewed session
|
|
|
|
|
session_exclusion = "music_sessions.id != '#{session_id}'" if session_id
|
|
|
|
|
session_exclusion = "music_sessions.id != '#{session_id}'" if session_id
|
|
|
|
|
msh = MusicSession
|
|
|
|
|
.where(:user_id => self.id)
|
|
|
|
|
.where(:fan_access => true)
|
|
|
|
|
.where(session_exclusion)
|
|
|
|
|
.order('created_at DESC')
|
|
|
|
|
.limit(10)
|
|
|
|
|
.where(:user_id => self.id)
|
|
|
|
|
.where(:fan_access => true)
|
|
|
|
|
.where(session_exclusion)
|
|
|
|
|
.order('created_at DESC')
|
|
|
|
|
.limit(10)
|
|
|
|
|
|
|
|
|
|
recordings.concat(msh)
|
|
|
|
|
recordings.sort! {|a,b| b.created_at <=> a.created_at}.first(5)
|
|
|
|
|
recordings.sort! { |a, b| b.created_at <=> a.created_at }.first(5)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
# returns the # of new notifications
|
|
|
|
|
@ -583,6 +585,7 @@ module JamRuby
|
|
|
|
|
|
|
|
|
|
def confirm_email!
|
|
|
|
|
self.email_confirmed = true
|
|
|
|
|
self.email_needs_verification = false
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def my_session_settings
|
|
|
|
|
@ -626,12 +629,12 @@ module JamRuby
|
|
|
|
|
# so that should_validate_password? fires
|
|
|
|
|
self.updating_password = true
|
|
|
|
|
|
|
|
|
|
attributes = { :password => new_password, :password_confirmation => new_password_confirmation }
|
|
|
|
|
attributes = {:password => new_password, :password_confirmation => new_password_confirmation}
|
|
|
|
|
|
|
|
|
|
# taken liberally from Devise::DatabaseAuthenticatable.update_with_password
|
|
|
|
|
|
|
|
|
|
if valid_password?(old_password)
|
|
|
|
|
update_attributes(attributes)
|
|
|
|
|
update_attributes(attributes)
|
|
|
|
|
else
|
|
|
|
|
self.assign_attributes(attributes)
|
|
|
|
|
self.valid?
|
|
|
|
|
@ -652,15 +655,15 @@ module JamRuby
|
|
|
|
|
user.change_password(new_password, new_password_confirmation)
|
|
|
|
|
user.save
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def change_password(new_password, new_password_confirmation)
|
|
|
|
|
# FIXME: Should verify that the new password meets certain quality criteria. Really, maybe that should be a
|
|
|
|
|
# verification step.
|
|
|
|
|
self.updating_password = true
|
|
|
|
|
self.updating_password = true
|
|
|
|
|
self.password = new_password
|
|
|
|
|
self.password_confirmation = new_password_confirmation
|
|
|
|
|
|
|
|
|
|
UserMailer.password_changed(self).deliver
|
|
|
|
|
|
|
|
|
|
UserMailer.password_changed(self).deliver
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def self.reset_password(email, base_uri)
|
|
|
|
|
@ -673,7 +676,7 @@ module JamRuby
|
|
|
|
|
|
|
|
|
|
reset_url = "#{base_uri}/reset_password_token?token=#{user.reset_password_token}&email=#{CGI.escape(email)}"
|
|
|
|
|
UserMailer.password_reset(user, reset_url).deliver
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
user
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
@ -694,11 +697,11 @@ module JamRuby
|
|
|
|
|
|
|
|
|
|
if hide_private
|
|
|
|
|
recordings = Recording.joins(:musician_recordings)
|
|
|
|
|
.where(:musicians_recordings => {:user_id => "#{user_id}"}, :public => true)
|
|
|
|
|
.where(:musicians_recordings => {:user_id => "#{user_id}"}, :public => true)
|
|
|
|
|
|
|
|
|
|
else
|
|
|
|
|
recordings = Recording.joins(:musician_recordings)
|
|
|
|
|
.where(:musicians_recordings => {:user_id => "#{user_id}"})
|
|
|
|
|
.where(:musicians_recordings => {:user_id => "#{user_id}"})
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
return recordings
|
|
|
|
|
@ -706,7 +709,7 @@ module JamRuby
|
|
|
|
|
|
|
|
|
|
def update_genres(gids, genre_type)
|
|
|
|
|
unless self.new_record?
|
|
|
|
|
GenrePlayer.delete_all(["player_id = ? AND player_type = ? AND genre_type = ?",
|
|
|
|
|
GenrePlayer.delete_all(["player_id = ? AND player_type = ? AND genre_type = ?",
|
|
|
|
|
self.id, self.class.name, genre_type])
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
@ -715,7 +718,7 @@ module JamRuby
|
|
|
|
|
genre_player.player_id = self.id
|
|
|
|
|
genre_player.player_type = self.class.name
|
|
|
|
|
genre_player.genre_id = gid
|
|
|
|
|
genre_player.genre_type = genre_type
|
|
|
|
|
genre_player.genre_type = genre_type
|
|
|
|
|
self.genre_players << genre_player
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
@ -727,7 +730,7 @@ module JamRuby
|
|
|
|
|
|
|
|
|
|
unless online_presences.nil?
|
|
|
|
|
online_presences.each do |op|
|
|
|
|
|
new_presence = OnlinePresence.create(self, op, false)
|
|
|
|
|
new_presence = OnlinePresence.create(self, op, false)
|
|
|
|
|
self.online_presences << new_presence
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
@ -783,7 +786,7 @@ module JamRuby
|
|
|
|
|
# this easy_save routine guards against nil sets, but many of these fields can be set to null.
|
|
|
|
|
# I've started to use it less as I go forward
|
|
|
|
|
def easy_save(first_name, last_name, email, password, password_confirmation, musician, gender,
|
|
|
|
|
birth_date, internet_service_provider, city, state, country, instruments, photo_url, biography = nil)
|
|
|
|
|
birth_date, internet_service_provider, city, state, country, instruments, photo_url, biography = nil)
|
|
|
|
|
|
|
|
|
|
# first name
|
|
|
|
|
unless first_name.nil?
|
|
|
|
|
@ -866,7 +869,7 @@ module JamRuby
|
|
|
|
|
|
|
|
|
|
# helper method for creating / updating a User
|
|
|
|
|
def self.save(id, updater_id, first_name, last_name, email, password, password_confirmation, musician, gender,
|
|
|
|
|
birth_date, internet_service_provider, city, state, country, instruments, photo_url, biography)
|
|
|
|
|
birth_date, internet_service_provider, city, state, country, instruments, photo_url, biography)
|
|
|
|
|
if id.nil?
|
|
|
|
|
user = User.new()
|
|
|
|
|
else
|
|
|
|
|
@ -875,7 +878,7 @@ module JamRuby
|
|
|
|
|
|
|
|
|
|
if user.id != updater_id
|
|
|
|
|
raise JamPermissionError, ValidationMessages::PERMISSION_VALIDATION_ERROR
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
user.easy_save(first_name, last_name, email, password, password_confirmation, musician, gender,
|
|
|
|
|
birth_date, internet_service_provider, city, state, country, instruments, photo_url, biography)
|
|
|
|
|
@ -959,7 +962,7 @@ module JamRuby
|
|
|
|
|
|
|
|
|
|
# def create_recording_like(targetRecordingId)
|
|
|
|
|
# targetRecording = Recording.find(targetRecordingId)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# like = Like.new
|
|
|
|
|
# like.likable = targetRecording
|
|
|
|
|
# like.user = self
|
|
|
|
|
@ -974,7 +977,7 @@ module JamRuby
|
|
|
|
|
user.email = user.update_email
|
|
|
|
|
user.update_email_token = nil
|
|
|
|
|
user.save
|
|
|
|
|
begin
|
|
|
|
|
begin
|
|
|
|
|
RecurlyClient.new.update_account(user)
|
|
|
|
|
rescue Recurly::Error
|
|
|
|
|
@@log.debug("No recurly account found; continuing")
|
|
|
|
|
@ -991,7 +994,7 @@ module JamRuby
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def favorite_count
|
|
|
|
|
0 # FIXME: update this with recording likes count when implemented
|
|
|
|
|
0 # FIXME: update this with recording likes count when implemented
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def self.delete_favorite(user_id, recording_id)
|
|
|
|
|
@ -1015,15 +1018,15 @@ module JamRuby
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
session_settings = { :band_id => music_session.band_id,
|
|
|
|
|
:musician_access => music_session.musician_access,
|
|
|
|
|
:approval_required => music_session.approval_required,
|
|
|
|
|
:fan_chat => music_session.fan_chat,
|
|
|
|
|
:fan_access => music_session.fan_access,
|
|
|
|
|
:description => music_session.description,
|
|
|
|
|
:genres => genres,
|
|
|
|
|
:invitees => invitees
|
|
|
|
|
}.to_json
|
|
|
|
|
session_settings = {:band_id => music_session.band_id,
|
|
|
|
|
:musician_access => music_session.musician_access,
|
|
|
|
|
:approval_required => music_session.approval_required,
|
|
|
|
|
:fan_chat => music_session.fan_chat,
|
|
|
|
|
:fan_access => music_session.fan_access,
|
|
|
|
|
:description => music_session.description,
|
|
|
|
|
:genres => genres,
|
|
|
|
|
:invitees => invitees
|
|
|
|
|
}.to_json
|
|
|
|
|
|
|
|
|
|
user.session_settings = session_settings
|
|
|
|
|
user.save
|
|
|
|
|
@ -1077,7 +1080,7 @@ module JamRuby
|
|
|
|
|
# Seth: I think we need a flag in the signature of signup to say 'social_signup=true'. If that flag is set,
|
|
|
|
|
# then you can do use.updating_password = false and instead set a null password
|
|
|
|
|
if password.nil?
|
|
|
|
|
user.password = user.password_confirmation = SecureRandom.urlsafe_base64
|
|
|
|
|
user.password = user.password_confirmation = SecureRandom.urlsafe_base64
|
|
|
|
|
else
|
|
|
|
|
user.password = password
|
|
|
|
|
user.password_confirmation = password_confirmation
|
|
|
|
|
@ -1178,7 +1181,7 @@ module JamRuby
|
|
|
|
|
# if a gift card value was passed in, then try to find that gift card and apply it to user
|
|
|
|
|
if gift_card
|
|
|
|
|
user.expecting_gift_card = true
|
|
|
|
|
found_gift_card = GiftCard.where(code:gift_card).where(user_id:nil).first
|
|
|
|
|
found_gift_card = GiftCard.where(code: gift_card).where(user_id: nil).first
|
|
|
|
|
user.gift_cards << found_gift_card if found_gift_card
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
@ -1203,6 +1206,35 @@ module JamRuby
|
|
|
|
|
|
|
|
|
|
user.errors.add("recaptcha", "verification failed") if recaptcha_failed
|
|
|
|
|
|
|
|
|
|
unless user.errors.any?
|
|
|
|
|
if Rails.application.config.verify_email_enabled
|
|
|
|
|
client = Kickbox::Client.new(Rails.application.config.kickbox_api_key)
|
|
|
|
|
kickbox = client.kickbox()
|
|
|
|
|
response = kickbox.verify(email)
|
|
|
|
|
result = response.body["result"]
|
|
|
|
|
|
|
|
|
|
user.kickbox_response = response.body.to_json
|
|
|
|
|
if result == "deliverable"
|
|
|
|
|
user.email_needs_verification = false
|
|
|
|
|
elsif result == "undeliverable"
|
|
|
|
|
|
|
|
|
|
did_you_mean = response.body["did_you_mean"]
|
|
|
|
|
if did_you_mean
|
|
|
|
|
user.errors.add(:email, "Did you mean #{did_you_mean}?")
|
|
|
|
|
else
|
|
|
|
|
user.errors.add(:email, "is not real")
|
|
|
|
|
end
|
|
|
|
|
elsif result == "risky" || result == "unknown"
|
|
|
|
|
user.email_needs_verification = true
|
|
|
|
|
end
|
|
|
|
|
else
|
|
|
|
|
user.email_needs_verification = false
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
user.save unless user.errors.any?
|
|
|
|
|
|
|
|
|
|
if user.errors.any?
|
|
|
|
|
raise ActiveRecord::Rollback
|
|
|
|
|
else
|
|
|
|
|
@ -1224,13 +1256,15 @@ module JamRuby
|
|
|
|
|
else
|
|
|
|
|
# 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.confirm_email(user, signup_confirm_url.nil? ? nil : (signup_confirm_url + "/" + user.signup_token) ).deliver
|
|
|
|
|
UserMailer.confirm_email(user, signup_confirm_url.nil? ? nil : (signup_confirm_url + "/" + user.signup_token)).deliver
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
user.reload if user.id# gift card adding gifted_jamtracks doesn't reflect here until reload
|
|
|
|
|
user.reload if user.id # gift card adding gifted_jamtracks doesn't reflect here until reload
|
|
|
|
|
user
|
|
|
|
|
end # def signup
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
# def signup
|
|
|
|
|
|
|
|
|
|
# this is intended to be development-mode or test-mode only; VRFS-149
|
|
|
|
|
# it creates or updates one user per developer, so that we aren't in the business
|
|
|
|
|
@ -1240,7 +1274,7 @@ module JamRuby
|
|
|
|
|
# because otherwise it's a bit of uncomfortable code
|
|
|
|
|
# to have sitting around
|
|
|
|
|
def self.create_dev_user(first_name, last_name, email, password,
|
|
|
|
|
city, state, country, instruments, photo_url)
|
|
|
|
|
city, state, country, instruments, photo_url)
|
|
|
|
|
|
|
|
|
|
if Environment.mode == "production"
|
|
|
|
|
# short-circuit out
|
|
|
|
|
@ -1248,7 +1282,7 @@ module JamRuby
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
user = User.find_or_create_by_email(email)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
User.transaction do
|
|
|
|
|
user.first_name = first_name
|
|
|
|
|
user.last_name = last_name
|
|
|
|
|
@ -1354,15 +1388,15 @@ module JamRuby
|
|
|
|
|
cropped_large_s3_path = cropped_large_fpfile["key"]
|
|
|
|
|
|
|
|
|
|
self.update_attributes(
|
|
|
|
|
:original_fpfile => original_fpfile,
|
|
|
|
|
:cropped_fpfile => cropped_fpfile,
|
|
|
|
|
:cropped_large_fpfile => cropped_large_fpfile,
|
|
|
|
|
:cropped_s3_path => cropped_s3_path,
|
|
|
|
|
:cropped_large_s3_path => cropped_large_s3_path,
|
|
|
|
|
:crop_selection => crop_selection,
|
|
|
|
|
:photo_url => S3Util.url(aws_bucket, escape_filename(cropped_s3_path), :secure => true),
|
|
|
|
|
:large_photo_url => S3Util.url(aws_bucket, escape_filename(cropped_large_s3_path), :secure => true)
|
|
|
|
|
)
|
|
|
|
|
:original_fpfile => original_fpfile,
|
|
|
|
|
:cropped_fpfile => cropped_fpfile,
|
|
|
|
|
:cropped_large_fpfile => cropped_large_fpfile,
|
|
|
|
|
:cropped_s3_path => cropped_s3_path,
|
|
|
|
|
:cropped_large_s3_path => cropped_large_s3_path,
|
|
|
|
|
:crop_selection => crop_selection,
|
|
|
|
|
:photo_url => S3Util.url(aws_bucket, escape_filename(cropped_s3_path), :secure => true),
|
|
|
|
|
:large_photo_url => S3Util.url(aws_bucket, escape_filename(cropped_large_s3_path), :secure => true)
|
|
|
|
|
)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def delete_avatar(aws_bucket)
|
|
|
|
|
@ -1453,10 +1487,10 @@ module JamRuby
|
|
|
|
|
|
|
|
|
|
if user_authorization.nil?
|
|
|
|
|
user_authorization = UserAuthorization.new(provider: 'twitter',
|
|
|
|
|
uid: twitter_uid,
|
|
|
|
|
token: token,
|
|
|
|
|
secret: secret,
|
|
|
|
|
user: self)
|
|
|
|
|
uid: twitter_uid,
|
|
|
|
|
token: token,
|
|
|
|
|
secret: secret,
|
|
|
|
|
user: self)
|
|
|
|
|
else
|
|
|
|
|
user_authorization.uid = twitter_uid
|
|
|
|
|
user_authorization.token = token
|
|
|
|
|
@ -1514,6 +1548,7 @@ module JamRuby
|
|
|
|
|
def self.after_maxmind_import
|
|
|
|
|
update_locidispids
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
# def check_lat_lng
|
|
|
|
|
# if (city_changed? || state_changed? || country_changed?) && !lat_changed? && !lng_changed?
|
|
|
|
|
# update_lat_lng
|
|
|
|
|
@ -1581,9 +1616,9 @@ module JamRuby
|
|
|
|
|
|
|
|
|
|
def top_followings
|
|
|
|
|
@topf ||= User.joins("INNER JOIN follows ON follows.followable_id = users.id AND follows.followable_type = '#{self.class.to_s}'")
|
|
|
|
|
.where(['follows.user_id = ?', self.id])
|
|
|
|
|
.order('follows.created_at DESC')
|
|
|
|
|
.limit(3)
|
|
|
|
|
.where(['follows.user_id = ?', self.id])
|
|
|
|
|
.order('follows.created_at DESC')
|
|
|
|
|
.limit(3)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def nearest_musicians
|
|
|
|
|
@ -1662,6 +1697,7 @@ module JamRuby
|
|
|
|
|
|
|
|
|
|
!approved_slots.blank?
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
# end devise compatibility
|
|
|
|
|
|
|
|
|
|
def self.stats
|
|
|
|
|
@ -1759,23 +1795,23 @@ module JamRuby
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
private
|
|
|
|
|
def create_remember_token
|
|
|
|
|
self.remember_token = SecureRandom.urlsafe_base64
|
|
|
|
|
end
|
|
|
|
|
def create_remember_token
|
|
|
|
|
self.remember_token = SecureRandom.urlsafe_base64
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def default_anonymous_names
|
|
|
|
|
self.first_name = 'Anonymous' if self.first_name.nil?
|
|
|
|
|
self.last_name = 'Anonymous' if self.last_name.nil?
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def stringify_avatar_info
|
|
|
|
|
# fpfile comes in as a hash, which is a easy-to-use and validate form. However, we store it as a VARCHAR,
|
|
|
|
|
# so we need t oconvert it to JSON before storing it (otherwise it gets serialized as a ruby object)
|
|
|
|
|
# later, when serving this data out to the REST API, we currently just leave it as a string and make a JSON capable
|
|
|
|
|
# client parse it, because it's very rare when it's needed at all
|
|
|
|
|
self.original_fpfile = original_fpfile.to_json if !original_fpfile.nil?
|
|
|
|
|
self.cropped_fpfile = cropped_fpfile.to_json if !cropped_fpfile.nil?
|
|
|
|
|
self.crop_selection = crop_selection.to_json if !crop_selection.nil?
|
|
|
|
|
end
|
|
|
|
|
def stringify_avatar_info
|
|
|
|
|
# fpfile comes in as a hash, which is a easy-to-use and validate form. However, we store it as a VARCHAR,
|
|
|
|
|
# so we need t oconvert it to JSON before storing it (otherwise it gets serialized as a ruby object)
|
|
|
|
|
# later, when serving this data out to the REST API, we currently just leave it as a string and make a JSON capable
|
|
|
|
|
# client parse it, because it's very rare when it's needed at all
|
|
|
|
|
self.original_fpfile = original_fpfile.to_json if !original_fpfile.nil?
|
|
|
|
|
self.cropped_fpfile = cropped_fpfile.to_json if !cropped_fpfile.nil?
|
|
|
|
|
self.crop_selection = crop_selection.to_json if !crop_selection.nil?
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|