goma 0.0.1.beta → 0.0.1.gamma
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +1 -0
- data/Gemfile.lock +9 -1
- data/README.md +18 -15
- data/goma.gemspec +16 -0
- data/lib/generators/goma/erb/templates/confirmation/new.html.erb +2 -2
- data/lib/generators/goma/erb/templates/password/new.html.erb +2 -2
- data/lib/generators/goma/erb/templates/session/new.html.erb +3 -3
- data/lib/generators/goma/erb/templates/unlock/new.html.erb +2 -2
- data/lib/generators/goma/helpers/helpers.rb +5 -0
- data/lib/generators/goma/install/templates/goma.rb +38 -22
- data/lib/generators/goma/mailer/erb/templates/activation_needed_email.html.erb +1 -1
- data/lib/generators/goma/mailer/erb/templates/activation_needed_email.text.erb +1 -1
- data/lib/generators/goma/mailer/erb/templates/email_confirmation_needed_email.html.erb +1 -1
- data/lib/generators/goma/mailer/erb/templates/email_confirmation_needed_email.text.erb +1 -1
- data/lib/generators/goma/mailer/templates/mailer.rb +1 -1
- data/lib/generators/goma/model/active_record_generator.rb +11 -0
- data/lib/generators/goma/model/oauth/active_record_generator.rb +10 -1
- data/lib/generators/goma/model/oauth/templates/model.rb +5 -0
- data/lib/generators/goma/resource_route/resource_route_generator.rb +10 -12
- data/lib/generators/goma/scaffold_controller/templates/confirmation_controller.rb +5 -5
- data/lib/generators/goma/scaffold_controller/templates/oauth_controller.rb +1 -1
- data/lib/generators/goma/scaffold_controller/templates/password_controller.rb +2 -2
- data/lib/generators/goma/scaffold_controller/templates/session_controller.rb +2 -2
- data/lib/generators/goma/scaffold_controller/templates/unlock_controller.rb +1 -1
- data/lib/generators/goma/scaffold_controller/templates/user_controller.rb +6 -1
- data/lib/goma/config.rb +16 -19
- data/lib/goma/models/confirmable.rb +1 -1
- data/lib/goma/models/rememberable.rb +2 -2
- data/lib/goma/railtie.rb +0 -9
- data/lib/goma/version.rb +1 -1
- data/test/controllers/confirmations_controller_test.rb +14 -0
- data/test/controllers/lockable_controller_test.rb +8 -8
- data/test/controllers/sessions_controller_test.rb +8 -8
- data/test/controllers/users_controller_test.rb +2 -13
- data/test/fabricators/users_fabricator.rb +2 -2
- data/test/integration/{authenticatable_test.rb → authenticatable_integration_test.rb} +4 -4
- data/test/integration/omniauthable_integration_test.rb +26 -0
- data/test/integration/{rememberable_test.rb → rememberable_integration_test.rb} +7 -7
- data/test/integration/{routes_test.rb → routes_integration_test.rb} +8 -8
- data/test/integration/{timeoutable_test.rb → timeoutable_integration_test.rb} +3 -3
- data/test/integration/{trackable_test.rb → trackable_integration_test.rb} +3 -3
- data/test/models/confirmable_test.rb +1 -1
- data/test/models/validatable_test.rb +7 -7
- data/test/rails_app/app/assets/javascripts/{sessions.js → confirmations.js} +0 -0
- data/test/rails_app/app/assets/stylesheets/authentications.css +4 -0
- data/test/rails_app/app/assets/stylesheets/confirmations.css +4 -0
- data/test/rails_app/app/assets/stylesheets/passwords.css +4 -0
- data/test/rails_app/app/assets/stylesheets/unlocks.css +4 -0
- data/test/rails_app/app/controllers/authentications_controller.rb +15 -0
- data/test/rails_app/app/controllers/confirmations_controller.rb +52 -0
- data/test/rails_app/app/controllers/passwords_controller.rb +41 -0
- data/test/rails_app/app/controllers/sessions_controller.rb +13 -5
- data/test/rails_app/app/controllers/unlocks_controller.rb +32 -0
- data/test/rails_app/app/controllers/users_controller.rb +32 -15
- data/test/rails_app/app/helpers/authentications_helper.rb +2 -0
- data/test/rails_app/app/helpers/confirmations_helper.rb +2 -0
- data/test/rails_app/app/helpers/passwords_helper.rb +2 -0
- data/test/rails_app/app/helpers/unlocks_helper.rb +2 -0
- data/test/rails_app/app/mailers/user_mailer.rb +33 -20
- data/test/rails_app/app/views/confirmations/new.html.erb +12 -0
- data/test/rails_app/app/views/passwords/edit.html.erb +27 -0
- data/test/rails_app/app/views/passwords/new.html.erb +11 -0
- data/test/rails_app/app/views/sessions/new.html.erb +13 -5
- data/test/rails_app/app/views/unlocks/new.html.erb +11 -0
- data/test/rails_app/app/views/user_mailer/activation_needed_email.text.erb +5 -2
- data/test/rails_app/app/views/user_mailer/activation_success_email.text.erb +7 -2
- data/test/rails_app/app/views/user_mailer/email_confirmation_needed_email.text.erb +5 -2
- data/test/rails_app/app/views/user_mailer/email_confirmation_success_email.text.erb +4 -2
- data/test/rails_app/app/views/user_mailer/reset_password_email.text.erb +10 -0
- data/test/rails_app/app/views/user_mailer/unlock_token_email.text.erb +10 -0
- data/test/rails_app/app/views/users/_form.html.erb +33 -0
- data/test/rails_app/app/views/users/edit.html.erb +6 -2
- data/test/rails_app/app/views/users/index.html.erb +25 -2
- data/test/rails_app/app/views/users/new.html.erb +5 -2
- data/test/rails_app/app/views/users/show.html.erb +4 -2
- data/test/rails_app/config/environments/test.rb +2 -0
- data/test/rails_app/config/initializers/goma.rb +43 -29
- data/test/rails_app/config/initializers/omniauth.rb +4 -0
- data/test/rails_app/config/routes.rb +20 -5
- data/test/rails_app/db/migrate/20140512081308_create_users.rb +44 -0
- data/test/rails_app/db/migrate/{20140326043644_create_authentications.rb → 20140512081309_create_authentications.rb} +1 -0
- data/test/rails_app/db/schema.rb +9 -5
- data/test/test_helper.rb +10 -0
- metadata +72 -24
- data/test/rails_app/app/views/user_mailer/unlock_email.text.erb +0 -0
- data/test/rails_app/db/migrate/20131205013904_goma_create_users.rb +0 -46
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a89f50e2d41994b88fc95fbc6c981684f8a71043
|
4
|
+
data.tar.gz: 0d9c4bb7dd2dfd2836b903d62fd5689d7bee43ed
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e1e4c13eb562fc355eb35effae5a44eca9f4f0e29d50ed69de2687689893609ef14ccc234d42eb9290b59f87091d1a596f9453405dcdaa701191fb864e5ba20d
|
7
|
+
data.tar.gz: 141f626b7c5a22e697bab9b7c63a4c335872e8b024be56c8e68a09e58ba9f44c464df38af417afb87d171a58c87ee1d1d30eee306ba4d788b87f82125abb840a
|
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
goma (0.0.1.
|
4
|
+
goma (0.0.1.gamma)
|
5
5
|
rails (~> 4.0)
|
6
6
|
warden
|
7
7
|
|
@@ -58,9 +58,16 @@ GEM
|
|
58
58
|
mocha (1.0.0)
|
59
59
|
metaclass (~> 0.0.1)
|
60
60
|
multi_json (1.9.3)
|
61
|
+
oauth (0.4.7)
|
61
62
|
omniauth (1.2.1)
|
62
63
|
hashie (>= 1.2, < 3)
|
63
64
|
rack (~> 1.0)
|
65
|
+
omniauth-oauth (1.0.1)
|
66
|
+
oauth
|
67
|
+
omniauth (~> 1.0)
|
68
|
+
omniauth-twitter (1.0.1)
|
69
|
+
multi_json (~> 1.3)
|
70
|
+
omniauth-oauth (~> 1.0)
|
64
71
|
polyglot (0.3.4)
|
65
72
|
rack (1.5.2)
|
66
73
|
rack-test (0.6.2)
|
@@ -114,6 +121,7 @@ DEPENDENCIES
|
|
114
121
|
minitest-ansi
|
115
122
|
mocha
|
116
123
|
omniauth
|
124
|
+
omniauth-twitter
|
117
125
|
shoulda-context
|
118
126
|
single_test
|
119
127
|
sqlite3
|
data/README.md
CHANGED
@@ -60,7 +60,7 @@ rails generate goma:scaffold NAME
|
|
60
60
|
|
61
61
|
Replace NAME by the class name used for the applications users, it's frequently `user` but could also be anything you want. This will create a model with a migration, controllers, views, and mailers (that are configured based on the initializer file which is created by `rails generate goma:install`).
|
62
62
|
|
63
|
-
Please note that this scaffold generator is just a "better than nothing
|
63
|
+
Please note that this scaffold generator is just a "better than nothing" thing. It does not include tests and there must be bugs. But if you see the code which is generated by this scaffold, you can see how to use this gem roughly. If you find bugs, please create an issue or send a pull request.
|
64
64
|
|
65
65
|
|
66
66
|
You can also use the following generators.
|
@@ -89,26 +89,29 @@ rails generate goma:model MODEL
|
|
89
89
|
|
90
90
|
```
|
91
91
|
# in routes
|
92
|
-
current_user
|
93
|
-
|
92
|
+
current_user # If you have an :admin scope, you can use current_admin
|
93
|
+
logged_in? #
|
94
|
+
user_logged_in? # you can specify scope
|
94
95
|
|
95
96
|
# in controllers
|
96
|
-
require_login
|
97
|
-
require_user_login
|
98
|
-
login(identifier, password, remember_me=false)
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
97
|
+
require_login # this is a before filter (default scope)
|
98
|
+
require_user_login # ditto. You can specify a scope.
|
99
|
+
login(identifier, password, remember_me=false)
|
100
|
+
# You can use multiple identifiers in a field, such as username or email.
|
101
|
+
force_login(user) # Login without credentials (same as auto_login in Sorcery gem)
|
102
|
+
logout(scope=Goma.config.default_scope)
|
103
|
+
# Logout. you can specify a scope.
|
104
|
+
user_logout # ditto
|
105
|
+
logged_in? # Available in view
|
106
|
+
user_logged_in? # ditto. You can specify a scope.
|
107
|
+
current_user # Available in view. If you have an :admin scope, you can use current_admin
|
105
108
|
|
106
109
|
# Password authenticatable
|
107
|
-
find_by_identifier
|
110
|
+
find_by_identifier # You can find user by authentication key
|
108
111
|
|
109
112
|
# Rememberable
|
110
|
-
remember_me!
|
111
|
-
forget_me!
|
113
|
+
remember_me! # Goma call this automatically so that, usually, You don't have to call this manually.
|
114
|
+
forget_me! # ditto
|
112
115
|
|
113
116
|
# Confirmable
|
114
117
|
User.load_from_activation_token(token)
|
data/goma.gemspec
CHANGED
@@ -18,6 +18,7 @@ Gem::Specification.new do |s|
|
|
18
18
|
s.test_files = `git ls-files -- test/*`.split("\n")
|
19
19
|
s.require_paths = ['lib']
|
20
20
|
s.post_install_message =<<-MESSAGE
|
21
|
+
|
21
22
|
\e[32mThank you for installing!
|
22
23
|
|
23
24
|
You can use this gem as follows:
|
@@ -28,6 +29,21 @@ Edit config/initializers/goma.rb to fit your needs.
|
|
28
29
|
|
29
30
|
\e[0mrails g goma:scaffold User\e[32m
|
30
31
|
|
32
|
+
|
33
|
+
===========================================================================
|
34
|
+
Some setup you must do manually if you heven't yet:
|
35
|
+
|
36
|
+
- Ensure you have defined default url options in your environments files.
|
37
|
+
Here is an example of default_url_options appropriate for a development
|
38
|
+
environment in config/environments/development.rb
|
39
|
+
|
40
|
+
\e[0mconfig.action_mailer.default_url_options = { host: 'localhost:3000' }\e[32m
|
41
|
+
|
42
|
+
in production, :host should be set to the actual host of your application.
|
43
|
+
|
44
|
+
===========================================================================
|
45
|
+
|
46
|
+
|
31
47
|
That's it.
|
32
48
|
|
33
49
|
This gem is in early development phase and I do not recommend you to use this for production for a while.
|
@@ -2,8 +2,8 @@
|
|
2
2
|
|
3
3
|
<%%= form_tag(:<%= name.underscore.pluralize %>_url, method: :post) do %>
|
4
4
|
<div class="field">
|
5
|
-
<%%= label_tag :<%= goma_config.authentication_keys.
|
6
|
-
<%%= text_field_tag
|
5
|
+
<%%= label_tag :<%= goma_config.authentication_keys.to_field_name %> %><br>
|
6
|
+
<%%= text_field_tag :<%= goma_config.authentication_keys.to_field_name %>
|
7
7
|
</div>
|
8
8
|
<div class="actions">
|
9
9
|
<%%= submit_tag "Resend activation instructions" %>
|
@@ -2,8 +2,8 @@
|
|
2
2
|
|
3
3
|
<%%= form_tag(<%= name.underscore.pluralize %>_url, method: :post) do %>
|
4
4
|
<div class="field">
|
5
|
-
<%%= label_tag :<%= goma_config.authentication_keys.
|
6
|
-
<%%= text_field_tag
|
5
|
+
<%%= label_tag :<%= goma_config.authentication_keys.to_field_name %> %><br>
|
6
|
+
<%%= text_field_tag :<%= goma_config.authentication_keys.to_field_name %> %>
|
7
7
|
</div>
|
8
8
|
<div class="actions">
|
9
9
|
<%%= submit_tag "Send me reset password instructions" %>
|
@@ -1,9 +1,9 @@
|
|
1
1
|
<h1>Login</h1>
|
2
2
|
|
3
|
-
<%%= form_tag(<%= name.underscore
|
3
|
+
<%%= form_tag(<%= name.underscore %>_url, method: :post) do %>
|
4
4
|
<div class="field">
|
5
|
-
<%%= label_tag :<%= goma_config.authentication_keys.
|
6
|
-
<%%= text_field_tag
|
5
|
+
<%%= label_tag :<%= goma_config.authentication_keys.to_field_name %> %><br>
|
6
|
+
<%%= text_field_tag :<%= goma_config.authentication_keys.to_field_name %> %>
|
7
7
|
</div>
|
8
8
|
<div class="field">
|
9
9
|
<%%= label_tag :<%= goma_config.password_attribute_name %> %><br>
|
@@ -2,8 +2,8 @@
|
|
2
2
|
|
3
3
|
<%%= form_tag(<%= name.underscore.pluralize%>_url, method: :post) do %>
|
4
4
|
<div class="field">
|
5
|
-
<%%= label_tag :<%= goma_config.authentication_keys.
|
6
|
-
<%%= text_field_tag
|
5
|
+
<%%= label_tag :<%= goma_config.authentication_keys.to_field_name %> %><br>
|
6
|
+
<%%= text_field_tag :<%= goma_config.authentication_keys.to_field_name %>
|
7
7
|
</div>
|
8
8
|
<div class="actions">
|
9
9
|
<%%= submit_tag "Resend unlock instructions" %>
|
@@ -1,28 +1,39 @@
|
|
1
1
|
Goma.configure do |config|
|
2
2
|
# config.default_mailer_name = 'UserMailer'
|
3
3
|
config.mailer_sender = 'please-change-me-at-config-initializers-goma@example.com'
|
4
|
-
# config.authentication_keys = [ :email ]
|
5
|
-
# config.email_regexp = /\A[^@]+@[^@]+\z/
|
6
|
-
# config.case_insensitive_keys = [ :email ]
|
7
|
-
# config.strip_whitespace_keys = [ :email ]
|
8
4
|
# config.clean_up_csrf_token_on_authentication = true
|
9
5
|
config.secret_key = '<%= SecureRandom.hex(64) %>'
|
10
|
-
# config.
|
11
|
-
config.stretches = Rails.env.test? ? 1 : 10
|
12
|
-
# config.pepper = '<%= SecureRandom.hex(64) %>'
|
13
|
-
# config.serialization_method = :devise
|
6
|
+
# config.serialization_method = :goma
|
14
7
|
# config.scopes = [:user]
|
15
8
|
# config.default_scope = :user
|
16
|
-
#
|
9
|
+
#
|
10
|
+
# Select modules you need. All modules are included by default.
|
11
|
+
config.modules = [:password_authenticatable, :validatable, :confirmable, :rememberable, :timeoutable, :lockable, :recoverable, :trackable, :omniauthable]
|
12
|
+
# config.save_return_to_url = true
|
13
|
+
# config.not_authenticated_action = :not_authenticated
|
14
|
+
|
17
15
|
|
16
|
+
####################################################
|
17
|
+
# Password authenticatable
|
18
|
+
# config.authentication_keys = [ :email ]
|
19
|
+
# config.case_insensitive_keys = [ :email ]
|
20
|
+
# config.strip_whitespace_keys = [ :email ]
|
21
|
+
# config.encryptor = :bcrypt
|
22
|
+
# config.pepper = '<%= SecureRandom.hex(64) %>'
|
23
|
+
config.stretches = Rails.env.test? ? 1 : 10
|
18
24
|
# config.email_attribute_name = :email
|
19
25
|
# config.password_attribute_name = :password
|
20
26
|
# config.encrypted_password_attribute_name = :encrypted_password
|
21
27
|
|
28
|
+
####################################################
|
29
|
+
# Validatable
|
30
|
+
# config.password_length = 8..128
|
31
|
+
# config.email_regexp = /\A[^@]+@[^@]+\z/
|
32
|
+
|
22
33
|
####################################################
|
23
34
|
# Confirmable
|
24
35
|
# config.activation_mailer_name = nil
|
25
|
-
# config.
|
36
|
+
# config.email_confirmation_mailer_name = nil
|
26
37
|
# config.confirmation_keys = [ :email ]
|
27
38
|
# config.allow_unconfirmed_access_for = 0
|
28
39
|
# config.activate_within = 3.days
|
@@ -44,22 +55,28 @@ Goma.configure do |config|
|
|
44
55
|
# config.remember_for = 2.weeks
|
45
56
|
# config.extend_remember_period = false
|
46
57
|
# config.rememberable_options = {}
|
58
|
+
# config.remember_token_attribute_name = nil
|
59
|
+
# config.remember_created_at_attribute_name = :remember_created_at
|
47
60
|
|
48
61
|
|
49
62
|
####################################################
|
50
63
|
# Timeoutable
|
51
64
|
# config.timeout_in = 30.minutes
|
52
65
|
# config.logout_all_scopes = false
|
66
|
+
# config.validate_session_even_in_not_login_area = true
|
53
67
|
|
54
68
|
####################################################
|
55
69
|
# Lockable
|
56
70
|
# config.unlock_token_mailer_name = nil
|
71
|
+
# config.unlock_token_email_method_name = :unlock_email
|
57
72
|
# config.lock_strategy = :failed_attempts
|
58
73
|
# config.unlock_keys = [ :email ]
|
59
74
|
# config.unlock_strategies = [ :email, :time ]
|
60
75
|
# config.maximum_attempts = 20
|
76
|
+
# config.failed_attempts_attribute_name = :failed_attempts
|
77
|
+
# config.locked_at_attribute_name = :locked_at
|
61
78
|
# config.unlock_in = 1.hour
|
62
|
-
# config.last_attempt_warning = false
|
79
|
+
# config.last_attempt_warning = false # TODO not yet implemented
|
63
80
|
# config.unlock_token_attribute_name = :unlock_token
|
64
81
|
# config.unlock_token_sent_at_attribute_name = :unlock_token_sent_at
|
65
82
|
# config.unlock_token_to_send_attribute_name = :raw_unlock_token
|
@@ -67,30 +84,29 @@ Goma.configure do |config|
|
|
67
84
|
####################################################
|
68
85
|
# Recoverable
|
69
86
|
# config.reset_password_mailer_name = nil
|
87
|
+
# config.reset_password_email_method_name = :reset_password_email
|
70
88
|
# config.reset_password_keys = [ :email ]
|
71
89
|
# config.reset_password_within = 6.hours
|
72
90
|
# config.reset_password_token_attribute_name = :reset_password_token
|
73
91
|
# config.reset_password_token_sent_at_attribute_name = :reset_password_token_sent_at
|
74
92
|
# config.reset_password_token_to_send_attribute_name = :raw_reset_password_token
|
75
93
|
|
94
|
+
####################################################
|
95
|
+
# Trackable
|
96
|
+
# config.login_count_attribute_name = :login_count
|
97
|
+
# config.current_login_at_attribute_name = :current_login_at
|
98
|
+
# config.last_login_at_attribute_name = :last_login_at
|
99
|
+
# config.current_login_ip_attribute_name = :current_login_ip
|
100
|
+
# config.last_login_ip_attribute_name = :last_login_ip
|
101
|
+
|
76
102
|
####################################################
|
77
103
|
# Omniauthable
|
78
|
-
# No providers are registered by default.
|
79
|
-
# ex.)
|
80
|
-
# config.omniauth :developer if Rails.env.in? ['development', 'test']
|
81
|
-
# config.omniauth :twitter, 'APP_ID', 'APP_SECRET'
|
82
|
-
#
|
83
104
|
# config.oauth_authentication_class_name = 'Authentication'
|
84
105
|
# config.oauth_provider_attribute_name = :provider
|
85
106
|
# config.oauth_uid_attribute_name = :uid
|
86
|
-
|
87
|
-
|
88
|
-
####################################################
|
89
|
-
# Attribute names settings
|
90
|
-
# config.salt_attribute_name = nil
|
91
|
-
# config.salt_join_token = ''
|
92
107
|
end
|
93
108
|
|
94
109
|
# Scope specific configuration
|
95
110
|
# Goma.configure_for(:user) do |config|
|
111
|
+
# -- scope specifig configurations goes here --
|
96
112
|
# end
|
@@ -2,4 +2,4 @@
|
|
2
2
|
|
3
3
|
<p>You can activate your account through the link below:</p>
|
4
4
|
|
5
|
-
<p><%%= link_to 'Activate my account',
|
5
|
+
<p><%%= link_to 'Activate my account', confirmation_url(@<%= resource_name %>.<%= goma_config.confirmation_token_to_send_attribute_name %>) %></p>
|
@@ -3,4 +3,4 @@ Welcome, <%%= @<%= resource_name %>.<%= goma_config.email_attribute_name %> %>
|
|
3
3
|
|
4
4
|
You can activate your account through the link below:
|
5
5
|
|
6
|
-
<%%=
|
6
|
+
<%%= activate_confirmation_url(@<%= resource_name %>.<%= goma_config.confirmation_token_to_send_attribute_name %>) %>
|
@@ -2,4 +2,4 @@
|
|
2
2
|
|
3
3
|
<p>You can confirm your account email through the link below:</p>
|
4
4
|
|
5
|
-
<p><%%= link_to 'Comfirm my account email',
|
5
|
+
<p><%%= link_to 'Comfirm my account email', email_confirmation_url(@<%= resource_name %>.<%= goma_config.confirmation_token_to_send_attribute_name %>) %></p>
|
@@ -3,4 +3,4 @@ Hello, <%%= @<%= resource_name %>.<%= goma_config.email_attribute_name %> %>
|
|
3
3
|
|
4
4
|
You can confirm your account email through the link below:
|
5
5
|
|
6
|
-
<%%=
|
6
|
+
<%%= email_confirmation_url(@<%= resource_name %>.<%= goma_config.confirmation_token_to_send_attribute_name %>) %>
|
@@ -1,6 +1,6 @@
|
|
1
1
|
<% module_namespacing do -%>
|
2
2
|
class <%= class_name %> < ActionMailer::Base
|
3
|
-
default from: "
|
3
|
+
default from: "<%= goma_config.mailer_sender %>"
|
4
4
|
|
5
5
|
<% goma_actions.each do |action, subject| -%>
|
6
6
|
# Subject can be set in your I18n file at config/locales/en.yml
|
@@ -12,6 +12,17 @@ module Goma
|
|
12
12
|
merge_goma_user_attributes!
|
13
13
|
end
|
14
14
|
|
15
|
+
def add_options_to_migration
|
16
|
+
if path = self.class.migration_exists?('db/migrate', migration_file_name)
|
17
|
+
gsub_file(path,
|
18
|
+
"t.integer :#{goma_config.failed_attempts_attribute_name}",
|
19
|
+
"t.integer :#{goma_config.failed_attempts_attribute_name}, default: 0, null: false")
|
20
|
+
gsub_file(path,
|
21
|
+
"t.integer :#{goma_config.login_count_attribute_name}",
|
22
|
+
"t.integer :#{goma_config.login_count_attribute_name}, default: 0, null: false")
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
15
26
|
private
|
16
27
|
def merge_goma_user_attributes!
|
17
28
|
self.attributes = (goma_user_attributes.map do |attr|
|
@@ -9,14 +9,23 @@ module Goma
|
|
9
9
|
@generator_name = 'active_record'
|
10
10
|
hide!
|
11
11
|
|
12
|
-
source_root File.expand_path('
|
12
|
+
source_root File.expand_path('../templates', __FILE__)
|
13
13
|
|
14
14
|
def initialize(*)
|
15
15
|
super
|
16
16
|
merge_goma_oauth_attributes!
|
17
17
|
end
|
18
18
|
|
19
|
+
# This method overwrite is needed, because template source location is different. (one level deeper)
|
20
|
+
# I know this is terrible hack.
|
21
|
+
def create_migration_file
|
22
|
+
return unless options[:migration] && options[:parent].nil?
|
23
|
+
attributes.each { |a| a.attr_options.delete(:index) if a.reference? && !a.has_index? } if options[:indexes] == false
|
24
|
+
migration_template "../../../migration/templates/create_table_migration.rb", "db/migrate/create_#{table_name}.rb"
|
25
|
+
end
|
26
|
+
|
19
27
|
def inject_index
|
28
|
+
# if path = self.class.migration_exists('db/migrate', migration_file_name)
|
20
29
|
if behavior == :invoke
|
21
30
|
insert_into_file("db/migrate/#{migration_number}_#{migration_file_name}.rb", goma_oauth_index, {after: /^\s{4,}end\s*\n/})
|
22
31
|
end
|
@@ -38,14 +38,14 @@ module Goma
|
|
38
38
|
end
|
39
39
|
|
40
40
|
def resource_string
|
41
|
-
"#{
|
41
|
+
"#{resource_definition}#{restriction}#{appending_string}"
|
42
42
|
end
|
43
43
|
|
44
|
-
def
|
45
|
-
if options[:controller_type] ==
|
46
|
-
"resource"
|
44
|
+
def resource_definition
|
45
|
+
if options[:controller_type] == 'session'
|
46
|
+
"resource :#{file_name.singularize}"
|
47
47
|
else
|
48
|
-
"resources"
|
48
|
+
"resources :#{file_name.pluralize}"
|
49
49
|
end
|
50
50
|
end
|
51
51
|
|
@@ -53,12 +53,10 @@ module Goma
|
|
53
53
|
case options[:controller_type]
|
54
54
|
when 'session'
|
55
55
|
', only: [:new, :create, :destroy]'
|
56
|
-
when 'confirmation'
|
57
|
-
', only: [:new, :create]'
|
56
|
+
when 'confirmation', 'unlock'
|
57
|
+
', only: [:show, :new, :create]'
|
58
58
|
when 'password'
|
59
59
|
', only: [:new, :create, :edit, :update]'
|
60
|
-
when 'unlock'
|
61
|
-
', only: [:show, :new, :create,]'
|
62
60
|
when 'oauth'
|
63
61
|
', only: [:create]'
|
64
62
|
else
|
@@ -67,11 +65,11 @@ module Goma
|
|
67
65
|
end
|
68
66
|
|
69
67
|
def appending_string
|
70
|
-
if options[:controller_type] == 'confirmation' &&
|
68
|
+
if options[:controller_type] == 'confirmation' &&
|
69
|
+
goma_config.modules.include?(:confirmable) && goma_config.email_confirmation_enabled
|
71
70
|
strings = []
|
72
71
|
strings << ' do'
|
73
|
-
strings << ' get :
|
74
|
-
strings << ' get :confirm, on: :member' if goma_config.email_confirmation_enabled
|
72
|
+
strings << ' get :email, on: :member'
|
75
73
|
strings << 'end'
|
76
74
|
strings.join("\n")
|
77
75
|
elsif options[:controller_type] == 'oauth'
|
@@ -12,7 +12,7 @@ class <%= controller_class_name %>Controller < ApplicationController
|
|
12
12
|
|
13
13
|
# POST <%= route_url %>
|
14
14
|
def create
|
15
|
-
@<%= resource_name %> = <%= resource_class_name %>.find_by_identifier(params[
|
15
|
+
@<%= resource_name %> = <%= resource_class_name %>.find_by_identifier(params[:<%= goma_config.authentication_keys.to_field_name %>])
|
16
16
|
@<%= resource_name %>.generate_confirmation_token
|
17
17
|
@<%= resource_name %>.send_activation_needed_email
|
18
18
|
|
@@ -20,8 +20,8 @@ class <%= controller_class_name %>Controller < ApplicationController
|
|
20
20
|
end
|
21
21
|
|
22
22
|
|
23
|
-
# GET <%= route_url %>/1
|
24
|
-
def
|
23
|
+
# GET <%= route_url %>/1
|
24
|
+
def show
|
25
25
|
@<%= resource_name %>, err = <%= resource_class_name %>.load_from_activation_token_with_error(params[:id])
|
26
26
|
|
27
27
|
if @<%= resource_name %>
|
@@ -38,8 +38,8 @@ class <%= controller_class_name %>Controller < ApplicationController
|
|
38
38
|
end
|
39
39
|
|
40
40
|
|
41
|
-
# GET <%= route_url %>/1/
|
42
|
-
def
|
41
|
+
# GET <%= route_url %>/1/email
|
42
|
+
def email
|
43
43
|
@<%= resource_name %>, err = <%= resource_class_name %>.load_from_email_confirmation_token_with_error(params[:id])
|
44
44
|
|
45
45
|
if @<%= resource_name %>
|
@@ -14,7 +14,7 @@ class <%= controller_class_name %>Controller < ApplicationController
|
|
14
14
|
else
|
15
15
|
<%=resource_name %> = <%= resource_class_name %>.create_with_omniauth!(omniauth)
|
16
16
|
end
|
17
|
-
|
17
|
+
force_login(<%= resource_name %>)
|
18
18
|
<%= specify_scope_if_needed %>redirect_back_or_to root_url, notice: "Successfully authenticated from #{omniauth[:provider]} account."
|
19
19
|
end
|
20
20
|
end
|
@@ -12,7 +12,7 @@ class <%= controller_class_name %>Controller < ApplicationController
|
|
12
12
|
|
13
13
|
# POST <%= route_url %>
|
14
14
|
def create
|
15
|
-
@<%= resource_name %> = <%= resource_class_name %>.find_by_identifier(params[
|
15
|
+
@<%= resource_name %> = <%= resource_class_name %>.find_by_identifier(params[:<%= goma_config.authentication_keys.to_field_name %>])
|
16
16
|
@<%= resource_name %>.send_reset_password_instructions! if @<%= resource_name %>
|
17
17
|
|
18
18
|
flash[:notice] = "You will receive an email with instructions about how to reset your password in a few minutes."
|
@@ -31,7 +31,7 @@ class <%= controller_class_name %>Controller < ApplicationController
|
|
31
31
|
if @<%= resource_name %>
|
32
32
|
@<%= resource_name %>.unlock_access! if @<%= resource_name %>.lockable? && @<%= resource_name %>.access_locked?
|
33
33
|
@<%= resource_name %>.change_password!(params[:<%= goma_config.password_attribute_name %>], params[:<%= goma_config.password_attribute_name %>_confirmation])
|
34
|
-
|
34
|
+
force_login(@<%= resource_name %>)
|
35
35
|
<%= specify_scope_if_needed %>redirect_back_or_to root_url, notice: 'Your password was changed successfully. You are now logged in.'
|
36
36
|
else
|
37
37
|
if err == :token_expired
|
@@ -13,7 +13,7 @@ class <%= controller_class_name %>Controller < ApplicationController
|
|
13
13
|
# POST <%= route_url %>
|
14
14
|
def create
|
15
15
|
<% if goma_config.modules.include? :confirmable -%>
|
16
|
-
if @<%= resource_name %> = <%= resource_name %>_login(params[
|
16
|
+
if @<%= resource_name %> = <%= resource_name %>_login(params[:<%= goma_config.authentication_keys.to_field_name %>], params[:<%= goma_config.password_attribute_name %>]<%= goma_config.modules.include?(:rememberable) ? ', params[:remember_me]' : '' %>)
|
17
17
|
<%= specify_scope_if_needed %>redirect_back_or_to root_url, notice: 'Login successful'
|
18
18
|
else
|
19
19
|
if goma_error(:<%= resource_name %>) == :not_activated
|
@@ -24,7 +24,7 @@ class <%= controller_class_name %>Controller < ApplicationController
|
|
24
24
|
render :new
|
25
25
|
end
|
26
26
|
<% else -%>
|
27
|
-
if @<%= resource_name %> = <%= resource_name %>_login(params[
|
27
|
+
if @<%= resource_name %> = <%= resource_name %>_login(params[:<%= goma_config.authentication_keys.to_field_name %>], params[:<%= goma_config.password_attribute_name %>])
|
28
28
|
<%= specify_scope_if_needed %>redirect_back_or_to root_url, notice: 'Login successful'
|
29
29
|
else
|
30
30
|
flash.now[:alert] = 'Login failed'
|
@@ -28,7 +28,7 @@ class <%= controller_class_name %>Controller < ApplicationController
|
|
28
28
|
|
29
29
|
# POST <%= route_url %>
|
30
30
|
def create
|
31
|
-
@<%= resource_name %> = <%= resource_class_name %>.find_by_identifier(params[
|
31
|
+
@<%= resource_name %> = <%= resource_class_name %>.find_by_identifier(params[:<%= goma_config.authentication_keys.to_field_name %>])
|
32
32
|
@<%= resource_name %>.send_unlock_instructions!
|
33
33
|
|
34
34
|
flash[:notice] = 'Instructions have been sent to your email.'
|
@@ -29,7 +29,12 @@ class <%= controller_class_name %>Controller < ApplicationController
|
|
29
29
|
@<%= singular_table_name %> = <%= orm_class.build(class_name, "#{singular_table_name}_params") %>
|
30
30
|
|
31
31
|
if @<%= orm_instance.save %>
|
32
|
-
|
32
|
+
<% if goma_config.modules.include?(:confirmable) && goma_config.allow_unactivated_access_for == 0 -%>
|
33
|
+
redirect_to <%= login_url %>, notice: "You have signed up successfully. However, we could not sign you in because your account is not yet activated. You will receive an email with instructions about how to activate your account in a few minutes."
|
34
|
+
<% else -%>
|
35
|
+
force_login(@<%= singular_table_name %>)
|
36
|
+
redirect_back_or_to root_url, notice: "Welcome! You have signed up successfully.<%= goma_config.modules.include?(:confirmable) ? ' You will receive an email with instructions about how to activate your account in a few minutes.' : '' %>"
|
37
|
+
<% end -%>
|
33
38
|
else
|
34
39
|
render :new
|
35
40
|
end
|