Guest User

Untitled

a guest
Feb 21st, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.52 KB | None | 0 0
  1. class AccountController < ApplicationController
  2.  
  3. include MobileMessagingSupport
  4.  
  5. skip_before_filter :check_user, :only => [:forgot_password, :send_forgot_password_email, :reset_password, :new_password, :confirm_new_email]
  6.  
  7. layout 'base'
  8.  
  9. def account
  10. find_user
  11. @page_title = 'Account Management'
  12. @guide = 'Here you can manage your Account settings.'
  13. end
  14.  
  15. def forgot_password
  16.  
  17. inauthenticate
  18. @page_title = 'So, you forgot your Password . . .'
  19. @guide = 'No worries, you will be back on FlowMingle in no time.'
  20.  
  21. end
  22.  
  23. def send_forgot_password_email
  24.  
  25. user = User.find_by_email(params[:email]) if !params[:email].blank?
  26. if user
  27. user.update_attribute(:forgot_password_hash, user.confirmation_hash_maker(user.email))
  28. WaitingMail.create(:mail => MessageMaker.create_forgot_password(user, user.forgot_password_hash))
  29. render :update do |page|
  30. page.replace_html 'forgot_password', %Q{<h2>We sent you an email at <span class="comment">#{user.email}</span></h2><h3>Follow the link in the email to reset your Password.</h3>}
  31. end
  32. else
  33. if !params[:email].blank?
  34. render :update do |page|
  35. page.replace_html :email_error, '<p>We do not recognize this Email Address.</p> <p>Please make sure you typed it correctly.</p> <p>Also, you must be a FlowMingle member to reset your Password.</p>'
  36. end
  37. else
  38. render :nothing => true
  39. end
  40. end
  41.  
  42. end
  43.  
  44. def reset_password
  45.  
  46. inauthenticate
  47. @page_title = 'Create Your New Password'
  48. @guide = 'Create a New Password (that you, hopefully, will not forget).'
  49. session[:forgot_password_hash] = params[:hash]
  50.  
  51. end
  52.  
  53. def new_password
  54.  
  55. @user = User.find_by_forgot_password_hash(session[:forgot_password_hash])
  56. if @user
  57. @user.password_entry = params[:user][:password_entry]
  58. @user.password_entry_confirmation = params[:user][:password_entry_confirmation]
  59. @user.validate_new_password
  60. if @user.errors.empty?
  61. @user.update_attributes(:password => params[:user][:password_entry], :forgot_password_hash => '')
  62. @status = 'success'
  63. render :update do |page|
  64. page.replace_html :resetPassword, :partial => 'new_password_status'
  65. end
  66. else
  67. render :update do |page|
  68. page.replace_html :resetPassword, :partial => 'new_password'
  69. end
  70. end
  71. else
  72. @status = 'fail'
  73. render :update do |page|
  74. page.replace_html :resetPassword, :partial => 'new_password_status'
  75. end
  76. end
  77. end
  78.  
  79. def show_available_credits
  80. render :update do |page|
  81. page.replace_html :availableCreditsContainer, :partial => 'available_credits'
  82. page << "$('toggleAvailableCredits').toggleClassName('toggleOpen')"
  83. page.visual_effect :toggle_blind, :availableCreditsContainer, :duration => 0.3
  84. end
  85. end
  86.  
  87. def show_billing_info
  88. render :update do |page|
  89. page.replace_html :billingInfoContainer, :partial => 'billing_info'
  90. page << "$('toggleBillingInfo').toggleClassName('toggleOpen')"
  91. page.visual_effect :toggle_blind, :billingInfoContainer, :duration => 0.3
  92. end
  93. end
  94.  
  95. def show_add_payment_method
  96. render :update do |page|
  97. page.replace_html :addCardContainer, :partial => 'store/add_card'
  98. end
  99. end
  100.  
  101. def show_change_password
  102. render :update do |page|
  103. page.replace_html :changePasswordContainer, :partial => 'change_password'
  104. page.visual_effect :toggle_blind, :changePasswordContainer, :duration => 0.3
  105. page << "$('toggleChangePassword').toggleClassName('toggleOpen')"
  106. end
  107. end
  108.  
  109. def show_change_email
  110. render :update do |page|
  111. page.replace_html :changeEmailContainer, :partial => 'change_email'
  112. page.visual_effect :toggle_blind, :changeEmailContainer, :duration => 0.3
  113. page << "$('toggleChangeEmail').toggleClassName('toggleOpen')"
  114. end
  115. end
  116.  
  117. def show_change_mobile
  118. @mobile = MobileProfile.find(:first, :conditions => ["user_id = ?", session[:user_id]])
  119. render :update do |page|
  120. page.replace_html :changeMobileContainer, :partial => 'shared/change_mobile'
  121. page.visual_effect :toggle_blind, :changeMobileContainer, :duration => 0.3
  122. page << "$('toggleChangeMobile').toggleClassName('toggleOpen')"
  123. end
  124. end
  125.  
  126. def show_update_demographic
  127. @user = User.find(session[:user_id])#, :include => :demographic)
  128. @demographic = Demographic.find(:first, :conditions => ["user_id = #{session[:user_id]}"])
  129. render :update do |page|
  130. page.replace_html :updateDemographicContainer, :partial => 'update_demographic'
  131. page.visual_effect :toggle_blind, :updateDemographicContainer, :duration => 0.3
  132. page << "$('toggleUpdateDemographic').toggleClassName('toggleOpen')"
  133. end
  134. end
  135.  
  136. def show_decommission_account
  137. render :update do |page|
  138. page.replace_html :decommissionAccountContainer, :partial => 'decommission_account'
  139. page.visual_effect :toggle_blind, :decommissionAccountContainer, :duration => 0.3
  140. page << "$('toggleDecommissionAccount').toggleClassName('toggleOpen')"
  141. end
  142. end
  143.  
  144. def cancel_change_mobile
  145.  
  146. render :update do |page|
  147. page['changeMobileContainer'].visual_effect :slideUp, :duration => 0.3
  148. page << "$('toggleChangeMobile').removeClassName('toggleOpen')"
  149. end
  150.  
  151. end
  152.  
  153. def change_password
  154.  
  155. @user = User.find(session[:user_id])
  156. @user.current_password = params[:user][:current_password]
  157. @user.password_entry = params[:user][:password_entry]
  158. @user.password_entry_confirmation = params[:user][:password_entry_confirmation]
  159. @user.current_password_correct?
  160. @user.validate_new_password
  161. if @user.errors.empty?
  162. @user.update_attribute(:password, params[:user][:password_entry])
  163. render :update do |page|
  164. page.show :changePasswordSuccess
  165. page.replace_html :changePasswordSuccess, "Password changed!"
  166. page[:changePasswordSuccess].visual_effect :highlight, :startcolor => '#fcff80', :duration => 2
  167. page << "$('toggleChangePassword').removeClassName('toggleOpen')"
  168. page['changePasswordContainer'].visual_effect :slideUp, :duration => 0.3
  169. end
  170. else
  171. render :update do |page|
  172. page.replace_html :changePasswordContainer, :partial => 'change_password'
  173. end
  174. end
  175. end
  176.  
  177. def change_email
  178.  
  179. @user = User.find(session[:user_id])
  180. @user.current_password = params[:user][:current_password]
  181. @user.new_email = params[:user][:new_email]
  182. @user.new_email_confirmation = params[:user][:new_email_confirmation]
  183. @user.new_email_confirmation.strip!
  184. @user.new_email_confirmation.chomp!
  185. @user.current_password_correct?
  186. @user.validate_email('new_email')
  187. if @user.errors.empty?
  188. # @user.new_email.strip!
  189. # @user.new_email.chomp!
  190. @user.new_email_hash = @user.confirmation_hash_maker(@user.new_email)
  191. WaitingMail.create(:mail => MessageMaker.create_change_email(@user, @user.new_email_hash))
  192. @user.save
  193. render :update do |page|
  194. page.show :changeEmailSuccess
  195. page.replace_html :changeEmailSuccess, %Q{Your Email will not be changed until you validate the new address. Instructions for how to validate your new email address have been sent to you at <span class="comment">#{@user.new_email}</span>.}
  196. page[:changeEmailSuccess].visual_effect :highlight, :startcolor => '#fcff80', :duration => 2
  197. page << "$('toggleChangeEmail').removeClassName('toggleOpen')"
  198. page['changeEmailContainer'].visual_effect :slideUp, :duration => 0.3
  199. end
  200. else
  201. render :update do |page|
  202. page.replace_html :changeEmailContainer, :partial => 'change_email'
  203. end
  204. end
  205.  
  206. end
  207.  
  208. def confirm_new_email
  209.  
  210. @page_title = "Confirm your New Email Address"
  211. @user = User.find_by_new_email_hash(params[:hash])
  212. direct_access(@user.id) if @user
  213. if @user && User.find(:all, :conditions => ["email = :email && confirmed = TRUE", {:email => @user.new_email}]).empty?
  214. @user.email = @user.new_email
  215. @user.new_email = ''
  216. @user.new_email_hash = ''
  217. @user.confirmed = true
  218. @user.save
  219. @status = 'changed'
  220. @guide = "Congrats on changing your Email Address."
  221. else
  222. @guide = 'Oops! There is an error.'
  223. @status = 'failed'
  224. end
  225.  
  226. end
  227.  
  228. def save_demographic
  229.  
  230. @user = User.find(session[:user_id])#, :include => :demographic)
  231. @user.first_name = params[:user][:first_name]
  232. @user.last_name = params[:user][:last_name]
  233. @user.current_password = params[:user][:current_password]
  234. @demographic = Demographic.find(:first, :conditions => ["user_id = #{session[:user_id]}"])
  235. @demographic.zip = params[:demographic][:zip]
  236. @demographic.dob = Date.new(params[:demographic]["dob(1i)".to_sym].to_i, 1, 1)
  237. @demographic.gender = params[:demographic][:gender]
  238. @demographic.date_preference = params[:demographic][:date_preference]
  239. @demographic.ethnicity = params[:demographic][:ethnicity]
  240. @demographic.religion = params[:demographic][:religion]
  241. @demographic.smoke = params[:demographic][:smoke]
  242. @demographic.divorced = params[:demographic][:divorced]
  243. @demographic.have_kids = params[:demographic][:have_kids]
  244. if @user.current_password_correct?
  245. @demographic.valid?
  246. if @user.valid? && @demographic.valid?
  247. @demographic.save
  248. @user.save
  249. render :update do |page|
  250. page.show :updateDemographicSuccess
  251. page.replace_html :updateDemographicSuccess, "Your information has been updated!"
  252. page[:updateDemographicSuccess].visual_effect :highlight, :startcolor => '#fcff80', :duration => 2
  253. page << "$('toggleUpdateDemographic').removeClassName('toggleOpen')"
  254. page['updateDemographicContainer'].visual_effect :slideUp, :duration => 0.3
  255. end
  256. else
  257. render :update do |page|
  258. page.replace_html :updateDemographicContainer, :partial => 'update_demographic'
  259. end
  260. end
  261. else
  262. render :update do |page|
  263. page.replace_html :updateDemographicContainer, :partial => 'update_demographic'
  264. end
  265. end
  266.  
  267. end
  268.  
  269. def decommission_account
  270. #:current_password, :reason
  271. #if someone wants to delete their account or leave JD, not likely though :)
  272. render :update do |page|
  273. page.show :decommissionAccountSuccess
  274. page.replace_html :decommissionAccountSuccess, "Now you've done it. You've gone and made me cry"
  275. page[:decommissionAccountSuccess].visual_effect :highlight, :startcolor => '#fcff80', :duration => 2
  276. page << "$('toggleDecommissionAccount').removeClassName('toggleOpen')"
  277. page['decommissionAccountContainer'].visual_effect :slideUp, :duration => 0.3
  278. end
  279. end
  280.  
  281. end
Add Comment
Please, Sign In to add comment