goma 0.0.1.gamma → 0.0.1.rc1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (57) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +0 -1
  3. data/Gemfile.lock +13 -9
  4. data/Rakefile +14 -0
  5. data/goma.gemspec +6 -0
  6. data/lib/generators/goma/erb/templates/confirmation/new.html.erb +2 -2
  7. data/lib/generators/goma/erb/templates/password/edit.html.erb +6 -6
  8. data/lib/generators/goma/erb/templates/unlock/new.html.erb +1 -1
  9. data/lib/generators/goma/erb/templates/user/_form.html.erb +1 -1
  10. data/lib/generators/goma/erb/templates/user/new.html.erb +4 -0
  11. data/lib/generators/goma/mailer/erb/templates/activation_needed_email.text.erb +1 -1
  12. data/lib/generators/goma/model/active_record_generator.rb +1 -0
  13. data/lib/generators/goma/model/oauth/active_record_generator.rb +3 -3
  14. data/lib/generators/goma/resource_route/resource_route_generator.rb +13 -9
  15. data/lib/generators/goma/scaffold_controller/templates/confirmation_controller.rb +8 -4
  16. data/lib/generators/goma/scaffold_controller/templates/oauth_controller.rb +5 -0
  17. data/lib/generators/goma/scaffold_controller/templates/password_controller.rb +9 -4
  18. data/lib/generators/goma/scaffold_controller/templates/unlock_controller.rb +1 -0
  19. data/lib/generators/goma/scaffold_controller/templates/user_controller.rb +41 -1
  20. data/lib/goma/config.rb +4 -4
  21. data/lib/goma/models/authenticatable.rb +20 -9
  22. data/lib/goma/models/confirmable.rb +15 -9
  23. data/lib/goma/models/password_authenticatable.rb +2 -1
  24. data/lib/goma/models/recoverable.rb +1 -1
  25. data/lib/goma/models/validatable.rb +4 -4
  26. data/lib/goma/railtie.rb +1 -0
  27. data/lib/goma/version.rb +1 -1
  28. data/test/integration/confirmable_integration_test.rb +185 -0
  29. data/test/integration/lockable_integration_test.rb +49 -0
  30. data/test/integration/omniauthable_integration_test.rb +64 -12
  31. data/test/integration/password_authenticatable_integration_test.rb +40 -0
  32. data/test/integration/recoverable_integration_test.rb +96 -0
  33. data/test/integration/rememberable_integration_test.rb +14 -0
  34. data/test/models/confirmable_test.rb +6 -6
  35. data/test/models/omniauthable_test.rb +2 -2
  36. data/test/rails_app/app/controllers/authentications_controller.rb +5 -0
  37. data/test/rails_app/app/controllers/confirmations_controller.rb +8 -4
  38. data/test/rails_app/app/controllers/passwords_controller.rb +9 -4
  39. data/test/rails_app/app/controllers/unlocks_controller.rb +1 -0
  40. data/test/rails_app/app/controllers/users_controller.rb +25 -2
  41. data/test/rails_app/app/views/confirmations/new.html.erb +2 -2
  42. data/test/rails_app/app/views/layouts/application.html.erb +3 -1
  43. data/test/rails_app/app/views/passwords/edit.html.erb +6 -6
  44. data/test/rails_app/app/views/unlocks/new.html.erb +1 -1
  45. data/test/rails_app/app/views/user_mailer/activation_needed_email.text.erb +1 -1
  46. data/test/rails_app/app/views/users/_form.html.erb +1 -1
  47. data/test/rails_app/app/views/users/new.html.erb +1 -0
  48. data/test/rails_app/config/initializers/omniauth.rb +0 -1
  49. data/test/rails_app/config/routes.rb +6 -10
  50. data/test/rails_app/db/migrate/{20140512081308_create_users.rb → 20140515111009_create_users.rb} +0 -0
  51. data/test/rails_app/db/migrate/{20140512081309_create_authentications.rb → 20140515111010_create_authentications.rb} +0 -0
  52. data/test/rails_app/db/schema.rb +1 -1
  53. data/test/test_helper.rb +43 -0
  54. metadata +33 -13
  55. data/test/controllers/confirmations_controller_test.rb +0 -14
  56. data/test/controllers/users_controller_test.rb +0 -12
  57. data/test/integration/authenticatable_integration_test.rb +0 -26
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a89f50e2d41994b88fc95fbc6c981684f8a71043
4
- data.tar.gz: 0d9c4bb7dd2dfd2836b903d62fd5689d7bee43ed
3
+ metadata.gz: 5ef7018f710a582f625d31c0933a64ca21c04ae6
4
+ data.tar.gz: f74640b684a0feaef3146ff6ab537e46c7009b8b
5
5
  SHA512:
