Class: UsersController

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

Instance Method Summary collapse

Methods inherited from ApplicationController

#current_navable, #current_navable=, #current_user, #point_navigation_to, #redirect_www_subdomain, #set_locale

Instance Method Details

#autocomplete_titleObject



61
62
63
64
65
66
67
68
69
70
71
# File 'app/controllers/users_controller.rb', line 61

def autocomplete_title
  query = params[:term] if params[ :term ]
  query ||= params[ :query ] if params[ :query ]
  query ||= ""
  
  @users = User.where("CONCAT(first_name, ' ', last_name) LIKE ?", "%#{query}%")

  # render json: json_for_autocomplete(@users, :title)
  # render json: @users.to_json( :methods => [ :title ] )
  render json: @users.map(&:title)
end

#createObject



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'app/controllers/users_controller.rb', line 40

def create
  @user_params = user_params
  @basic_user_params = @user_params.select { |key, value| key.to_s.in? ['first_name', 'last_name', 'email', 'female', 'create_account'] }
  @basic_user_params[:first_name] ||= I18n.t(:first_name)
  @basic_user_params[:last_name] ||= I18n.t(:last_name)
  @user = User.create(@basic_user_params)
  if @user_params[:add_to_group]
    Group.find(@user_params[:add_to_group]).assign_user @user
    @user_params.except! :add_to_group
  end
  @user.update_attributes(@user_params)
  @user.fill_in_template_profile_information
  @user.send_welcome_email if @user.
  redirect_to @user
end

#forgot_passwordObject



73
74
75
76
77
78
# File 'app/controllers/users_controller.rb', line 73

def forgot_password
  authorize! :update, @user.
  @user..send_new_password
  flash[:notice] = I18n.t(:new_password_has_been_sent_to, user_name: @user.title)
  redirect_to :back
end

#indexObject



9
10
11
12
13
14
15
# File 'app/controllers/users_controller.rb', line 9

def index
  begin
    redirect_to group_path(Group.everyone)
  rescue
    raise "No basic groups are present, yet. Try `rake bootstrap:all`."
  end
end

#newObject



31
32
33
34
35
36
37
38
# File 'app/controllers/users_controller.rb', line 31

def new
  @user = User.new
  
  @parent_group = Group.find(params[:parent_id]) if params[:parent_type] == 'Group'
  @user.add_to_group = @parent_group.try(:id)
  @user.female = false
  @user.alias = params[:alias]
end

#showObject



17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'app/controllers/users_controller.rb', line 17

def show
  if current_user == @user
    current_user.update_last_seen_activity("sieht sich sein eigenes Profil an", @user)
  else
    current_user.try(:update_last_seen_activity, "sieht sich das Profil von #{@user.title} an", @user)
  end
  
  respond_to do |format|
    format.html # show.html.erb
                #format.json { render json: @profile.sections }  # TODO
  end
  metric_logger.log_event @user.attributes.merge({name: @user.name, title: @user.title}), type: :show_user
end

#updateObject



56
57
58
59
# File 'app/controllers/users_controller.rb', line 56

def update
  @user.update_attributes(user_params)
  respond_with @user
end