Resolve conflict with User nickname and uname
This commit is contained in:
parent
b61797e896
commit
310f588621
|
@ -8,7 +8,7 @@ class EventLog < ActiveRecord::Base
|
||||||
scope :default_order, order('id DESC') # order('created_at DESC')
|
scope :default_order, order('id DESC') # order('created_at DESC')
|
||||||
|
|
||||||
before_create do
|
before_create do
|
||||||
self.user_name = user.try(:nickname) || 'guest'
|
self.user_name = user.try(:uname) || 'guest'
|
||||||
self.object_name ||= object.name if object.respond_to?(:name)
|
self.object_name ||= object.name if object.respond_to?(:name)
|
||||||
end
|
end
|
||||||
# after_create { self.class.current_controller = nil }
|
# after_create { self.class.current_controller = nil }
|
||||||
|
|
|
@ -1,10 +1,11 @@
|
||||||
class User < ActiveRecord::Base
|
class User < ActiveRecord::Base
|
||||||
has_many :authentications, :dependent => :destroy
|
|
||||||
|
|
||||||
devise :database_authenticatable, :registerable, :omniauthable, # :token_authenticatable, :encryptable, :timeoutable
|
devise :database_authenticatable, :registerable, :omniauthable, # :token_authenticatable, :encryptable, :timeoutable
|
||||||
:recoverable, :rememberable, :validatable #, :trackable, :confirmable, :lockable
|
:recoverable, :rememberable, :validatable #, :trackable, :confirmable, :lockable
|
||||||
|
|
||||||
|
has_many :authentications, :dependent => :destroy
|
||||||
|
|
||||||
has_many :roles, :through => :targets
|
has_many :roles, :through => :targets
|
||||||
|
|
||||||
has_many :targets, :as => :object, :class_name => 'Relation'
|
has_many :targets, :as => :object, :class_name => 'Relation'
|
||||||
|
|
||||||
has_many :own_projects, :as => :owner, :class_name => 'Project'
|
has_many :own_projects, :as => :owner, :class_name => 'Project'
|
||||||
|
@ -15,37 +16,20 @@ class User < ActiveRecord::Base
|
||||||
has_many :platforms, :through => :targets, :source => :target, :source_type => 'Platform', :autosave => true
|
has_many :platforms, :through => :targets, :source => :target, :source_type => 'Platform', :autosave => true
|
||||||
has_many :repositories, :through => :targets, :source => :target, :source_type => 'Repository', :autosave => true
|
has_many :repositories, :through => :targets, :source => :target, :source_type => 'Repository', :autosave => true
|
||||||
|
|
||||||
|
|
||||||
devise :database_authenticatable,
|
|
||||||
:recoverable, :rememberable, :validatable
|
|
||||||
|
|
||||||
attr_accessible :email, :password, :password_confirmation, :remember_me, :name, :uname
|
|
||||||
|
|
||||||
validates :uname, :presence => true, :uniqueness => {:case_sensitive => false}, :format => { :with => /^[a-zA-Z0-9_]+$/ }, :allow_nil => false, :allow_blank => false
|
validates :uname, :presence => true, :uniqueness => {:case_sensitive => false}, :format => { :with => /^[a-zA-Z0-9_]+$/ }, :allow_nil => false, :allow_blank => false
|
||||||
|
|
||||||
# validates :nickname, :presence => true, :uniqueness => {:case_sensitive => false}, :format => /^[a-zA-Z0-9_]+$/i
|
attr_accessible :email, :password, :password_confirmation, :remember_me, :login, :name, :ssh_key, :uname
|
||||||
|
|
||||||
attr_accessible :email, :password, :password_confirmation, :remember_me, :login, :name, :ssh_key, :uname#, :nickname
|
|
||||||
# attr_readonly :nickname
|
|
||||||
attr_readonly :uname
|
attr_readonly :uname
|
||||||
before_save :create_dir
|
|
||||||
after_destroy :remove_dir
|
|
||||||
|
|
||||||
def path
|
|
||||||
build_path(uname)
|
|
||||||
end
|
|
||||||
|
|
||||||
protected
|
|
||||||
|
|
||||||
attr_accessor :login
|
attr_accessor :login
|
||||||
|
|
||||||
|
before_save :create_dir
|
||||||
|
after_destroy :remove_dir
|
||||||
# after_create() { UserMailer.new_user_notification(self).deliver }
|
# after_create() { UserMailer.new_user_notification(self).deliver }
|
||||||
|
|
||||||
class << self
|
class << self
|
||||||
def find_for_database_authentication(warden_conditions)
|
def find_for_database_authentication(warden_conditions)
|
||||||
conditions = warden_conditions.dup
|
conditions = warden_conditions.dup
|
||||||
login = conditions.delete(:login)
|
login = conditions.delete(:login)
|
||||||
#where(conditions).where(["lower(nickname) = :value OR lower(email) = :value", { :value => login.downcase }]).first
|
|
||||||
where(conditions).where(["lower(uname) = :value OR lower(email) = :value", { :value => login.downcase }]).first
|
where(conditions).where(["lower(uname) = :value OR lower(email) = :value", { :value => login.downcase }]).first
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -54,8 +38,7 @@ class User < ActiveRecord::Base
|
||||||
if data = session["devise.omniauth_data"]
|
if data = session["devise.omniauth_data"]
|
||||||
if info = data['user_info'] and info.present?
|
if info = data['user_info'] and info.present?
|
||||||
user.email = info['email'].presence if user.email.blank?
|
user.email = info['email'].presence if user.email.blank?
|
||||||
# user.nickname ||= info['nickname'].presence || info['username'].presence
|
user.uname ||= info['nickname'].presence || info['username'].presence
|
||||||
user.uname ||= info['uname'].presence || info['username'].presence
|
|
||||||
user.name ||= info['name'].presence || [info['first_name'], info['last_name']].join(' ').strip
|
user.name ||= info['name'].presence || [info['first_name'], info['last_name']].join(' ').strip
|
||||||
end
|
end
|
||||||
user.password = Devise.friendly_token[0,20] # stub password
|
user.password = Devise.friendly_token[0,20] # stub password
|
||||||
|
@ -77,6 +60,11 @@ class User < ActiveRecord::Base
|
||||||
result
|
result
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def path
|
||||||
|
build_path(uname)
|
||||||
|
end
|
||||||
|
|
||||||
|
protected
|
||||||
def build_path(dir)
|
def build_path(dir)
|
||||||
puts APP_CONFIG['root_path']
|
puts APP_CONFIG['root_path']
|
||||||
puts dir
|
puts dir
|
||||||
|
|
|
@ -391,7 +391,7 @@ ru:
|
||||||
name: Имя
|
name: Имя
|
||||||
login: Никнейм или Email
|
login: Никнейм или Email
|
||||||
email: Email
|
email: Email
|
||||||
nickname: Никнейм
|
uname: Никнейм
|
||||||
ssh_key: SSH ключ
|
ssh_key: SSH ключ
|
||||||
current_password: Текущий пароль
|
current_password: Текущий пароль
|
||||||
roles: Роли
|
roles: Роли
|
||||||
|
|
|
@ -0,0 +1,13 @@
|
||||||
|
class DeleteNicknameInitUname < ActiveRecord::Migration
|
||||||
|
def self.up
|
||||||
|
remove_column :users, :nickname
|
||||||
|
add_index :users, :uname, :unique => true
|
||||||
|
User.all.each {|u| User.where(:id => u.id).update_all(:uname => u.email.split('@').first)}
|
||||||
|
end
|
||||||
|
|
||||||
|
def self.down
|
||||||
|
add_column :users, :nickname, :string
|
||||||
|
remove_index :users, :uname
|
||||||
|
User.all.each {|u| User.where(:id => u.id).update_all(:nickname => u.email.split('@').first)}
|
||||||
|
end
|
||||||
|
end
|
|
@ -10,7 +10,7 @@
|
||||||
#
|
#
|
||||||
# It's strongly recommended to check this file into your version control system.
|
# It's strongly recommended to check this file into your version control system.
|
||||||
|
|
||||||
ActiveRecord::Schema.define(:version => 20111019173246) do
|
ActiveRecord::Schema.define(:version => 20111021164945) do
|
||||||
|
|
||||||
create_table "arches", :force => true do |t|
|
create_table "arches", :force => true do |t|
|
||||||
t.string "name", :null => false
|
t.string "name", :null => false
|
||||||
|
@ -251,13 +251,12 @@ ActiveRecord::Schema.define(:version => 20111019173246) do
|
||||||
t.datetime "remember_created_at"
|
t.datetime "remember_created_at"
|
||||||
t.datetime "created_at"
|
t.datetime "created_at"
|
||||||
t.datetime "updated_at"
|
t.datetime "updated_at"
|
||||||
t.string "nickname"
|
|
||||||
t.text "ssh_key"
|
t.text "ssh_key"
|
||||||
t.string "uname"
|
t.string "uname"
|
||||||
end
|
end
|
||||||
|
|
||||||
add_index "users", ["email"], :name => "index_users_on_email", :unique => true
|
add_index "users", ["email"], :name => "index_users_on_email", :unique => true
|
||||||
add_index "users", ["nickname"], :name => "index_users_on_nickname", :unique => true
|
|
||||||
add_index "users", ["reset_password_token"], :name => "index_users_on_reset_password_token", :unique => true
|
add_index "users", ["reset_password_token"], :name => "index_users_on_reset_password_token", :unique => true
|
||||||
|
add_index "users", ["uname"], :name => "index_users_on_uname", :unique => true
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue