rails_jwt_auth 0.6.0 → 0.7.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6b162526193bd334a5f559b06df71fa65af2596e
4
- data.tar.gz: 39edbb7292698a62f424a94807295d0cb3941dc8
3
+ metadata.gz: 732cc9120a9c32603d50b8037cd0b38b03d5b0ae
4
+ data.tar.gz: e452f967009f3bb0d3764144e5c8db02c6ee47dc
5
5
  SHA512:
6
- metadata.gz: 56056babd43f0f71ef9b33990b4ba847986ae5d81dc49222f60f615709e6e64ebb4b2ff34551ae636008fe49171812e1d52bcb1bb84c60cb9a80495855886a1c
7
- data.tar.gz: 2c715028b96c35fc280030471a61ea13e646c9bf3b2a87476ad0f57926e19ec46cd34c3fa345c7838436d7e952c086243c3e742e038c984d7b733240e8b4ddd3
6
+ metadata.gz: 8fdb318be4a9616c94e295c3b7758c7baf642681985e752be68660e876a8fc44d13d07e781d6bc76036d03fd6adb5ef936e76f0085a79d4953d30cc92b832808
7
+ data.tar.gz: 8fc17cdbede35b8df01e91aabed6a0cf18bb90bd973be9cf119d49111ec62e97d6fd1c647998bb47c4d783136762cbc03dc05539a094209ad98a31287d725f07
data/README.md CHANGED
@@ -352,6 +352,10 @@ resource :registration, controller: 'registrations', only: [:create, :update, :d
352
352
 
353
353
  You can overwrite `RailsJwtAuth::RenderHelper` to customize controllers responses.
354
354
 
355
+ ## Custom strong parameters
356
+
357
+ You can overwrite `RailsJwtAuth::ParamsHelper` to customize controllers strong parameters.
358
+
355
359
  ## Testing (rspec)
356
360
 
357
361
  Require the RailsJwtAuth::Spec::Helpers helper module in `rails_helper.rb`.
@@ -0,0 +1,27 @@
1
+ module RailsJwtAuth
2
+ module ParamsHelper
3
+ private
4
+
5
+ def registration_create_params
6
+ params.require(RailsJwtAuth.model_name.underscore).permit(
7
+ RailsJwtAuth.auth_field_name, :password, :password_confirmation
8
+ )
9
+ end
10
+
11
+ def confirmation_create_params
12
+ params.require(:confirmation).permit(:email)
13
+ end
14
+
15
+ def session_create_params
16
+ params.require(:session).permit(RailsJwtAuth.auth_field_name, :password)
17
+ end
18
+
19
+ def password_create_params
20
+ params.require(:password).permit(:email)
21
+ end
22
+
23
+ def password_update_params
24
+ params.require(:password).permit(:password, :password_confirmation)
25
+ end
26
+ end
27
+ end
@@ -1,9 +1,10 @@
1
1
  module RailsJwtAuth
2
2
  class ConfirmationsController < ApplicationController
3
+ include ParamsHelper
3
4
  include RenderHelper
4
5
 
5
6
  def create
6
- user = RailsJwtAuth.model.where(email: confirmation_params[:email]).first
7
+ user = RailsJwtAuth.model.where(email: confirmation_create_params[:email]).first
7
8
  return render_422(email: [I18n.t('rails_jwt_auth.errors.not_found')]) unless user
8
9
 
9
10
  user.send_confirmation_instructions ? render_204 : render_422(user.errors)
@@ -15,11 +16,5 @@ module RailsJwtAuth
15
16
 
16
17
  user.confirm! ? render_204 : render_422(user.errors)
17
18
  end
18
-
19
- private
20
-
21
- def confirmation_params
22
- params.require(:confirmation).permit(:email)
23
- end
24
19
  end
25
20
  end
@@ -1,9 +1,10 @@
1
1
  module RailsJwtAuth
2
2
  class PasswordsController < ApplicationController
3
+ include ParamsHelper
3
4
  include RenderHelper
4
5
 
5
6
  def create
6
- user = RailsJwtAuth.model.where(email: create_password_params[:email]).first
7
+ user = RailsJwtAuth.model.where(email: password_create_params[:email]).first
7
8
  return render_422(email: [I18n.t('rails_jwt_auth.errors.not_found')]) unless user
8
9
 
9
10
  user.send_reset_password_instructions ? render_204 : render_422(user.errors)
@@ -13,17 +14,7 @@ module RailsJwtAuth
13
14
  user = RailsJwtAuth.model.where(reset_password_token: params[:reset_password_token]).first
14
15
  return render_422(reset_password_token: [I18n.t('rails_jwt_auth.errors.not_found')]) unless user
15
16
 
16
- user.update_attributes(update_password_params) ? render_204 : render_422(user.errors)
17
- end
18
-
19
- private
20
-
21
- def create_password_params
22
- params.require(:password).permit(:email)
23
- end
24
-
25
- def update_password_params
26
- params.require(:password).permit(:password, :password_confirmation)
17
+ user.update_attributes(password_update_params) ? render_204 : render_422(user.errors)
27
18
  end
28
19
  end
29
20
  end
@@ -1,19 +1,11 @@
1
1
  module RailsJwtAuth
2
2
  class RegistrationsController < ApplicationController
3
+ include ParamsHelper
3
4
  include RenderHelper
4
5
 
5
6
  def create
6
- user = RailsJwtAuth.model.new(create_params)
7
-
7
+ user = RailsJwtAuth.model.new(registration_create_params)
8
8
  user.save ? render_201(user) : render_422(user.errors)
9
9
  end
10
-
11
- private
12
-
13
- def create_params
14
- params.require(RailsJwtAuth.model_name.underscore).permit(
15
- RailsJwtAuth.auth_field_name, :password, :password_confirmation
16
- )
17
- end
18
10
  end
19
11
  end
@@ -3,18 +3,18 @@ require 'rails_jwt_auth/jwt/request'
3
3
 
4
4
  module RailsJwtAuth
5
5
  class SessionsController < ApplicationController
6
+ include ParamsHelper
6
7
  include RenderHelper
7
8
 
8
9
  def create
9
- user = RailsJwtAuth.model.where(
10
- RailsJwtAuth.auth_field_name => create_params[RailsJwtAuth.auth_field_name].to_s.downcase
11
- ).first
10
+ user = RailsJwtAuth.model.where(RailsJwtAuth.auth_field_name =>
11
+ session_create_params[RailsJwtAuth.auth_field_name].to_s.downcase).first
12
12
 
13
13
  if !user
14
14
  render_422 session: [create_session_error]
15
15
  elsif user.respond_to?('confirmed?') && !user.confirmed?
16
16
  render_422 session: [I18n.t('rails_jwt_auth.errors.unconfirmed')]
17
- elsif user.authenticate(create_params[:password])
17
+ elsif user.authenticate(session_create_params[:password])
18
18
  render_201 session: {jwt: get_jwt(user)}
19
19
  else
20
20
  render_422 session: [create_session_error]
@@ -33,10 +33,6 @@ module RailsJwtAuth
33
33
  RailsJwtAuth::Jwt::Manager.encode(auth_token: token)
34
34
  end
35
35
 
36
- def create_params
37
- params.require(:session).permit(RailsJwtAuth.auth_field_name, :password)
38
- end
39
-
40
36
  def create_session_error
41
37
  I18n.t('rails_jwt_auth.errors.create_session', field: RailsJwtAuth.auth_field_name)
42
38
  end
@@ -1,3 +1,3 @@
1
1
  module RailsJwtAuth
2
- VERSION = '0.6.0'
2
+ VERSION = '0.7.0'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails_jwt_auth
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.0
4
+ version: 0.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - rjurado
@@ -77,13 +77,14 @@ files:
77
77
  - MIT-LICENSE
78
78
  - README.md
79
79
  - Rakefile
80
+ - app/controllers/concerns/rails_jwt_auth/params_helper.rb
81
+ - app/controllers/concerns/rails_jwt_auth/render_helper.rb
82
+ - app/controllers/concerns/rails_jwt_auth/warden_helper.rb
80
83
  - app/controllers/rails_jwt_auth/confirmations_controller.rb
81
84
  - app/controllers/rails_jwt_auth/passwords_controller.rb
82
85
  - app/controllers/rails_jwt_auth/registrations_controller.rb
83
86
  - app/controllers/rails_jwt_auth/sessions_controller.rb
84
87
  - app/controllers/unauthorized_controller.rb
85
- - app/helpers/rails_jwt_auth/render_helper.rb
86
- - app/helpers/rails_jwt_auth/warden_helper.rb
87
88
  - app/mailers/rails_jwt_auth/mailer.rb
88
89
  - app/models/concerns/rails_jwt_auth/authenticatable.rb
89
90
  - app/models/concerns/rails_jwt_auth/confirmable.rb