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

GET /my-account



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

PUT /my-account



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
# 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"   then user.username    = value
	  	when "email"      then user.email       = value
	  	when "phone"      then user.phone       = 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