6
- metadata.gz: e1e4c13eb562fc355eb35effae5a44eca9f4f0e29d50ed69de2687689893609ef14ccc234d42eb9290b59f87091d1a596f9453405dcdaa701191fb864e5ba20d
7
- data.tar.gz: 141f626b7c5a22e697bab9b7c63a4c335872e8b024be56c8e68a09e58ba9f44c464df38af417afb87d171a58c87ee1d1d30eee306ba4d788b87f82125abb840a
6
+ metadata.gz: 9d68a65ac82a574ab10110551e453aee53dac951d96c4cdee43822e47b86231fb554615635d1449ef690a5124f3a5f80afc8cd29fcd57ad2ac8f9e847639a9e8
7
+ data.tar.gz: a2f9662edacd4404694af19493b9e626319ee4fbe985c7c7fb3c8f05d07275f966dcebb56ab3212c021054ee1cd5009f3e275440c5826f19904776d78f1bf7dd
data/Gemfile CHANGED
@@ -15,5 +15,4 @@ gemspec
15
15
 
16
16
  group :development, :test do
17
17
  gem 'omniauth'
18
- gem 'omniauth-twitter'
19
18
  end
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- goma (0.0.1.gamma)
4
+ goma (0.0.1.rc1)
5
5
  rails (~> 4.0)
6
6
  warden
7
7
 
@@ -39,6 +39,12 @@ GEM
39
39
  byebug (3.1.2)
40
40
  columnize (~> 0.8)
41
41
  debugger-linecache (~> 1.2)
42
+ capybara (2.2.1)
43
+ mime-types (>= 1.16)
44
+ nokogiri (>= 1.3.3)
45
+ rack (>= 1.0.0)
46
+ rack-test (>= 0.5.4)
47
+ xpath (~> 2.0)
42
48
  columnize (0.8.9)
43
49
  debugger-linecache (1.2.0)
44
50
  erubis (2.7.0)
@@ -51,6 +57,7 @@ GEM
51
57
  treetop (~> 1.4.8)
52
58
  metaclass (0.0.4)
53
59
  mime-types (1.25.1)
60
+ mini_portile (0.6.0)
54
61
  minitest (4.7.5)
55
62
  minitest-ansi (0.1.3)
56
63
  ansi (~> 1.3)
@@ -58,16 +65,11 @@ GEM
58
65
  mocha (1.0.0)
59
66
  metaclass (~> 0.0.1)
60
67
  multi_json (1.9.3)
61
- oauth (0.4.7)
68
+ nokogiri (1.6.2.1)
69
+ mini_portile (= 0.6.0)
62
70
  omniauth (1.2.1)
63
71
  hashie (>= 1.2, < 3)
64
72
  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)
71
73
  polyglot (0.3.4)
72
74
  rack (1.5.2)
73
75
  rack-test (0.6.2)
@@ -109,6 +111,8 @@ GEM
109
111
  tzinfo (0.3.39)
110
112
  warden (1.2.3)
111
113
  rack (>= 1.0)
