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




64
65
66
# File 'app/controllers/users_controller.rb', line 64

def avatar
  respond_with(@user)
end

#change_passwordObject

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




102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
# File 'app/controllers/users_controller.rb', line 102

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

  respond_with(@user)
end

#createObject

POST /users POST /users.js




33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'app/controllers/users_controller.rb', line 33

def create
  if @user.save
    if Setting. == :needs_approval
      flash[:notice] = t(:msg_account_created)
      redirect_to 
    else
      flash[:notice] = t(:msg_successful_signup)
      redirect_back_or_default profile_url
    end
  else
    render :new
  end
end

#editObject

GET /users/1/edit.js




49
50
51
# File 'app/controllers/users_controller.rb', line 49

def edit
  respond_with(@user)
end

#newObject

GET /users/new GET /users/new.js




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

def new
  respond_with(@user)
end

#opportunities_overviewObject

GET /users/opportunities_overview




128
129
130
131
# File 'app/controllers/users_controller.rb', line 128

def opportunities_overview
  @users_with_opportunities = User.have_assigned_opportunities.order(:first_name)
  @unassigned_opportunities = Opportunity.unassigned.pipeline.order(:stage)
end

#passwordObject

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




95
96
97
# File 'app/controllers/users_controller.rb', line 95

def password
  respond_with(@user)
end

#redrawObject

POST /users/1/redraw




121
122
123
124
# File 'app/controllers/users_controller.rb', line 121

def redraw
  current_user.preference[:locale] = params[:locale]
  render(:update) { |page| page.redirect_to user_path(current_user) }
end

#showObject

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




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

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

#updateObject

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




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

def update
  @user.update_attributes(params[:user])
  respond_with(@user)
end

#upload_avatarObject

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




71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
# File 'app/controllers/users_controller.rb', line 71

def upload_avatar
  if params[:gravatar]
    @user.avatar = nil
    @user.save
    render
  else
    if params[:avatar]
      @user.avatar = Avatar.new(params[:avatar].merge(:entity => @user))
      unless @user.save && @user.avatar.errors.blank?
        @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 and (return if Rails.env.test?)
    end
  end
end