nyauth 0.3.0 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (31) hide show
  1. checksums.yaml +4 -4
  2. data/app/controllers/nyauth/confirmation_requests_controller.rb +12 -9
  3. data/app/controllers/nyauth/registrations_controller.rb +7 -7
  4. data/app/controllers/nyauth/reset_password_requests_controller.rb +12 -9
  5. data/app/controllers/nyauth/sessions_controller.rb +7 -7
  6. data/app/services/nyauth/confirmation_request.rb +19 -0
  7. data/app/services/nyauth/registration.rb +22 -0
  8. data/app/services/nyauth/reset_password_request.rb +19 -0
  9. data/app/services/nyauth/{session_service.rb → session.rb} +4 -4
  10. data/app/views/nyauth/confirmation_requests/new.html.erb +1 -1
  11. data/app/views/nyauth/registrations/new.html.erb +1 -1
  12. data/app/views/nyauth/reset_password_requests/new.html.erb +1 -1
  13. data/app/views/nyauth/sessions/new.html.erb +1 -1
  14. data/config/locales/en.yml +1 -0
  15. data/config/locales/ja.yml +1 -0
  16. data/lib/nyauth/version.rb +1 -1
  17. data/spec/dummy/db/development.sqlite3 +0 -0
  18. data/spec/dummy/db/test.sqlite3 +0 -0
  19. data/spec/dummy/log/development.log +3645 -0
  20. data/spec/dummy/log/test.log +10449 -0
  21. data/spec/dummy/tmp/pids/server.pid +1 -0
  22. data/spec/featrues/nyauth/confirmation_requests_spec.rb +2 -2
  23. data/spec/featrues/nyauth/registrations_spec.rb +3 -3
  24. data/spec/featrues/nyauth/reset_password_requests_spec.rb +2 -2
  25. data/spec/featrues/nyauth/sessions_spec.rb +6 -6
  26. data/spec/lib/generators/nyauth/tmp/app/views/nyauth/confirmation_requests/new.html.erb +1 -1
  27. data/spec/lib/generators/nyauth/tmp/app/views/nyauth/registrations/new.html.erb +1 -1
  28. data/spec/lib/generators/nyauth/tmp/app/views/nyauth/reset_password_requests/new.html.erb +1 -1
  29. data/spec/lib/generators/nyauth/tmp/app/views/nyauth/sessions/new.html.erb +1 -1
  30. metadata +8 -4
  31. data/app/services/nyauth/confirmation_request_service.rb +0 -15
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 87601c468486a44c289a5237814b284c2ddd99a3
4
- data.tar.gz: 6a6b8354a185b0e79712b0ead1fb173a7277074c
3
+ metadata.gz: b179e705b0291eb4ab1cb5ceb28ed1ab60f6c36e
4
+ data.tar.gz: 789c2faca7c10305ecfdef41985394aeca889a4c
5
5
  SHA512:
6
- metadata.gz: faa4fe34f07107d34c8eec9afa935522bf28e29f5f78e60a391c4923a02009338b8398ebace396d42314535c21dd275f8aba592a5635d75bc6d9324760358c64
7
- data.tar.gz: 35c441c44d9e59689368b606fe49267e68ffb4bd6fab19708901472faaf1d95a60bcb0d8199384c13ba33faa9930ec4532161643d11afe0ab3f7c9731f4abb2d
6
+ metadata.gz: ae1e764608c2e31037aef15d9e52038f70de3f40b37998c30128078013abdb619a412c52ae63c073ed5fdd9280eb954a1c2bd498666eb251dfc5754e0efb3586
7
+ data.tar.gz: de4269ccf19ad4fb969f05f3b0ae33ca0fbdd846032f3f688c7fc182b0deb6f70a215ba0c6e74f471659a9dbba26c65c77fcd1db2afe84e500598a42912ba529
@@ -4,27 +4,30 @@ module Nyauth
4
4
  allow_everyone
5
5
  self.responder = Nyauth::AppResponder
6
6
  respond_to :html, :json
7
- before_action :set_client, only: [:create]
8
- after_action :send_mail, only: [:create], if: -> { @client.confirmation_key.present? }
7
+ before_action :set_service
8
+ after_action :send_mail, only: [:create], if: -> { @service.errors.blank? }
9
9
 
10
10
  def new
11
11
  end
12
12
 
13
13
  def create
14
- @client.request_confirmation
15
- respond_with(@client, location: Nyauth.configuration.redirect_path_after_create_request_confirmation.call(nyauth_client_name) || main_app.root_path)
14
+ @service.save(as: nyauth_client_name)
15
+ respond_with(@service, location: Nyauth.configuration.redirect_path_after_create_request_confirmation.call(nyauth_client_name) || main_app.root_path)
16
16
  end
17
17
 
18
18
  private
19
19
 
