Guest User

Untitled

a guest
May 6th, 2018
226
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.95 KB | None | 0 0
  1. class ChannelRegistrationController < AbstractController
  2.  
  3. layout 'channel_registration'
  4.  
  5. def questions
  6. redirect_to '/' and return if !init_vars
  7. @header_image = 'header2.gif'
  8. end
  9.  
  10. def reg_form
  11. redirect_to '/' and return if !init_vars
  12. if @why.blank? || @poss.blank?
  13. flash[:error] = 'Bitte fülle alle Felder aus.'
  14. @header_image = 'header2.gif'
  15. render :action => 'questions'
  16. return
  17. end
  18. end
  19.  
  20. def confirmation
  21. redirect_to '/' and return if !init_vars
  22.  
  23. missing = []
  24. [:first_name, :last_name, :login, :password, :confirm_password, :country_id, :region_id, :city_id, :university_id].each do |f|
  25. if params[f].blank? then missing << f end
  26. end
  27. if params[:email].blank? && params[:email_address].blank?
  28. missing << :email
  29. end
  30.  
  31. @first_name = params[:first_name]
  32. @last_name = params[:last_name]
  33. @login = params[:login]
  34. @country_id = params[:country_id].to_i
  35. @region_id = params[:region_id].to_i
  36. @city_id = params[:city_id].to_i
  37. @university_id = params[:university_id].to_i
  38. poss_name = @poss.to_i.to_s
  39. @why_smaboo = 'Weiterempfehlen? ' + poss_name + "\n\n" + @why
  40. @accept_agb = params[:accept_agb]
  41. @accept_data_privacy = params[:accept_data_privacy]
  42.  
  43. return if @email_code.blank?
  44.  
  45. if missing.length > 0
  46. puts 'Bitte fülle alle Felder aus!'
  47. flash[:error] = 'Bitte fülle alle Felder aus!'
  48. render :action => 'reg_form' and return
  49. end
  50.  
  51. if (params[:password] <=> params[:confirm_password]) != 0
  52. flash[:error] = 'Die angegebenen Passwörter stimmen nicht überein'
  53. render :action => 'reg_form' and return
  54. end
  55.  
  56. if(params[:accept_agb] != "1")
  57. flash[:error] = 'Die AGB müssen akzeptiert werden'
  58. render :action => 'reg_form' and return
  59. end
  60.  
  61. if(params[:accept_data_privacy] != "1")
  62. flash[:error] = 'Bitte lies die Datenschutzbestimmungen'
  63. render :action => 'reg_form' and return
  64. end
  65.  
  66. existing = Login.find_by_login(params[:login])
  67. if existing != nil
  68. flash[:error] = 'Login "' + @login + '" ist bereits vergeben.'
  69. render :action => 'reg_form' and return
  70. end
  71.  
  72. existing = User.find_by_email(@email)
  73. if !existing.nil?
  74. flash[:error] = 'Email "' + @email + '" ist bereits vergeben.'
  75. render :action => 'reg_form' and return
  76. end
  77.  
  78. snr = create_smaboo_nr(@first_name, @last_name)
  79.  
  80. unless @email_code.blank?
  81. ac = AgentCode.find_by_code(@email_code)
  82. if ac
  83. if ac.status == AgentCode::STATUS_EMAIL_OPEN
  84. ac.status = AgentCode::STATUS_EMAIL_USED
  85. ac.save!
  86. elsif ac.status == AgentCode::STATUS_MULTI_USE
  87. # Nothing to do
  88. else
  89. flash[:error] = 'Inaktiver Registrierungscode'
  90. render :action => 'reg_form' and return
  91. end
  92. agent_id = ac.agent_id
  93. else
  94. flash[:error] = 'Unbekannter Registrierungscode'
  95. render :action => 'reg_form' and return
  96. end
  97. end
  98.  
  99. #User::STATUS_ACTIVE
  100. l = Login.create! :login => params[:login], :password => params[:password]
  101. u = User.create! :login_id => l.id, :status => User::STATUS_CANDIDATE, :is_promoter => 1,
  102. :first_name => @first_name, :last_name => @last_name, :smaboo_nr => snr,
  103. :email => @email, :country_id => @country_id, :university_id => @university_id,
  104. :why_smaboo => @why_smaboo, :register_code => random_text(20),
  105. :payment_type => 'p', :agent_id => agent_id, :member_since => Date.today
  106.  
  107. send_channel_registration_mail(u)
  108.  
  109. c = @channel.campaign
  110. reason = @why_smaboo
  111. uid = u.id
  112.  
  113. CampaignUser.create(:user_id => uid,
  114. :campaign_id => c.id,
  115. :state => CampaignUser::STATE_APPLICATE,
  116. :application_reason => reason)
  117.  
  118. promoter = u
  119. agent = promoter.agent
  120.  
  121. email = agent.email
  122. gs = GlobalSetting.inst
  123. from = gs.smaboo_email_sender
  124. bcc = if gs.smaboo_email_bcc.blank? then nil else gs.smaboo_email_bcc end
  125.  
  126. subject = EmailText.find_by_code(EmailText::CampaignApplicationMailSubject).text
  127. subject = subject.gsub('PROMOTER_FIRST_NAME', promoter.first_name)
  128. subject = subject.gsub('PROMOTER_LAST_NAME', promoter.last_name)
  129. subject = subject.gsub('AGENT_FIRST_NAME', agent.first_name)
  130. subject = subject.gsub('AGENT_LAST_NAME', agent.last_name)
  131. subject = subject.gsub('CAMPAIGN_NAME', c.name)
  132. subject = subject.gsub('APPLICATION_REASON', reason)
  133.  
  134. body = EmailText.find_by_code(EmailText::CampaignApplicationMailBody).text
  135. body = body.gsub('PROMOTER_FIRST_NAME', promoter.first_name)
  136. body = body.gsub('PROMOTER_LAST_NAME', promoter.last_name)
  137. body = body.gsub('AGENT_FIRST_NAME', agent.first_name)
  138. body = body.gsub('AGENT_LAST_NAME', agent.last_name)
  139. body = body.gsub('CAMPAIGN_NAME', c.name)
  140. body = body.gsub('APPLICATION_REASON', reason)
  141.  
  142. SmabooMailer.deliver_standard_mail(email, subject, body, from, bcc)
  143.  
  144. end
  145.  
  146. def confirm_registration
  147. login = params[:login]
  148. code = params[:code]
  149.  
  150. if login.blank? or code.blank?
  151. puts "CONF_REG_ERR_1"
  152. flash[:error] = "Ungültiger Bestätigungslink (Login oder Sicherheitscode fehlt)"
  153. redirect_to :controller => 'home', :action => 'index'
  154. return
  155. end
  156. l = Login.find_by_login(login)
  157. unless l
  158. puts "CONF_REG_ERR_2"
  159. flash[:error] = "Ungültiger Bestätigungslink (Login nicht gefunden)"
  160. redirect_to :controller => 'home', :action => 'index'
  161. return
  162. end
  163. u = l.user
  164. unless u
  165. puts "CONF_REG_ERR_3"
  166. flash[:error] = "Ungültiger Bestätigungslink (Benutzer nicht gefunden)"
  167. redirect_to :controller => 'home', :action => 'index'
  168. return
  169. end
  170. if code != u.register_code
  171. puts "CONF_REG_ERR_4"
  172. flash[:error] = "Ungültiger Bestätigungslink (Falscher Sicherheitscode)"
  173. redirect_to :controller => 'home', :action => 'index'
  174. return
  175. end
  176. u.status = User::STATUS_ACTIVE
  177. u.save!
  178. set_channel(u.agent_id)
  179. session[:current_user_id] = u.id
  180. session[:master_login] = 1
  181. end
  182.  
  183. private
  184. def create_smaboo_nr first_name, last_name
  185. initials = first_name[0, 1] + last_name[0, 1]
  186. nr = nil
  187. good_number = false
  188. begin
  189. r = rand(100000)
  190. if r > 11340
  191. nr = r.to_s + initials
  192. occ = User.find(:all, :conditions => ['smaboo_nr=?', nr])
  193. if occ.length == 0
  194. good_number = true
  195. end
  196. end
  197. end until good_number
  198. nr
  199. end
  200.  
  201. private
  202. def send_channel_registration_mail user
  203. if user.status == User::STATUS_ACTIVE || user.status == User::STATUS_CANDIDATE
  204. subject = EmailText.find_by_code(EmailText::ChannelRegistrationMailSubject).text
  205. body = EmailText.find_by_code(EmailText::ChannelRegistrationMailBody).text
  206. confirmation_link = url_for(:controller => 'channel_registration',:action => "confirm_registration", :login => user.login.login, :code => user.register_code)
  207. bd = body
  208. bd = bd.gsub('FIRST_NAME', user.first_name)
  209. bd = bd.gsub('LAST_NAME', user.last_name)
  210. bd = bd.gsub('CONFIRMATION_LINK', confirmation_link)
  211.  
  212. gs = GlobalSetting.inst
  213. from = gs.smaboo_email_sender
  214. bcc = if gs.smaboo_email_bcc.blank? then nil else gs.smaboo_email_bcc end
  215.  
  216. puts "Trying to send mail .."
  217. SmabooMailer.deliver_standard_mail(user.email, subject, bd, from, bcc)
  218. puts "Mail sent."
  219. end
  220. end
  221.  
  222.  
  223. private
  224. def init_vars
  225. @agent = User.find_by_id(params[:agent_id])
  226. return false if @agent.nil?
  227. @current_user_id = current_user_id
  228. @email_code = params[:email_code]
  229. @email = @email_address = params[:email].to_s
  230. #redirect_to '/' and return true if @agent.nil?
  231. @agent_name = @agent.full_name
  232. @channel = @agent.channel
  233. @why = params[:why]
  234. @poss = params[:poss]
  235. true
  236. end
  237.  
  238. end
Add Comment
Please, Sign In to add comment