114
+ xpath (2.0.0)
115
+ nokogiri (~> 1.3)
112
116
 
113
117
  PLATFORMS
114
118
  ruby
@@ -116,12 +120,12 @@ PLATFORMS
116
120
  DEPENDENCIES
117
121
  bcrypt (~> 3.0)
118
122
  byebug
123
+ capybara
119
124
  fabrication
120
125
  goma!
121
126
  minitest-ansi
122
127
  mocha
123
128
  omniauth
124
- omniauth-twitter
125
129
  shoulda-context
126
130
  single_test
127
131
  sqlite3
data/Rakefile CHANGED
@@ -29,5 +29,19 @@ Rake::TestTask.new(:test) do |t|
29
29
  t.verbose = false
30
30
  end
31
31
 
32
+ desc "Rebuild test app's resources"
33
+ task "rebuild_test_app" do
34
+ migration = 'migrate' == ARGV.last ? '' : ' --no-migration'
35
+ cd "test/rails_app"
36
+ sh "bundle exec rails d goma:scaffold User#{migration}"
37
+ sh "bundle exec rails g goma:scaffold User#{migration}"
38
+ if migration.empty?
39
+ sh "RAILS_ENV=test bundle exec rake db:drop"
40
+ sh "RAILS_ENV=test bundle exec rake db:create"
41
+ sh "RAILS_ENV=test bundle exec rake db:migrate"
42
+ end
43
+ sh "rm -rf test/*"
44
+ cd "../.."
45
+ end
32
46
 
33
47
  task default: :test
data/goma.gemspec CHANGED
@@ -49,6 +49,11 @@ That's it.
49
49
  This gem is in early development phase and I do not recommend you to use this for production for a while.
50
50
  Bug reports and pull requests are welcome.
51
51
 