20
- def set_client
21
- @client = nyauth_client_class.find_by!(email: params[nyauth_client_name][:email])
22
- rescue ActiveRecord::RecordNotFound
23
- render :new
20
+ def set_service
21
+ @service = Nyauth::ConfirmationRequest.new(confirmation_request_params)
22
+ end
23
+
24
+ def confirmation_request_params
25
+ params.fetch(:confirmation_request, {})
26
+ .permit(:email)
24
27
  end
25
28
 
26
29
  def send_mail
27
- Nyauth::RequestMailer.request_confirmation(@client).deliver_now
30
+ Nyauth::RequestMailer.request_confirmation(@service.client).deliver_now
28
31
  end
29
32
  end
30
33
  end
@@ -4,24 +4,24 @@ module Nyauth
4
4
  allow_everyone
5
5
  self.responder = Nyauth::AppResponder
6
6
  respond_to :html, :json
7
- before_action :set_client
7
+ before_action :set_service
8
8
 
9
9
  def new
10
10
  end
11
11
 
12
12
  def create
13
- sign_in(@client) if @client.save
14
- respond_with(@client, location: Nyauth.configuration.redirect_path_after_registration.call(nyauth_client_name) || main_app.root_path)
13
+ sign_in(@service.client) if @service.save(as: nyauth_client_name)
14
+ respond_with @service, location: Nyauth.configuration.redirect_path_after_registration.call(nyauth_client_name) || main_app.root_path
15
15
  end
16
16
 
17
17
  private
18
18
 
19
- def set_client
20
- @client = nyauth_client_class.new(client_params)
19
+ def set_service
20
+ @service = Nyauth::Registration.new(registration_params)
21
21
  end
22
22
 
23
- def client_params
24
- params.fetch(nyauth_client_name, {})
23
+ def registration_params
24
+ params.fetch(:registration, {})
25
25
  .permit(:email, :password, :password_confirmation)
26
26
  end
27
27
  end
@@ -4,27 +4,30 @@ module Nyauth
4
4
  allow_everyone
5
5
  self.responder = Nyauth::AppResponder
6
6
  respond_to :html, :json
7
- before_action :set_client, only: [:create]
8
- after_action :send_mail, only: [:create], if: -> { @client.reset_password_key.present? }
7
+ before_action :set_service
8
+ after_action :send_mail, only: [:create], if: -> { @service.errors.blank? }
9
9
 
10
10
  def new
11
11
  end
12
12
 
13
13
  def create
14
- @client.request_reset_password
15
- respond_with(@client, location: Nyauth.configuration.redirect_path_after_reset_password_request.call(nyauth_client_name) || main_app.root_path)
14
+ @service.save(as: nyauth_client_name)
15
+ respond_with(@service, location: Nyauth.configuration.redirect_path_after_reset_password_request.call(nyauth_client_name) || main_app.root_path)
16
16
  end
17
17
 
18
18
  private
19
19
 
20
- def set_client
21
- @client = nyauth_client_class.find_by!(email: params[nyauth_client_name][:email])
22
- rescue ActiveRecord::RecordNotFound
23
- render :new
20
+ def set_service
21
+ @service = Nyauth::ResetPasswordRequest.new(reset_password_request_params)
22
+ end
23
+
24
+ def reset_password_request_params
25
+ params.fetch(:reset_password_request, {})
26
+ .permit(:email)
24
27
  end
25
28
 
26
29
  def send_mail
27
- Nyauth::RequestMailer.request_reset_password(@client).deliver_now
30
+ Nyauth::RequestMailer.request_reset_password(@service.client).deliver_now
28
31
  end
29
32
  end
30
33
  end
@@ -5,15 +5,15 @@ module Nyauth
5
5
  allow_everyone only: [:new, :create]
6
6
  self.responder = Nyauth::AppResponder
7
7
  respond_to :html, :json
8
- before_action :set_session_service
8
+ before_action :set_service
9
9
 
10
10
  def new
11
11
  end
12
12
 
13
13
  def create
14
- sign_in(@session_service.client) if @session_service.save(as: nyauth_client_name)
14
+ sign_in(@service.client) if @service.save(as: nyauth_client_name)
15
15
  redirect_path = session.delete("#{nyauth_client_name}_return_to")
16
- respond_with @session_service,
16
+ respond_with @service,
17
17
  location: redirect_path || \
18
18
  Nyauth.configuration.redirect_path_after_sign_in.call(nyauth_client_name) || \
19
19
  main_app.root_path
@@ -21,17 +21,17 @@ module Nyauth
21
21
 
22
22
  def destroy
23
23
  sign_out
24
- respond_with @session_service, location: Nyauth.configuration.redirect_path_after_sign_out.call(nyauth_client_name) || new_session_path_for(nyauth_client_name)
24
+ respond_with @service, location: Nyauth.configuration.redirect_path_after_sign_out.call(nyauth_client_name) || new_session_path_for(nyauth_client_name)
25
25
  end
26
26
 
27
27
  private
28
28
 
29
- def set_session_service
30
- @session_service = Nyauth::SessionService.new(session_service_params)
29
+ def set_service
30
+ @service = Nyauth::Session.new(session_service_params)
31
31
  end
