Class: Devise::Customizers::UserName
- Inherits:
-
Object
- Object
- Devise::Customizers::UserName
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
#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, login_attribute
@orm = orm
@user_class = user_class
@login_attribute = login_attribute
end
|
Instance Attribute Details
#login_attribute ⇒ Object
Returns the value of attribute login_attribute.
11
12
13
|
# File 'lib/generators/devise/customize/helpers/username_helper.rb', line 11
def login_attribute
@login_attribute
end
|
#orm ⇒ Object
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_class ⇒ Object
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_class ⇒ Object
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, login_attribute).modify_initializer
if login_attribute == 'login'
configure_generic_login
::Devise::CustomizeMessage.locales_update
end
end
|
#add_virtual_login_accessor ⇒ Object
47
48
49
50
51
52
53
54
|
# File 'lib/generators/devise/customize/helpers/username_helper.rb', line 47
def add_virtual_login_accessor
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
|
56
57
58
59
60
61
|
# File 'lib/generators/devise/customize/helpers/username_helper.rb', line 56
def configure_generic_login
debug! 'configure generic login'
add_virtual_login_accessor
override_user_auth
modify_retrieve_password
end
|
#insert_reset_password_keys_stmt ⇒ Object
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_accessible ⇒ Object
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_password ⇒ Object
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
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_auth ⇒ Object
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
|