Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class AccountController < ApplicationController
- include MobileMessagingSupport
- skip_before_filter :check_user, :only => [:forgot_password, :send_forgot_password_email, :reset_password, :new_password, :confirm_new_email]
- layout 'base'
- def account
- find_user
- @page_title = 'Account Management'
- @guide = 'Here you can manage your Account settings.'
- end
- def forgot_password
- inauthenticate
- @page_title = 'So, you forgot your Password . . .'
- @guide = 'No worries, you will be back on FlowMingle in no time.'
- end
- def send_forgot_password_email
- user = User.find_by_email(params[:email]) if !params[:email].blank?
- if user
- user.update_attribute(:forgot_password_hash, user.confirmation_hash_maker(user.email))
- WaitingMail.create(:mail => MessageMaker.create_forgot_password(user, user.forgot_password_hash))
- render :update do |page|
- 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>}
- end
- else
- if !params[:email].blank?
- render :update do |page|
- 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>'
- end
- else
- render :nothing => true
- end
- end
- end
- def reset_password
- inauthenticate
- @page_title = 'Create Your New Password'
- @guide = 'Create a New Password (that you, hopefully, will not forget).'
- session[:forgot_password_hash] = params[:hash]
- end
- def new_password
- @user = User.find_by_forgot_password_hash(session[:forgot_password_hash])
- if @user
- @user.password_entry = params[:user][:password_entry]
- @user.password_entry_confirmation = params[:user][:password_entry_confirmation]
- @user.validate_new_password
- if @user.errors.empty?
- @user.update_attributes(:password => params[:user][:password_entry], :forgot_password_hash => '')
- @status = 'success'
- render :update do |page|
- page.replace_html :resetPassword, :partial => 'new_password_status'
- end
- else
- render :update do |page|
- page.replace_html :resetPassword, :partial => 'new_password'
- end
- end
- else
- @status = 'fail'
- render :update do |page|
- page.replace_html :resetPassword, :partial => 'new_password_status'
- end
- end
- end
- def show_available_credits
- render :update do |page|
- page.replace_html :availableCreditsContainer, :partial => 'available_credits'
- page << "$('toggleAvailableCredits').toggleClassName('toggleOpen')"
- page.visual_effect :toggle_blind, :availableCreditsContainer, :duration => 0.3
- end
- end
- def show_billing_info
- render :update do |page|
- page.replace_html :billingInfoContainer, :partial => 'billing_info'
- page << "$('toggleBillingInfo').toggleClassName('toggleOpen')"
- page.visual_effect :toggle_blind, :billingInfoContainer, :duration => 0.3
- end
- end
- def show_add_payment_method
- render :update do |page|
- page.replace_html :addCardContainer, :partial => 'store/add_card'
- end
- end
- def show_change_password
- render :update do |page|
- page.replace_html :changePasswordContainer, :partial => 'change_password'
- page.visual_effect :toggle_blind, :changePasswordContainer, :duration => 0.3
- page << "$('toggleChangePassword').toggleClassName('toggleOpen')"
- end
- end
- def show_change_email
- render :update do |page|
- page.replace_html :changeEmailContainer, :partial => 'change_email'
- page.visual_effect :toggle_blind, :changeEmailContainer, :duration => 0.3
- page << "$('toggleChangeEmail').toggleClassName('toggleOpen')"
- end
- end
- def show_change_mobile
- @mobile = MobileProfile.find(:first, :conditions => ["user_id = ?", session[:user_id]])
- render :update do |page|
- page.replace_html :changeMobileContainer, :partial => 'shared/change_mobile'
- page.visual_effect :toggle_blind, :changeMobileContainer, :duration => 0.3
- page << "$('toggleChangeMobile').toggleClassName('toggleOpen')"
- end
- end
- def show_update_demographic
- @user = User.find(session[:user_id])#, :include => :demographic)
- @demographic = Demographic.find(:first, :conditions => ["user_id = #{session[:user_id]}"])
- render :update do |page|
- page.replace_html :updateDemographicContainer, :partial => 'update_demographic'
- page.visual_effect :toggle_blind, :updateDemographicContainer, :duration => 0.3
- page << "$('toggleUpdateDemographic').toggleClassName('toggleOpen')"
- end
- end
- def show_decommission_account
- render :update do |page|
- page.replace_html :decommissionAccountContainer, :partial => 'decommission_account'
- page.visual_effect :toggle_blind, :decommissionAccountContainer, :duration => 0.3
- page << "$('toggleDecommissionAccount').toggleClassName('toggleOpen')"
- end
- end
- def cancel_change_mobile
- render :update do |page|
- page['changeMobileContainer'].visual_effect :slideUp, :duration => 0.3
- page << "$('toggleChangeMobile').removeClassName('toggleOpen')"
- end
- end
- def change_password
- @user = User.find(session[:user_id])
- @user.current_password = params[:user][:current_password]
- @user.password_entry = params[:user][:password_entry]
- @user.password_entry_confirmation = params[:user][:password_entry_confirmation]
- @user.current_password_correct?
- @user.validate_new_password
- if @user.errors.empty?
- @user.update_attribute(:password, params[:user][:password_entry])
- render :update do |page|
- page.show :changePasswordSuccess
- page.replace_html :changePasswordSuccess, "Password changed!"
- page[:changePasswordSuccess].visual_effect :highlight, :startcolor => '#fcff80', :duration => 2
- page << "$('toggleChangePassword').removeClassName('toggleOpen')"
- page['changePasswordContainer'].visual_effect :slideUp, :duration => 0.3
- end
- else
- render :update do |page|
- page.replace_html :changePasswordContainer, :partial => 'change_password'
- end
- end
- end
- def change_email
- @user = User.find(session[:user_id])
- @user.current_password = params[:user][:current_password]
- @user.new_email = params[:user][:new_email]
- @user.new_email_confirmation = params[:user][:new_email_confirmation]
- @user.new_email_confirmation.strip!
- @user.new_email_confirmation.chomp!
- @user.current_password_correct?
- @user.validate_email('new_email')
- if @user.errors.empty?
- # @user.new_email.strip!
- # @user.new_email.chomp!
- @user.new_email_hash = @user.confirmation_hash_maker(@user.new_email)
- WaitingMail.create(:mail => MessageMaker.create_change_email(@user, @user.new_email_hash))
- @user.save
- render :update do |page|
- page.show :changeEmailSuccess
- 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>.}
- page[:changeEmailSuccess].visual_effect :highlight, :startcolor => '#fcff80', :duration => 2
- page << "$('toggleChangeEmail').removeClassName('toggleOpen')"
- page['changeEmailContainer'].visual_effect :slideUp, :duration => 0.3
- end
- else
- render :update do |page|
- page.replace_html :changeEmailContainer, :partial => 'change_email'
- end
- end
- end
- def confirm_new_email
- @page_title = "Confirm your New Email Address"
- @user = User.find_by_new_email_hash(params[:hash])
- direct_access(@user.id) if @user
- if @user && User.find(:all, :conditions => ["email = :email && confirmed = TRUE", {:email => @user.new_email}]).empty?
- @user.email = @user.new_email
- @user.new_email = ''
- @user.new_email_hash = ''
- @user.confirmed = true
- @user.save
- @status = 'changed'
- @guide = "Congrats on changing your Email Address."
- else
- @guide = 'Oops! There is an error.'
- @status = 'failed'
- end
- end
- def save_demographic
- @user = User.find(session[:user_id])#, :include => :demographic)
- @user.first_name = params[:user][:first_name]
- @user.last_name = params[:user][:last_name]
- @user.current_password = params[:user][:current_password]
- @demographic = Demographic.find(:first, :conditions => ["user_id = #{session[:user_id]}"])
- @demographic.zip = params[:demographic][:zip]
- @demographic.dob = Date.new(params[:demographic]["dob(1i)".to_sym].to_i, 1, 1)
- @demographic.gender = params[:demographic][:gender]
- @demographic.date_preference = params[:demographic][:date_preference]
- @demographic.ethnicity = params[:demographic][:ethnicity]
- @demographic.religion = params[:demographic][:religion]
- @demographic.smoke = params[:demographic][:smoke]
- @demographic.divorced = params[:demographic][:divorced]
- @demographic.have_kids = params[:demographic][:have_kids]
- if @user.current_password_correct?
- @demographic.valid?
- if @user.valid? && @demographic.valid?
- @demographic.save
- @user.save
- render :update do |page|
- page.show :updateDemographicSuccess
- page.replace_html :updateDemographicSuccess, "Your information has been updated!"
- page[:updateDemographicSuccess].visual_effect :highlight, :startcolor => '#fcff80', :duration => 2
- page << "$('toggleUpdateDemographic').removeClassName('toggleOpen')"
- page['updateDemographicContainer'].visual_effect :slideUp, :duration => 0.3
- end
- else
- render :update do |page|
- page.replace_html :updateDemographicContainer, :partial => 'update_demographic'
- end
- end
- else
- render :update do |page|
- page.replace_html :updateDemographicContainer, :partial => 'update_demographic'
- end
- end
- end
- def decommission_account
- #:current_password, :reason
- #if someone wants to delete their account or leave JD, not likely though :)
- render :update do |page|
- page.show :decommissionAccountSuccess
- page.replace_html :decommissionAccountSuccess, "Now you've done it. You've gone and made me cry"
- page[:decommissionAccountSuccess].visual_effect :highlight, :startcolor => '#fcff80', :duration => 2
- page << "$('toggleDecommissionAccount').removeClassName('toggleOpen')"
- page['decommissionAccountContainer'].visual_effect :slideUp, :duration => 0.3
- end
- end
- end
Add Comment
Please, Sign In to add comment