Class: UserController

Inherits:
KitController show all
Defined in:
app/controllers/user_controller.rb

Constant Summary

Constants inherited from KitController

KitController::Pagebase

Instance Attribute Summary

Attributes inherited from KitController

#is_image_request, #kit_request, #layout_being_used, #requested_url, #template_being_used

Instance Method Summary collapse

Methods inherited from KitController

#anti_spam_okay?, #app_name, #can_moderate, #can_use, #captcha_okay?, #check_and_record_goal, #check_user, #csv_headers, #dif, #edit_page_path, #feature?, #get_asset, #get_view_content, #host_name, #index_name, #info_page_path, #kit_layout_in_use, #kit_render, #kit_session, #kit_session_end, #link_to, #mailchimp_connect, #mobile_template, #no_read, #no_write, #not_found, #not_found_404, #offline, #page_path, #pref, #rails_app_name, #render, #render_error, #render_page, #render_page_by_url, #routing_error, #sanity_check_okay?, #session_id, #set_requested_url, #show_form, #stylesheets, #super_render, #user_sees_menu?

Instance Method Details

#attributeObject



35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'app/controllers/user_controller.rb', line 35

def attribute
  @user = current_user

  uav = UserAttributeValue.find_or_initialize_by_user_id_and_user_attribute_id(@user.id, params[:id])
  uav.value = params[:user_attribute_value][:value]
  uav.updated_by = current_user
  uav.system_id = _sid
  uav.save
  @user.update_index
  Activity.add(_sid, "Set attribute '#{uav.user_attribute.name}' to '#{uav.value}' by '#{@user.email}'", current_user, "Users")

  respond_with_bip(uav)
end

#check_display_nameObject



113
114
115
116
117
118
119
120
121
122
123
124
125
# File 'app/controllers/user_controller.rb', line 113

def check_display_name
  name = params[:name]

  if (name.length<2)
    render :text=>"Too short"
  else
    if User.sys(_sid).where(:display_name=>name).count > 0
      render :text=>"Name in use"
    else
      render :text=> ""
    end
  end
end

#display_nameObject



104
105
106
107
108
109
110
111
# File 'app/controllers/user_controller.rb', line 104

def display_name
  current_user.display_name = params[:user][:display_name]
  if current_user.display_name.is_blank?
    current_user.display_name = nil
  end
  current_user.save!
  redirect_to request.referer
end

#edit_profileObject



25
26
27
28
29
30
31
32
33
# File 'app/controllers/user_controller.rb', line 25

def edit_profile
  form = Preference.get_cached(_sid, 'user_profile_edit_form')
  if form.not_blank?
    render :inline=>form, :layout=>profile_layout # Preference.get_cached!(0,"user_profile_layout", "application") #TODO sub in auth token
    return
  end

  render "edit_profile", :layout=>profile_layout
end

#preferencesObject



5
6
7
8
9
10
# File 'app/controllers/user_controller.rb', line 5

def preferences
  @page_title = 'Preferences'
  @user = current_user

  render "preferences", :layout=>profile_layout
end

#profileObject



12
13
14
15
16
# File 'app/controllers/user_controller.rb', line 12

def profile
  @page_title = "Your Profile"
  @user = current_user
  show_profile(true)
end

#remove_profile_attributeObject



49
50
51
52
53
# File 'app/controllers/user_controller.rb', line 49

def remove_profile_attribute

  UserAttributeValue.delete_all(["user_id = #{current_user.id} and user_attribute_id = ?", params[:id]])
  redirect_to "/user/profile"
end

#updateObject



55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# File 'app/controllers/user_controller.rb', line 55

def update
  @user = current_user
  @errors = {}
  at_least_one = false
  all_okay = true

  UserAttribute.sys(_sid).where("owner_visible = 1").each do |ua|
    if val = params[ua.code_name.to_sym]
      if (ua.form_field_type.has_asset? && val) || (!ua.form_field_type.has_asset?)
        uav = UserAttributeValue.where(:user_id=>@user.id).where(:user_attribute_id=>ua.id).first
        unless uav
          uav = UserAttributeValue.create(:user_id=>@user.id, :user_attribute_id=>ua.id)
        end

        if ua.form_field_type.has_asset?
          uav.asset = val
          uav.value = ''
        else
          uav.value = val
        end
        uav.updated_by = current_user.id
        if uav.save
          at_least_one = true
        else
          all_okay = false
        end
        Activity.add(_sid, "Set attribute '#{uav.user_attribute.name}' to '#{uav.value}' by '#{@user.email}'", current_user, "Users")
      else
        if ua.is_mandatory?
          @errors[ua.id] = {:message=>"You must enter a value for '#{ua.name}'", :field=>"field_#{ua.id}"}
          all_okay = false
        end
      end
    end
  end

  if at_least_one
    @user.update_index
  end

  if all_okay 
    flash[:info] = "Profile updated"
    redirect_to "/user/profile"
  else
    flash[:info] = "There were errors"
    render "user/edit_profile"
  end
end

#user_profileObject



18
19
20
21
22
# File 'app/controllers/user_controller.rb', line 18

def 
  @user = User.find_sys_id(_sid,params[:id])
  @page_title = "Profile for '#{@user.display_name || 'Anonymous User'}'"
  show_profile(false)
end