Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class ChannelRegistrationController < AbstractController
- layout 'channel_registration'
- def questions
- redirect_to '/' and return if !init_vars
- @header_image = 'header2.gif'
- end
- def reg_form
- redirect_to '/' and return if !init_vars
- if @why.blank? || @poss.blank?
- flash[:error] = 'Bitte fülle alle Felder aus.'
- @header_image = 'header2.gif'
- render :action => 'questions'
- return
- end
- end
- def confirmation
- redirect_to '/' and return if !init_vars
- missing = []
- [:first_name, :last_name, :login, :password, :confirm_password, :country_id, :region_id, :city_id, :university_id].each do |f|
- if params[f].blank? then missing << f end
- end
- if params[:email].blank? && params[:email_address].blank?
- missing << :email
- end
- @first_name = params[:first_name]
- @last_name = params[:last_name]
- @login = params[:login]
- @country_id = params[:country_id].to_i
- @region_id = params[:region_id].to_i
- @city_id = params[:city_id].to_i
- @university_id = params[:university_id].to_i
- poss_name = @poss.to_i.to_s
- @why_smaboo = 'Weiterempfehlen? ' + poss_name + "\n\n" + @why
- @accept_agb = params[:accept_agb]
- @accept_data_privacy = params[:accept_data_privacy]
- return if @email_code.blank?
- if missing.length > 0
- puts 'Bitte fülle alle Felder aus!'
- flash[:error] = 'Bitte fülle alle Felder aus!'
- render :action => 'reg_form' and return
- end
- if (params[:password] <=> params[:confirm_password]) != 0
- flash[:error] = 'Die angegebenen Passwörter stimmen nicht überein'
- render :action => 'reg_form' and return
- end
- if(params[:accept_agb] != "1")
- flash[:error] = 'Die AGB müssen akzeptiert werden'
- render :action => 'reg_form' and return
- end
- if(params[:accept_data_privacy] != "1")
- flash[:error] = 'Bitte lies die Datenschutzbestimmungen'
- render :action => 'reg_form' and return
- end
- existing = Login.find_by_login(params[:login])
- if existing != nil
- flash[:error] = 'Login "' + @login + '" ist bereits vergeben.'
- render :action => 'reg_form' and return
- end
- existing = User.find_by_email(@email)
- if !existing.nil?
- flash[:error] = 'Email "' + @email + '" ist bereits vergeben.'
- render :action => 'reg_form' and return
- end
- snr = create_smaboo_nr(@first_name, @last_name)
- unless @email_code.blank?
- ac = AgentCode.find_by_code(@email_code)
- if ac
- if ac.status == AgentCode::STATUS_EMAIL_OPEN
- ac.status = AgentCode::STATUS_EMAIL_USED
- ac.save!
- elsif ac.status == AgentCode::STATUS_MULTI_USE
- # Nothing to do
- else
- flash[:error] = 'Inaktiver Registrierungscode'
- render :action => 'reg_form' and return
- end
- agent_id = ac.agent_id
- else
- flash[:error] = 'Unbekannter Registrierungscode'
- render :action => 'reg_form' and return
- end
- end
- #User::STATUS_ACTIVE
- l = Login.create! :login => params[:login], :password => params[:password]
- u = User.create! :login_id => l.id, :status => User::STATUS_CANDIDATE, :is_promoter => 1,
- :first_name => @first_name, :last_name => @last_name, :smaboo_nr => snr,
- :email => @email, :country_id => @country_id, :university_id => @university_id,
- :why_smaboo => @why_smaboo, :register_code => random_text(20),
- :payment_type => 'p', :agent_id => agent_id, :member_since => Date.today
- send_channel_registration_mail(u)
- c = @channel.campaign
- reason = @why_smaboo
- uid = u.id
- CampaignUser.create(:user_id => uid,
- :campaign_id => c.id,
- :state => CampaignUser::STATE_APPLICATE,
- :application_reason => reason)
- promoter = u
- agent = promoter.agent
- email = agent.email
- gs = GlobalSetting.inst
- from = gs.smaboo_email_sender
- bcc = if gs.smaboo_email_bcc.blank? then nil else gs.smaboo_email_bcc end
- subject = EmailText.find_by_code(EmailText::CampaignApplicationMailSubject).text
- subject = subject.gsub('PROMOTER_FIRST_NAME', promoter.first_name)
- subject = subject.gsub('PROMOTER_LAST_NAME', promoter.last_name)
- subject = subject.gsub('AGENT_FIRST_NAME', agent.first_name)
- subject = subject.gsub('AGENT_LAST_NAME', agent.last_name)
- subject = subject.gsub('CAMPAIGN_NAME', c.name)
- subject = subject.gsub('APPLICATION_REASON', reason)
- body = EmailText.find_by_code(EmailText::CampaignApplicationMailBody).text
- body = body.gsub('PROMOTER_FIRST_NAME', promoter.first_name)
- body = body.gsub('PROMOTER_LAST_NAME', promoter.last_name)
- body = body.gsub('AGENT_FIRST_NAME', agent.first_name)
- body = body.gsub('AGENT_LAST_NAME', agent.last_name)
- body = body.gsub('CAMPAIGN_NAME', c.name)
- body = body.gsub('APPLICATION_REASON', reason)
- SmabooMailer.deliver_standard_mail(email, subject, body, from, bcc)
- end
- def confirm_registration
- login = params[:login]
- code = params[:code]
- if login.blank? or code.blank?
- puts "CONF_REG_ERR_1"
- flash[:error] = "Ungültiger Bestätigungslink (Login oder Sicherheitscode fehlt)"
- redirect_to :controller => 'home', :action => 'index'
- return
- end
- l = Login.find_by_login(login)
- unless l
- puts "CONF_REG_ERR_2"
- flash[:error] = "Ungültiger Bestätigungslink (Login nicht gefunden)"
- redirect_to :controller => 'home', :action => 'index'
- return
- end
- u = l.user
- unless u
- puts "CONF_REG_ERR_3"
- flash[:error] = "Ungültiger Bestätigungslink (Benutzer nicht gefunden)"
- redirect_to :controller => 'home', :action => 'index'
- return
- end
- if code != u.register_code
- puts "CONF_REG_ERR_4"
- flash[:error] = "Ungültiger Bestätigungslink (Falscher Sicherheitscode)"
- redirect_to :controller => 'home', :action => 'index'
- return
- end
- u.status = User::STATUS_ACTIVE
- u.save!
- set_channel(u.agent_id)
- session[:current_user_id] = u.id
- session[:master_login] = 1
- end
- private
- def create_smaboo_nr first_name, last_name
- initials = first_name[0, 1] + last_name[0, 1]
- nr = nil
- good_number = false
- begin
- r = rand(100000)
- if r > 11340
- nr = r.to_s + initials
- occ = User.find(:all, :conditions => ['smaboo_nr=?', nr])
- if occ.length == 0
- good_number = true
- end
- end
- end until good_number
- nr
- end
- private
- def send_channel_registration_mail user
- if user.status == User::STATUS_ACTIVE || user.status == User::STATUS_CANDIDATE
- subject = EmailText.find_by_code(EmailText::ChannelRegistrationMailSubject).text
- body = EmailText.find_by_code(EmailText::ChannelRegistrationMailBody).text
- confirmation_link = url_for(:controller => 'channel_registration',:action => "confirm_registration", :login => user.login.login, :code => user.register_code)
- bd = body
- bd = bd.gsub('FIRST_NAME', user.first_name)
- bd = bd.gsub('LAST_NAME', user.last_name)
- bd = bd.gsub('CONFIRMATION_LINK', confirmation_link)
- gs = GlobalSetting.inst
- from = gs.smaboo_email_sender
- bcc = if gs.smaboo_email_bcc.blank? then nil else gs.smaboo_email_bcc end
- puts "Trying to send mail .."
- SmabooMailer.deliver_standard_mail(user.email, subject, bd, from, bcc)
- puts "Mail sent."
- end
- end
- private
- def init_vars
- @agent = User.find_by_id(params[:agent_id])
- return false if @agent.nil?
- @current_user_id = current_user_id
- @email_code = params[:email_code]
- @email = @email_address = params[:email].to_s
- #redirect_to '/' and return true if @agent.nil?
- @agent_name = @agent.full_name
- @channel = @agent.channel
- @why = params[:why]
- @poss = params[:poss]
- true
- end
- end
Add Comment
Please, Sign In to add comment