Class: UsersController

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

Overview

Fat Free CRM Copyright © 2008-2011 by Michael Dvorkin

This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details.

You should have received a copy of the GNU Affero General Public License along with this program. If not, see <www.gnu.org/licenses/>.


Instance Method Summary collapse

Methods inherited from ApplicationController

#auto_complete

Instance Method Details

#avatarObject

GET /users/1/avatar GET /users/1/avatar.xml AJAX




93
94
95
# File 'app/controllers/users_controller.rb', line 93

def avatar
  respond_with(@user)
end

#change_passwordObject

PUT /users/1/change_password PUT /users/1/change_password.xml AJAX




131
132
133
134
135
136
137
138
139
140
141
142
143
144
# File 'app/controllers/users_controller.rb', line 131

def change_password
  if @user.valid_password?(params[:current_password], true) || @user.password_hash.blank?
    unless params[:user][:password].blank?
      @user.update_attributes(params[:user])
      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.xml HTML




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

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

#destroyObject

DELETE /users/1 DELETE /users/1.xml HTML and AJAX (not directly exposed yet)




86
87
88
# File 'app/controllers/users_controller.rb', line 86

def destroy
  # not exposed
end

#editObject

GET /users/1/edit AJAX




52
53
54
# File 'app/controllers/users_controller.rb', line 52

def edit
  respond_with(@user)
end

#newObject

GET /users/new GET /users/new.json GET /users/new.xml HTML




42
43
44
45
46
47
48
# File 'app/controllers/users_controller.rb', line 42

def new
  if can_signup?
    respond_with(@user)
  else
    redirect_to 
  end
end

#passwordObject

GET /users/1/password GET /users/1/password.xml AJAX




124
125
126
# File 'app/controllers/users_controller.rb', line 124

def password
  respond_with(@user)
end

#redrawObject

POST /users/1/redraw AJAX




148
149
150
151
# File 'app/controllers/users_controller.rb', line 148

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.json GET /users/1.xml HTML




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

def show
  respond_with(@user)
end

#updateObject

PUT /users/1 PUT /users/1.json PUT /users/1.xml AJAX




77
78
79
80
81
# File 'app/controllers/users_controller.rb', line 77

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

  respond_with(@user)
end

#upload_avatarObject

PUT /users/1/upload_avatar PUT /users/1/upload_avatar.xml AJAX




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

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