32
32
 
33
33
  def session_service_params
34
- params.fetch(:session_service, {})
34
+ params.fetch(:session, {})
35
35
  .permit(:email, :password)
36
36
  end
37
37
  end
@@ -0,0 +1,19 @@
1
+ module Nyauth
2
+ class ConfirmationRequest
3
+ include ActiveModel::Model
4
+ attr_reader :email, :client
5
+
6
+ def initialize(service_params = {})
7
+ @email = service_params[:email]
8
+ end
9
+
10
+ def save(options = {})
11
+ options.reverse_merge!(as: :user)
12
+ klass = options[:as].to_s.classify.constantize
13
+ @client = klass.find_by!(email: @email)
14
+ @client.request_confirmation
15
+ rescue
16
+ errors.add(:base, :invalid_email)
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,22 @@
1
+ module Nyauth
2
+ class Registration
3
+ include ActiveModel::Model
4
+ attr_reader :email, :password, :password_confirmation, :client
5
+
6
+ def initialize(service_params = {})
7
+ @email = service_params[:email]
8
+ @password = service_params[:password]
9
+ @password_confirmation = service_params[:password_confirmation]
10
+ end
11
+
12
+ def save(options = {})
13
+ options.reverse_merge!(as: :user)
14
+ klass = options[:as].to_s.classify.constantize
15
+ @client = klass.create(email: @email,
16
+ password: @password,
17
+ password_confirmation: @password_confirmation)
18
+ @errors = @client.errors
19
+ @client.valid?
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,19 @@
1
+ module Nyauth
2
+ class ResetPasswordRequest
3
+ include ActiveModel::Model
4
+ attr_reader :email, :client
5
+
6
+ def initialize(service_params = {})
7
+ @email = service_params[:email]
8
+ end
9
+
10
+ def save(options = {})
11
+ options.reverse_merge!(as: :user)
12
+ klass = options[:as].to_s.classify.constantize
13
+ @client = klass.find_by!(email: @email)
14
+ @client.request_reset_password
15
+ rescue
16
+ errors.add(:base, :invalid_email)
17
+ end
18
+ end
19
+ end
@@ -1,11 +1,11 @@
1
1
  module Nyauth
2
- class SessionService
2
+ class Session
3
3
  include ActiveModel::Model
4
4
  attr_reader :email, :password, :client
5
5
 
6
- def initialize(session_service_params = {})
7
- @email = session_service_params[:email]
8
- @password = session_service_params[:password]
6
+ def initialize(service_params = {})
7
+ @email = service_params[:email]
8
+ @password = service_params[:password]
9
9
  end
10
10
 
11
11
  def save(options = {})
@@ -1,4 +1,4 @@
1
- <%= form_for nyauth_client_class.new, url: confirmation_requests_path_for(nyauth_client_name) do |f| %>
1
+ <%= form_for @service, url: confirmation_requests_path_for(nyauth_client_name) do |f| %>
2
2
  <%= f.email_field :email %>
3
3
  <%= f.submit 'request confirmation' %>
4
4
  <% end %>
@@ -1,4 +1,4 @@
1
- <%= form_for @client, url: registration_path_for(nyauth_client_name) do |f| %>
1
+ <%= form_for @service, url: registration_path_for(nyauth_client_name) do |f| %>
2
2
  <%= f.object.errors.full_messages.join ',' %>
3
3
  <%= f.email_field :email %>
4
4
  <%= f.password_field :password %>
@@ -1,4 +1,4 @@
1
- <%= form_for nyauth_client_class.new, url: reset_password_requests_path_for(nyauth_client_name) do |f| %>
1
+ <%= form_for @service, url: reset_password_requests_path_for(nyauth_client_name) do |f| %>
2
2
  <%= f.text_field :email %>
3
3
  <%= f.submit 'reset password' %>
4
4
  <% end %>
@@ -1,4 +1,4 @@
1
- <%= form_for @session_service, url: session_path_for(nyauth_client_name) do |f| %>
1
+ <%= form_for @service, url: session_path_for(nyauth_client_name) do |f| %>
2
2
  <%= f.object.errors.full_messages.join ',' %>
3
3
  <%= f.email_field :email %>
4
4
  <%= f.password_field :password %>
@@ -31,3 +31,4 @@ en:
31
31
  errors:
32
32
  messages:
33
33
  invalid_email_or_password: 'Invalid email or password'
34
+ invalid_email: 'Invalid email'
@@ -31,3 +31,4 @@ ja:
31
31
  errors:
32
32
  messages:
33
33
  invalid_email_or_password: 'ログイン情報に誤りがあります'
34
+ invalid_email: 'メールアドレスに誤りがあります'
@@ -1,3 +1,3 @@
1
1
  module Nyauth
2
- VERSION = "0.3.0"
2
+ VERSION = "0.4.0"
3
3
  end
Binary file
Binary file