Class: Caboose::MyAccountController

Inherits:
ApplicationController show all
Defined in:
app/controllers/caboose/my_account_controller.rb

Instance Method Summary collapse

Methods inherited from ApplicationController

#add_ga_event, #admin_add, #admin_bulk_add, #admin_bulk_delete, #admin_bulk_update, #admin_delete, #admin_edit, #admin_index, #admin_json, #admin_json_single, #admin_update, #before_action, #before_before_action, #hashify_query_string, #init_cart, #logged_in?, #logged_in_user, #login_user, #logout_user, #parse_url_params, #reject_param, #under_construction_or_forwarding_domain?, #user_is_allowed, #user_is_allowed_to, #validate_cookie, #validate_token, #var, #verify_logged_in

Instance Method Details

#indexObject


5
6
7
8
# File 'app/controllers/caboose/my_account_controller.rb', line 5

def index
  return if !verify_logged_in
  @user = logged_in_user      
end

#updateObject


11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'app/controllers/caboose/my_account_controller.rb', line 11

def update  
  return if !logged_in?
  
  resp = StdClass.new     
  user = logged_in_user

  save = true
  params.each do |name,value|
    case name
	  	when "first_name" then user.first_name  = value
	  	when "last_name"  then user.last_name   = value
	  	when "username"
        uname = value.strip.downcase
        if uname.length < 3
          resp.error = "Username must be at least three characters."
        elsif Caboose::User.where(:username => uname, :site_id => @site.id).where('id != ?',user.id).exists?
          resp.error = "That username is already taken."
        elsif uname == 'superadmin'
          resp.error = "Choose a different username."
        else
          user.username = uname
        end
	  	when "email"
        email = value.strip.downcase
        if !email.include?('@')
          resp.error = "Invalid email address."
        elsif Caboose::User.where(:email => email, :site_id => @site.id).where('id != ?',user.id).exists?
          resp.error = "That email address is already in the system."
        else
          user.email = email
        end
	  	when "phone"      then user.phone = value

      when "address"  then user.address   = value
      when "address2"  then user.address2   = value
      when "city"  then user.city   = value
      when "state"  then user.state   = value
      when "zip"  then user.zip   = value
      when "customer_profile_id"  then user.customer_profile_id   = value
      when "payment_profile_id"  then user.payment_profile_id   = value
      when "stripe_customer_id"  then user.stripe_customer_id   = value
      when "fax"  then user.fax   = value

	  	when "password"			  
	  	  confirm = params[:confirm]
	  		if value != confirm			
	  		  resp.error = "Passwords do not match.";
	  		  save = false
	  		elsif value.length < 8
	  		  resp.error = "Passwords must be at least 8 characters.";
	  		  save = false
	  		else
	  		  user.password = Digest::SHA1.hexdigest(Caboose::salt + value)
	  		end    	  	    		  
	  end
	end
	
	resp.success = save && user.save
	render :json => resp
end