Class: UsersController

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

Overview

Copyright © 2008-2013 Michael Dvorkin and contributors.

Fat Free CRM is freely distributable under the terms of MIT license. See MIT-LICENSE file or www.opensource.org/licenses/mit-license.php


Instance Method Summary collapse

Methods inherited from ApplicationController

#auto_complete

Instance Method Details

#avatarObject

GET /users/1/avatar GET /users/1/avatar.js




43
44
45
# File 'app/controllers/users_controller.rb', line 43

def avatar
  respond_with(@user)
end

#change_passwordObject

PUT /users/1/change_password PUT /users/1/change_password.js




83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
# File 'app/controllers/users_controller.rb', line 83

def change_password
  if @user.valid_password?(params[:current_password])
    if params[:user][:password].blank?
      flash[:notice] = t(:msg_password_not_changed)
    else
      @user.password = params[:user][:password]
      @user.password_confirmation = params[:user][:password_confirmation]
      @user.save
      flash[:notice] = t(:msg_password_changed)
    end
  else
    @user.errors.add(:current_password, t(:msg_invalid_password))
  end

  respond_with(@user)
end

#editObject

GET /users/1/edit.js




27
28
29
# File 'app/controllers/users_controller.rb', line 27

def edit
  respond_with(@user)
end

#opportunities_overviewObject

GET /users/opportunities_overview




109
110
111
112
# File 'app/controllers/users_controller.rb', line 109

def opportunities_overview
  @users_with_opportunities = User.have_assigned_opportunities.order(:first_name)
  @unassigned_opportunities = Opportunity.my(current_user).unassigned.pipeline.order(:stage).includes(:account, :user, :tags)
end

#passwordObject

GET /users/1/password GET /users/1/password.js




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

def password
  respond_with(@user)
end

#redrawObject

GET /users/1/redraw




102
103
104
105
# File 'app/controllers/users_controller.rb', line 102

def redraw
  current_user.preference[:locale] = params[:locale]
  render js: %(window.location.href = "#{user_path(current_user)}";)
end

#showObject

GET /users/1 GET /users/1.js




20
21
22
23
# File 'app/controllers/users_controller.rb', line 20

def show
  @user = current_user if params[:id].nil?
  respond_with(@user)
end

#updateObject

PUT /users/1 PUT /users/1.js




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

def update
  @user.update(user_params)
  flash[:notice] = t(:msg_user_updated)
  respond_with(@user)
end

#upload_avatarObject

PUT /users/1/upload_avatar PUT /users/1/upload_avatar.js




50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'app/controllers/users_controller.rb', line 50

def upload_avatar
  if params[:gravatar]
    @user.avatar = nil
    @user.save
    render
  else
    if params[:avatar]
      @avatar = Avatar.create(avatar_params)
      if @avatar.valid?
        @user.avatar = @avatar
      else
        @user.avatar.errors.clear
        @user.avatar.errors.add(:image, t(:msg_bad_image_file))
      end
    end
    responds_to_parent do
      # Without return RSpec2 screams bloody murder about rendering twice:
      # within the block and after yield in responds_to_parent.
      render && (return if Rails.env.test?)
    end
  end
end