Class: Devise::Customizers::UserName

Inherits:
Object
  • Object
show all
Extended by:
RailsAssist::UseMacro
Includes:
Cream::GeneratorHelper
Defined in:
lib/generators/devise/customize/helpers/username_helper.rb

Defined Under Namespace

Classes: AuthenticationKeys

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Cream::GeneratorHelper

#add_logger, #debug!, included, #info!, #logit!

Constructor Details

#initialize(orm, user_class, login_attribute) ⇒ UserName

Returns a new instance of UserName.



13
14
15
16
17
# File 'lib/generators/devise/customize/helpers/username_helper.rb', line 13

def initialize orm, user_class, 
  @orm = orm
  @user_class = user_class          
  @login_attribute = 
end

Instance Attribute Details

#login_attributeObject

Returns the value of attribute login_attribute.



11
12
13
# File 'lib/generators/devise/customize/helpers/username_helper.rb', line 11

def 
  @login_attribute
end

#ormObject

Returns the value of attribute orm.



11
12
13
# File 'lib/generators/devise/customize/helpers/username_helper.rb', line 11

def orm
  @orm
end

#user_classObject

Returns the value of attribute user_class.



11
12
13
# File 'lib/generators/devise/customize/helpers/username_helper.rb', line 11

def user_class
  @user_class
end

Instance Method Details

#add_to_user_classObject



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/generators/devise/customize/helpers/username_helper.rb', line 19

def add_to_user_class
  debug! 'add_to_user_class'
  if active_record? && !has_migration_file?(:add_username_to_users)
    debug! 'create migration: add_username_to_users'
    %x[rails g migration add_username_to_users username:string]
    %x[rake db:migrate]        
  end

  make_attribute_accessible                
  
  AuthenticationKeys.new(user_class, ).modify_initializer 

  if  == 'login'
    
    ::Devise::CustomizeMessage.locales_update
  end
end

#add_virtual_login_accessorObject



47
48
49
50
51
52
53
54
# File 'lib/generators/devise/customize/helpers/username_helper.rb', line 47

def           
  return if user_class_content? 'attr_accessor :login' 
  
  ::File.insert_into model_file(user_class), :before_last => 'end' do
    %q{
  attr_accessor :login}
  end
end

#configure_generic_loginObject



56
57
58
59
60
61
# File 'lib/generators/devise/customize/helpers/username_helper.rb', line 56

def 
  debug! 'configure generic login'
          
  override_user_auth        
  modify_retrieve_password
end

#insert_reset_password_keys_stmtObject



92
93
94
95
# File 'lib/generators/devise/customize/helpers/username_helper.rb', line 92

def insert_reset_password_keys_stmt
  return if devise_init_content? '# reset_password_keys = [ :login ]'        
  ::File.insert_into initializer_file(:devise), 'config.reset_password_keys = [ :login ]', :after => 'Rails::Application'
end

#make_attribute_accessibleObject



37
38
39
40
41
42
43
44
45
# File 'lib/generators/devise/customize/helpers/username_helper.rb', line 37

def make_attribute_accessible
  return if user_class_content? 'attr_accessible :username'

  ::File.insert_into model_file(user_class), :before_last => 'end' do
    %q{
  # accessor config
  attr_accessible :username}
  end
end

#modify_retrieve_passwordObject



76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
# File 'lib/generators/devise/customize/helpers/username_helper.rb', line 76

def modify_retrieve_password
  if !is_default_devise_orm?
    ::Devise::CustomizeMessage.retrieve_password
    return
  end
  insert_reset_password_keys_stmt # in devise initializer

  return if user_class_content? '# recover login'
  
  content =  << ::Devise::Customizers::RecoverLogin.new(orm).retrieve_password

  ::File.insert_into model_file(user_class), :before_last => 'end' do
    content
  end        
end

#override_user_authObject



63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/generators/devise/customize/helpers/username_helper.rb', line 63

def override_user_auth
  if !is_default_devise_orm?
    Devise::CustomizeMessage.find_record
    return
  end         

  return if user_class_content? '# self.find_for_database_authentication'
          
  ::File.insert_into model_file(user_class), :before_last => 'end' do
    ::Devise::QueryCustomizers::UserAuth.send orm
  end
end