52
+ I am surprised that this gem has been downloaded over 200 times, in spite of pre release versions of v0.0.1.
53
+ And, I feel bad about there were lots of bugs and incomplete implementations in previous versions.
54
+
55
+ I will release this as a release candidate, but will add lots of code before v0.0.1.
56
+
52
57
  Enjoy!\e[0m
53
58
  MESSAGE
54
59
 
@@ -61,6 +66,7 @@ MESSAGE
61
66
  s.add_development_dependency "mocha"
62
67
  s.add_development_dependency "shoulda-context"
63
68
  s.add_development_dependency "timecop"
69
+ s.add_development_dependency "capybara"
64
70
  s.add_development_dependency "minitest-ansi"
65
71
  s.add_development_dependency "single_test"
66
72
  s.add_development_dependency "byebug"
@@ -1,9 +1,9 @@
1
1
  <h1>Resend activation instructions</h1>
2
2
 
3
- <%%= form_tag(:<%= name.underscore.pluralize %>_url, method: :post) do %>
3
+ <%%= form_tag(<%= name.underscore.pluralize %>_url, method: :post) do %>
4
4
  <div class="field">
5
5
  <%%= label_tag :<%= goma_config.authentication_keys.to_field_name %> %><br>
6
- <%%= text_field_tag :<%= goma_config.authentication_keys.to_field_name %>
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" %>
@@ -1,18 +1,18 @@
1
1
  <h1>Change your password</h1>
2
2
 
3
- <%%= form_for(@<%= singular_table_name %>) do |f| %>
4
- <%% if @<%= singular_table_name %>.errors.any? %>
3
+ <%%= form_for(@<%= resource_name %>, url: <%= singular_table_name %>_url, html: {method: :put}) do |f| %>
4
+ <%% if @<%= resource_name %> && @<%= resource_name %>.errors.any? %>
5
5
  <div id="error_explanation">
6
- <h2><%%= pluralize(@<%= singular_table_name %>.errors.count, "error") %> prohibited this <%= singular_table_name %> from being saved:</h2>
6
+ <h2><%%= pluralize(@<%= resource_name %>.errors.count, "error") %> prohibited this <%= resource_name %> from being saved:</h2>
7
7
 
8
8
  <ul>
9
- <%% @<%= singular_table_name %>.errors.full_messages.each do |msg| %>
9
+ <%% @<%= resource_name %>.errors.full_messages.each do |msg| %>
10
10
  <li><%%= msg %></li>
11
11
  <%% end %>
12
12
  </ul>
13
13
  </div>
14
14
  <%% end %>
15
-
15
+ <%%= f.hidden_field :<%= goma_config.reset_password_token_to_send_attribute_name %> %>
16
16
  <div class="field">
17
17
  <%%= f.label :<%= goma_config.password_attribute_name %> %><br>
18
18
  <%%= f.password_field :<%= goma_config.password_attribute_name %> %>
@@ -22,6 +22,6 @@
22
22
  <%%= f.password_field :<%= goma_config.password_attribute_name %>_confirmation %>
23
23
  </div>
24
24
  <div class="actions">
25
- <%%= f.submit %>
25
+ <%%= f.submit 'Change my password' %>
26
26
  </div>
27
27
  <%% end %>
@@ -3,7 +3,7 @@
3
3
  <%%= form_tag(<%= name.underscore.pluralize%>_url, method: :post) do %>
4
4
  <div class="field">
5
5
  <%%= label_tag :<%= goma_config.authentication_keys.to_field_name %> %><br>
6
- <%%= text_field_tag :<%= goma_config.authentication_keys.to_field_name %>
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" %>
@@ -37,6 +37,6 @@
37
37
  </div>
38
38
  <% end -%>
39
39
  <div class="actions">
40
- <%%= f.submit %>
40
+ <%%= f.submit ( @<%= singular_table_name %>.try(:persisted?) ? 'Update' : 'Sign up' ) %>
41
41
  </div>
42
42
  <%% end %>
@@ -1,5 +1,9 @@
1
1
  <h1>New <%= singular_table_name %></h1>
2
2
 
3
3
  <%%= render 'form' %>
4
+ <% auth_keys = goma_config.authentication_keys - [goma_config.email_attribute_name] -%>
5
+ <% if goma_config.modules.include?(:confirmable) && auth_keys.present? -%>
6
+ * If you signed up with wrong email address, please enter correct email address and <%= auth_keys.join(', ') %> and password your entered when you signed up and click 'Sign up' again.
7
+ <% end -%>
4
8
 
5
9
  <%%= link_to 'Back', <%= index_helper %>_path %>
@@ -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
- <%%= activate_confirmation_url(@<%= resource_name %>.<%= goma_config.confirmation_token_to_send_attribute_name %>) %>
6
+ <%%= confirmation_url(@<%= resource_name %>.<%= goma_config.confirmation_token_to_send_attribute_name %>) %>
@@ -13,6 +13,7 @@ module Goma
13
13
  end
14
14
 
15
15
  def add_options_to_migration
16
+ return unless options['migration']
16
17
  if path = self.class.migration_exists?('db/migrate', migration_file_name)
17
18
  gsub_file(path,
18
19
  "t.integer :#{goma_config.failed_attempts_attribute_name}",
@@ -25,9 +25,9 @@ module Goma
25
25
  end
26
26
 
27
27
  def inject_index
28
- # if path = self.class.migration_exists('db/migrate', migration_file_name)
29
- if behavior == :invoke
30
- insert_into_file("db/migrate/#{migration_number}_#{migration_file_name}.rb", goma_oauth_index, {after: /^\s{4,}end\s*\n/})
28
+ return unless options['migration']
29
+ if path = self.class.migration_exists?('db/migrate', migration_file_name)
30
+ insert_into_file(path, goma_oauth_index, {after: /^\s{4,}end\s*\n/})
31
31
  end
32
32
  end
33
33
 
@@ -42,8 +42,11 @@ module Goma
42
42
  end
43
43
 
44
44
  def resource_definition
45
- if options[:controller_type] == 'session'
45
+ case options[:controller_type]
46
+ when 'session'
46
47
  "resource :#{file_name.singularize}"
48
+ when 'oauth'
49
+ ''
47
50
  else
48
51
  "resources :#{file_name.pluralize}"
49
52
  end
@@ -57,8 +60,6 @@ module Goma
57
60
  ', only: [:show, :new, :create]'
58
61
  when 'password'
59
62
  ', only: [:new, :create, :edit, :update]'
60
- when 'oauth'
61
- ', only: [:create]'
62
63
  else
63
64
  ''
64
65
  end
@@ -67,13 +68,16 @@ module Goma
67
68
  def appending_string
68
69
  if options[:controller_type] == 'confirmation' &&
69
70
  goma_config.modules.include?(:confirmable) && goma_config.email_confirmation_enabled
70
- strings = []
71
- strings << ' do'
72
- strings << ' get :email, on: :member'
73
- strings << 'end'
74
- strings.join("\n")
71
+ <<-BLOCK.strip_heredoc
72
+ do
73
+ get :email, on: :member
74
+ end
75
+ BLOCK
75
76
  elsif options[:controller_type] == 'oauth'
76
- "\nget '/auth/:provider/callback', to: '#{file_name.pluralize}#create'"
77
+ <<-RUBY.strip_heredoc
78
+ get '/auth/:provider/callback', to: '#{file_name.pluralize}#create'
79
+ get '/auth/failure', to: '#{file_name.pluralize}#failure'
80
+ RUBY
77
81
  end
78
82
  end
79
83
  end
@@ -13,8 +13,7 @@ class <%= controller_class_name %>Controller < ApplicationController
13
13
  # POST <%= route_url %>
14
14
  def create
15
15
  @<%= resource_name %> = <%= resource_class_name %>.find_by_identifier(params[:<%= goma_config.authentication_keys.to_field_name %>])
16
- @<%= resource_name %>.generate_confirmation_token
17
- @<%= resource_name %>.send_activation_needed_email
16
+ @<%= resource_name %>.resend_activation_needed_email
18
17
 
19
18
  redirect_to <%= login_url %>, notice: "We are processing your request. You will receive new activation email in a few minutes."
20
19
  end
@@ -44,14 +43,19 @@ class <%= controller_class_name %>Controller < ApplicationController
44
43
 
45
44
  if @<%= resource_name %>
46
45
  @<%= resource_name %>.confirm_email!
47
- redirect_to edit_<%= resource_name %>_url, notice: 'Your new email was successfully confirmed.'
46
+ redirect_to root_url, notice: 'Your new email was successfully confirmed.'
48
47
  else
49
48
  if err == :token_expired
50
49
  flash.now[:alert] = "Your email confirmation URL has expired, please change your email again."
51
50
  else
52
51
  flash.now[:alert] = "Email confirmation failed. Please make sure you used the full URL provided."
53
52
  end
54
- render edit_<%= resource_name%>_url(current_<%= resource_name %>)
53
+
54
+ if current_<%= resource_name %>
55
+ render edit_<%= resource_name%>_url(current_<%= resource_name %>)
56
+ else
57
+ render root_url
58
+ end
55
59
  end
56
60
  end
57
61
  end
@@ -17,5 +17,10 @@ class <%= controller_class_name %>Controller < ApplicationController
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
+
21
+ def failure
22
+ flash[:alert] = "Could not authenticate you from #{params[:strategy].capitalize} because \"#{params[:message].humanize}\"."
23
+ redirect_to <%= login_url %>
24
+ end
20
25
  end
21
26
  <% end -%>
@@ -21,16 +21,17 @@ class <%= controller_class_name %>Controller < ApplicationController
21
21
 
22
22
  # GET <%= route_url %>/1/edit
23
23
  def edit
24
- @reset_password_token = params[:id]
24
+ @<%= resource_name %> = <%= resource_class_name %>.new
25
+ @<%= resource_name %>.<%= goma_config.reset_password_token_to_send_attribute_name %> = params[:id]
25
26
  end
26
27
 
27
28
  # PATCH/PUT <%= route_url %>/1
28
29
  def update
29
- @<%= resource_name %>, err = <%= resource_class_name %>.load_from_reset_password_token_with_error(params[:id])
30
+ @<%= resource_name %>, err = <%= resource_class_name %>.load_from_reset_password_token_with_error(params[:<%= resource_name %>][:<%= goma_config.reset_password_token_to_send_attribute_name %>])
30
31
 
31
32
  if @<%= resource_name %>
32
33
  @<%= resource_name %>.unlock_access! if @<%= resource_name %>.lockable? && @<%= resource_name %>.access_locked?
33
- @<%= resource_name %>.change_password!(params[:<%= goma_config.password_attribute_name %>], params[:<%= goma_config.password_attribute_name %>_confirmation])
34
+ @<%= resource_name %>.change_password!(params[:<%= resource_name %>][:<%= goma_config.password_attribute_name %>], params[:<%= resource_name %>][:<%= goma_config.password_attribute_name %>_confirmation])
34
35
  force_login(@<%= resource_name %>)
35
36
  <%= specify_scope_if_needed %>redirect_back_or_to root_url, notice: 'Your password was changed successfully. You are now logged in.'
36
37
  else
@@ -38,10 +39,14 @@ class <%= controller_class_name %>Controller < ApplicationController
38
39
  flash.now[:alert] = "The password reset URL you visited has expired, please request a new one."
39
40
  render :new
40
41
  else
41
- flash.now[:alert] = "You can't access this page without comming from a password reset email. If you do come from a password reset email, please make sure you used the full URL provided."
42
+ @<%= resource_name %> = <%= resource_class_name %>.new
43
+ flash.now[:alert] = "You can't change your password in this page without coming from a password reset email. If you do come from a password reset email, please make sure you used the full URL provided."
42
44
  render :edit
43
45
  end
44
46
  end
47
+ rescue ActiveRecord::RecordInvalid
48
+ @<%= resource_name %>.<%= goma_config.reset_password_token_to_send_attribute_name %> = params[:<%= resource_name %>][:<%= goma_config.reset_password_token_to_send_attribute_name %>]
49
+ render :edit
45
50
  end
46
51
  end
47
52
  <% end -%>
@@ -9,6 +9,7 @@ class <%= controller_class_name %>Controller < ApplicationController
9
9
  def show
10
10
  @<%= resource_name %>, err = <%= resource_class_name %>.load_from_unlock_token_with_error(params[:id])
11
11
  if @<%= resource_name %>
12
+ @<%= resource_name %>.unlock_access!
12
13
  flash[:notice] = "Your account has been unlocked successfully. Please continue to login."
13
14
  redirect_to <%= login_url %>
14
15
  else
@@ -4,6 +4,7 @@ require_dependency "<%= namespaced_file_path %>/application_controller"
4
4
  <% end -%>
5
5
  <% module_namespacing do -%>
6
6
  class <%= controller_class_name %>Controller < ApplicationController
7
+ before_action <%= (singular_table_name == Goma.config.default_scope && !Helpers.include_scope_name_into_controller_name) ? ':require_login' : ":require_#{singular_table_name}_login" %>, only: [:edit, :update, :destroy]
7
8
  before_action :set_<%= singular_table_name %>, only: [:show, :edit, :update, :destroy]
8
9
 
9
10
  # GET <%= route_url %>
@@ -22,6 +23,7 @@ class <%= controller_class_name %>Controller < ApplicationController
22
23
 
23
24
  # GET <%= route_url %>/1/edit
24
25
  def edit
26
+ <%= goma_config.not_authenticated_action %> unless current_user = @user
25
27
  end
26
28
 
27
29
  # POST <%= route_url %>
@@ -36,14 +38,27 @@ class <%= controller_class_name %>Controller < ApplicationController
36
38
  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
39
  <% end -%>
38
40
  else
41
+ <% if goma_config.modules.include?(:confirmable) &&
42
+ (auth_keys = goma_config.authentication_keys - [goma_config.email_attribute_name]).present? -%>
43
+ update_email or render :new
44
+ <% else -%>
39
45
  render :new
46
+ <% end -%>
40
47
  end
41
48
  end
42
49
 
43
50
  # PATCH/PUT <%= route_url %>/1
44
51
  def update
52
+ <%= goma_config.not_authenticated_action %> unless current_user = @user
45
53
  if @<%= orm_instance.update("#{singular_table_name}_params") %>
46
- redirect_to @<%= singular_table_name %>, notice: <%= "'#{human_name} was successfully updated.'" %>
54
+ <% if goma_config.modules.include?(:confirmable) && goma_config.email_confirmation_enabled -%>
55
+ flash[:notice] = @<%= singular_table_name %>.<%= goma_config.confirmation_token_to_send_attribute_name %> ?
56
+ 'You updated your account successfully, but we need to verify your new email address. Please check your email and click on the confirmation link to finalize confirming your new email address.' :
57
+ 'You updated your account successfully'
58
+ redirect_to @<%= singular_table_name %>
59
+ <% else -%>
60
+ redirect_to @<%= singular_table_name %>, notice:'You updated your account successfully'
61
+ <% end -%>
47
62
  else
48
63
  render :edit
49
64
  end
@@ -51,6 +66,7 @@ class <%= controller_class_name %>Controller < ApplicationController
51
66
 
52
67
  # DELETE <%= route_url %>/1
53
68
  def destroy
69
+ <%= goma_config.not_authenticated_action %> unless current_user = @user
54
70
  @<%= orm_instance.destroy %>
55
71
  redirect_to <%= index_helper %>_url, notice: <%= "'#{human_name} was successfully destroyed.'" %>
56
72
  end
@@ -65,5 +81,29 @@ class <%= controller_class_name %>Controller < ApplicationController
65
81
  def <%= "#{singular_table_name}_params" %>
66
82
  params.require(:<%= singular_table_name %>).permit(<%= (resource_attributes + attributes_names).map { |name| ":#{name}" }.join(', ') %>)
67
83
  end
84
+ <% if goma_config.modules.include?(:confirmable) && auth_keys.present? -%>
85
+
86
+ def update_email
87
+ <% if auth_keys.length == 1 -%>
88
+ @<%= singular_table_name %> = <%= class_name %>.find_by(<%= auth_keys.first %>: params[:<%= singular_table_name %>][:<%= auth_keys.first %>])
89
+ <% else -%>
90
+ [<%= auth_keys.map{|k| ":#{k}"}.join(', ') %>].each do |key|
91
+ break if @<%= singular_table_name %> = <%= class_name %>.find_by(key => params[:<%= singular_table_name %>][key])
92
+ end
93
+ <% end -%>
94
+ if @<%= singular_table_name %>.activated?
95
+ return false
96
+ end
97
+
98
+ if ( Time.now <= @<%= singular_table_name %>.<%= goma_config.confirmation_token_sent_at_attribute_name %> + <%= goma_config.activate_within %> ) &&
99
+ !@<%= singular_table_name %>.valid_password?(params[:<%= singular_table_name %>][:<%= goma_config.password_attribute_name %>])
100
+ flash[:alert] = 'This username was already registered. If you want to change your email address, please make sure you entered correct password.'
101
+ return false
102
+ end
103
+
104
+ @<%= singular_table_name %>.resend_activation_needed_email(to: params[:<%= singular_table_name %>][:<%= goma_config.email_attribute_name %>])
105
+ redirect_to <%= login_url %>
106
+ end
107
+ <% end -%>
68
108
  end
69
109
  <% end -%>