intended to remove some of the weirdness when updating a users account. A blank password basically ends up causing the previously existing password to be hashed twice. Probably move to has_secure_password at some point although that may end up screwing up the intent of the particular tutorial item
This commit is contained in:
@@ -33,9 +33,12 @@ class UsersController < ApplicationController
|
|||||||
|
|
||||||
user = User.find(:first, :conditions => "user_id = '#{params[:user][:user_id]}'")
|
user = User.find(:first, :conditions => "user_id = '#{params[:user][:user_id]}'")
|
||||||
user.skip_user_id_assign = true
|
user.skip_user_id_assign = true
|
||||||
|
user.skip_hash_password = true
|
||||||
user.update_attributes(params[:user].reject { |k| %w(password password_confirmation user_id).include? k })
|
user.update_attributes(params[:user].reject { |k| %w(password password_confirmation user_id).include? k })
|
||||||
pass = params[:user][:password]
|
if !(params[:user][:password].empty?) && (params[:user][:password] == params[:user][:password_confirmation])
|
||||||
user.password = pass if !(pass.blank?)
|
user.skip_hash_password = false
|
||||||
|
user.password = params[:user][:password]
|
||||||
|
end
|
||||||
message = true if user.save!
|
message = true if user.save!
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
format.html { redirect_to user_account_settings_path(:user_id => current_user.user_id) }
|
format.html { redirect_to user_account_settings_path(:user_id => current_user.user_id) }
|
||||||
|
|||||||
+9
-5
@@ -1,15 +1,16 @@
|
|||||||
class User < ActiveRecord::Base
|
class User < ActiveRecord::Base
|
||||||
attr_accessible :email, :password, :admin, :password_confirmation, :first_name, :last_name
|
attr_accessible :email, :admin, :first_name, :last_name, :user_id, :password, :password_confirmation
|
||||||
validates_confirmation_of :password, :password_confirmation, :on => :create
|
|
||||||
validates :password, :presence => true,
|
validates :password, :presence => true,
|
||||||
:confirmation => true,
|
:confirmation => true,
|
||||||
:length => {:within => 6..40},
|
:length => {:within => 6..40},
|
||||||
:on => :create#,
|
:on => :create,
|
||||||
|
:if => :password#,
|
||||||
#:format => {:with => /\A.*(?=.{10,})(?=.*\d)(?=.*[a-z])(?=.*[A-Z])(?=.*[\@\#\$\%\^\&\+\=]).*\z/}
|
#:format => {:with => /\A.*(?=.{10,})(?=.*\d)(?=.*[a-z])(?=.*[A-Z])(?=.*[\@\#\$\%\^\&\+\=]).*\z/}
|
||||||
validates_presence_of :email
|
validates_presence_of :email
|
||||||
validates_uniqueness_of :email
|
validates_uniqueness_of :email
|
||||||
validates_format_of :email, :with => /.+@.+\..+/i
|
validates_format_of :email, :with => /.+@.+\..+/i
|
||||||
attr_accessor :skip_user_id_assign
|
attr_accessor :skip_user_id_assign
|
||||||
|
attr_accessor :skip_hash_password
|
||||||
before_save :assign_user_id, :on => :create
|
before_save :assign_user_id, :on => :create
|
||||||
before_save :hash_password
|
before_save :hash_password
|
||||||
has_one :retirement, :foreign_key => :user_id, :primary_key => :user_id, :dependent => :destroy
|
has_one :retirement, :foreign_key => :user_id, :primary_key => :user_id, :dependent => :destroy
|
||||||
@@ -18,6 +19,7 @@ class User < ActiveRecord::Base
|
|||||||
has_many :performance, :foreign_key => :user_id, :primary_key => :user_id, :dependent => :destroy
|
has_many :performance, :foreign_key => :user_id, :primary_key => :user_id, :dependent => :destroy
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def build_benefits_data
|
def build_benefits_data
|
||||||
build_retirement(POPULATE_RETIREMENTS.shuffle.first)
|
build_retirement(POPULATE_RETIREMENTS.shuffle.first)
|
||||||
build_paid_time_off(POPULATE_PAID_TIME_OFF.shuffle.first).schedule.build(POPULATE_SCHEDULE.shuffle.first)
|
build_paid_time_off(POPULATE_PAID_TIME_OFF.shuffle.first).schedule.build(POPULATE_SCHEDULE.shuffle.first)
|
||||||
@@ -55,8 +57,10 @@ class User < ActiveRecord::Base
|
|||||||
end
|
end
|
||||||
|
|
||||||
def hash_password
|
def hash_password
|
||||||
if self.password.present?
|
unless @skip_hash_password == true
|
||||||
self.password = Digest::MD5.hexdigest(password)
|
if password.present?
|
||||||
|
self.password = Digest::MD5.hexdigest(password)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
+6
-1
@@ -7,6 +7,7 @@ users = [
|
|||||||
:email => "admin@metacorp.com",
|
:email => "admin@metacorp.com",
|
||||||
:admin => true,
|
:admin => true,
|
||||||
:password => "admin1234",
|
:password => "admin1234",
|
||||||
|
:password_confirmation => "admin1234",
|
||||||
:first_name => "Admin",
|
:first_name => "Admin",
|
||||||
:last_name => "",
|
:last_name => "",
|
||||||
:user_id =>1
|
:user_id =>1
|
||||||
@@ -15,6 +16,7 @@ users = [
|
|||||||
:email => "jack@metacorp.com",
|
:email => "jack@metacorp.com",
|
||||||
:admin => false,
|
:admin => false,
|
||||||
:password => "yankeessuck",
|
:password => "yankeessuck",
|
||||||
|
:password_confirmation => "yankeessuck",
|
||||||
:first_name => "Jack",
|
:first_name => "Jack",
|
||||||
:last_name => "Mannino",
|
:last_name => "Mannino",
|
||||||
:user_id => 2
|
:user_id => 2
|
||||||
@@ -23,6 +25,7 @@ users = [
|
|||||||
:email => "jim@metacorp.com",
|
:email => "jim@metacorp.com",
|
||||||
:admin => false,
|
:admin => false,
|
||||||
:password => "alohaowasp",
|
:password => "alohaowasp",
|
||||||
|
:password_confirmation => "alohaowasp",
|
||||||
:first_name => "Jim",
|
:first_name => "Jim",
|
||||||
:last_name => "Manico",
|
:last_name => "Manico",
|
||||||
:user_id =>3
|
:user_id =>3
|
||||||
@@ -31,6 +34,7 @@ users = [
|
|||||||
:email => "mike@metacorp.com",
|
:email => "mike@metacorp.com",
|
||||||
:admin => false,
|
:admin => false,
|
||||||
:password => "motorcross1445",
|
:password => "motorcross1445",
|
||||||
|
:password_confirmation => "motorcross1445",
|
||||||
:first_name => "Mike",
|
:first_name => "Mike",
|
||||||
:last_name => "McCabe",
|
:last_name => "McCabe",
|
||||||
:user_id =>4
|
:user_id =>4
|
||||||
@@ -39,6 +43,7 @@ users = [
|
|||||||
:email => "ken@metacorp.com",
|
:email => "ken@metacorp.com",
|
||||||
:admin => false,
|
:admin => false,
|
||||||
:password => "citrusblend",
|
:password => "citrusblend",
|
||||||
|
:password_confirmation => "citrusblend",
|
||||||
:first_name => "Ken",
|
:first_name => "Ken",
|
||||||
:last_name => "Johnson",
|
:last_name => "Johnson",
|
||||||
:user_id =>5
|
:user_id =>5
|
||||||
@@ -233,7 +238,7 @@ paid_time_off = [
|
|||||||
|
|
||||||
|
|
||||||
users.each do |user_info|
|
users.each do |user_info|
|
||||||
user = User.new(user_info.reject {|k| k == :user_id})
|
user = User.new(user_info.reject {|k| k == :user_id })
|
||||||
user.user_id = user_info[:user_id]
|
user.user_id = user_info[:user_id]
|
||||||
user.save
|
user.save
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user