[Refs #257] Fix password change, refactoring.
This commit is contained in:
parent
73296059eb
commit
91ba8b1543
|
@ -1,7 +1,6 @@
|
|||
# -*- encoding : utf-8 -*-
|
||||
class UsersController < ApplicationController
|
||||
before_filter :authenticate_user!
|
||||
before_filter :find_user, :only => [:show, :edit, :update, :destroy, :private]
|
||||
|
||||
load_and_authorize_resource
|
||||
autocomplete :user, :uname
|
||||
|
@ -19,7 +18,6 @@ class UsersController < ApplicationController
|
|||
def show
|
||||
@groups = @user.groups.uniq
|
||||
@platforms = @user.platforms.paginate(:page => params[:platform_page], :per_page => 10)
|
||||
# @repositories = @user.repositories.paginate(:page => params[:repository_page], :per_page => 10)
|
||||
@projects = @user.projects.paginate(:page => params[:project_page], :per_page => 10)
|
||||
end
|
||||
|
||||
|
@ -42,8 +40,11 @@ class UsersController < ApplicationController
|
|||
end
|
||||
|
||||
def update
|
||||
@user.role = params[:user][:role] if params[:user][:role] && current_user.admin?
|
||||
if @user.update_attributes(params[:user])
|
||||
if params[:user][:role] && current_user.admin?
|
||||
@user.role = params[:user][:role]
|
||||
params[:user].delete(:role)
|
||||
end
|
||||
if @user.update_without_password(params[:user])
|
||||
flash[:notice] = t('flash.user.saved')
|
||||
redirect_to edit_user_path(@user)
|
||||
else
|
||||
|
@ -54,7 +55,7 @@ class UsersController < ApplicationController
|
|||
|
||||
def private
|
||||
if request.put?
|
||||
if @user.update_attributes(params[:user])
|
||||
if @user.update_with_password(params[:user])
|
||||
flash[:notice] = t('flash.user.saved')
|
||||
redirect_to user_private_settings_path(@user)
|
||||
else
|
||||
|
@ -70,9 +71,4 @@ class UsersController < ApplicationController
|
|||
redirect_to users_path
|
||||
end
|
||||
|
||||
protected
|
||||
|
||||
def find_user
|
||||
@user = User.find(params[:id])
|
||||
end
|
||||
end
|
||||
|
|
|
@ -35,9 +35,7 @@ class User < ActiveRecord::Base
|
|||
validate { errors.add(:uname, :taken) if Group.where('uname LIKE ?', uname).present? }
|
||||
validates :role, :inclusion => {:in => ROLES}, :allow_blank => true
|
||||
validates :language, :inclusion => {:in => LANGUAGES}, :allow_blank => true
|
||||
validates_confirmation_of :password
|
||||
|
||||
attr_accessor :password, :password_confirmation, :current_password
|
||||
attr_accessible :email, :password, :password_confirmation, :current_password, :remember_me, :login, :name, :ssh_key, :uname, :language,
|
||||
:site, :company, :professional_experience, :location, :avatar
|
||||
attr_readonly :uname, :own_projects_count
|
||||
|
@ -83,17 +81,17 @@ class User < ActiveRecord::Base
|
|||
end
|
||||
end
|
||||
|
||||
def update_with_password(params={})
|
||||
params.delete(:current_password)
|
||||
# self.update_without_password(params) # Don't allow password update
|
||||
if params[:password].blank?
|
||||
params.delete(:password)
|
||||
params.delete(:password_confirmation) if params[:password_confirmation].blank?
|
||||
end
|
||||
result = update_attributes(params)
|
||||
clean_up_passwords
|
||||
result
|
||||
end
|
||||
# def update_with_password(params={})
|
||||
# params.delete(:current_password)
|
||||
# # self.update_without_password(params) # Don't allow password update
|
||||
# if params[:password].blank?
|
||||
# params.delete(:password)
|
||||
# params.delete(:password_confirmation) if params[:password_confirmation].blank?
|
||||
# end
|
||||
# result = update_attributes(params)
|
||||
# clean_up_passwords
|
||||
# result
|
||||
# end
|
||||
|
||||
def commentor?(commentable)
|
||||
comments.exists?(:commentable_type => commentable.class.name, :commentable_id => commentable.id.hex)
|
||||
|
|
Loading…
Reference in New Issue