rails_jwt_auth 0.3.2 → 0.4.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: b96c7a63119aa045fa08e184f4ab932fbcaf4b1b
4
- data.tar.gz: 0d2823aee7a5f58f4586f03769bcba83e9dd96ef
3
+ metadata.gz: 3494e45b64c0d552272f8e20af88201294d4bf68
4
+ data.tar.gz: 3930404dd79c4d8c6807451579289f13085c4199
5
5
  SHA512:
6
- metadata.gz: b6165a6384a25f04e987da4a7e41dad7336fdeb830934cff72875412846aa43900e5ee3b9c11e0e77987decef9c8505f3b8e72bdd37ad4700a2f4c746a6faad1
7
- data.tar.gz: 6b49902ab3d1c3f88409c7ccda8bc3008268d59a5a812961eab9797a010686e6b713eefb80e2f61637b141a519f0e441b54fb4b1b69b5a6f0b1a2ef4ba95f913
6
+ metadata.gz: 0391f7c10a5819b25b42511b1546566e730e4145082bd8237aa5b6050874a493ca7816a803139c3eba336b53ca1a30d418d493ce341e14b1146fa901dd3ad7be
7
+ data.tar.gz: afae862ba2e5714b56a76206ee940c7d5f53ccfc77d5f65baea5a1d31d1a372eaf79649abc03a54d2fa4e47fbbeb7b2fb3876e848afd87f1295e22b9b8d40477
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # RailsJwtAuth
2
2
 
3
- Rails authentication solution based on Warden and JWT and inspired by Devise.
3
+ Rails-API authentication solution based on Warden and JWT and inspired by Devise.
4
4
 
5
5
  ## Installation
6
6
 
@@ -267,7 +267,7 @@ Confirmation api is defined by RailsJwtAuth::ConfirmationsController.
267
267
  ```js
268
268
  {
269
269
  url: host/confirmation,
270
- method: GET
270
+ method: PUT
271
271
  data: {
272
272
  confirmation_token: "token"
273
273
  }
@@ -1,23 +1,21 @@
1
1
  class RailsJwtAuth::ConfirmationsController < ApplicationController
2
- def show
3
- return render json: {}, status: 400 unless params[:confirmation_token]
2
+ def create
3
+ user = RailsJwtAuth.model.where(email: confirmation_params[:email]).first
4
+ return render json: create_error_response, status: 422 unless user
5
+
6
+ user.send_confirmation_instructions
7
+ render json: {}, status: 204
8
+ end
4
9
 
5
- user = RailsJwtAuth.model.find_by!(confirmation_token: params[:confirmation_token])
10
+ def update
11
+ user = RailsJwtAuth.model.where(confirmation_token: params[:confirmation_token]).first
12
+ return render json: update_error_response(nil), status: 422 unless user
6
13
 
7
14
  if user.confirm!
8
15
  render json: {}, status: 204
9
16
  else
10
- render json: show_error_response(user), status: 422
11
- end
12
- end
13
-
14
- def create
15
- unless (user = RailsJwtAuth.model.where(email: confirmation_params[:email]).first)
16
- return render json: create_error_response, status: 422
17
+ render json: update_error_response(user), status: 422
17
18
  end
18
-
19
- user.send_confirmation_instructions
20
- render json: {}, status: 204
21
19
  end
22
20
 
23
21
  private
@@ -26,11 +24,15 @@ class RailsJwtAuth::ConfirmationsController < ApplicationController
26
24
  params.require(:confirmation).permit(:email)
27
25
  end
28
26
 
29
- def show_error_response(user)
30
- {errors: user.errors}
31
- end
32
-
33
27
  def create_error_response
34
28
  {errors: {email: [I18n.t('rails_jwt_auth.errors.not_found')]}}
35
29
  end
30
+
31
+ def update_error_response(user)
32
+ if user
33
+ {errors: user.errors}
34
+ else
35
+ {errors: {confirmation_token: [I18n.t('rails_jwt_auth.errors.not_found')]}}
36
+ end
37
+ end
36
38
  end
@@ -1,15 +1,15 @@
1
1
  class RailsJwtAuth::PasswordsController < ApplicationController
2
2
  def create
3
- unless (user = RailsJwtAuth.model.where(email: create_password_params[:email]).first)
4
- return render json: create_error_response, status: 422
5
- end
3
+ user = RailsJwtAuth.model.where(email: create_password_params[:email]).first
4
+ return render json: create_error_response, status: 422 unless user
6
5
 
7
6
  user.send_reset_password_instructions
8
7
  render json: {}, status: 204
9
8
  end
10
9
 
11
10
  def update
12
- user = RailsJwtAuth.model.find_by!(reset_password_token: params[:reset_password_token])
11
+ user = RailsJwtAuth.model.where(reset_password_token: params[:reset_password_token]).first
12
+ return render json: update_error_response(nil), status: 422 unless user
13
13
 
14
14
  if user.update_attributes(update_password_params)
15
15
  render json: {}, status: 204
@@ -33,6 +33,10 @@ class RailsJwtAuth::PasswordsController < ApplicationController
33
33
  end
34
34
 
35
35
  def update_error_response(user)
36
- {errors: user.errors}
36
+ if user
37
+ {errors: user.errors}
38
+ else
39
+ {errors: {reset_password_token: [I18n.t('rails_jwt_auth.errors.not_found')]}}
40
+ end
37
41
  end
38
42
  end
@@ -31,20 +31,20 @@ module RailsJwtAuth
31
31
  RailsJwtAuth::Jwt::Manager.encode(auth_token: token)
32
32
  end
33
33
 
34
- def unconfirmed_error_response
35
- {errors: {session: 'Unconfirmed email'}}
36
- end
37
-
38
- def create_success_response(_user, jwt)
39
- {session: {jwt: jwt}}
34
+ def create_params
35
+ params.require(:session).permit(RailsJwtAuth.auth_field_name, :password)
40
36
  end
41
37
 
42
38
  def create_error_response(_user)
43
39
  {errors: {session: "Invalid #{RailsJwtAuth.auth_field_name} / password"}}
44
40
  end
45
41
 
46
- def create_params
47
- params.require(:session).permit(RailsJwtAuth.auth_field_name, :password)
42
+ def unconfirmed_error_response
43
+ {errors: {session: 'Unconfirmed email'}}
44
+ end
45
+
46
+ def create_success_response(_user, jwt)
47
+ {session: {jwt: jwt}}
48
48
  end
49
49
  end
50
50
  end
@@ -9,7 +9,7 @@ class RailsJwtAuth::InstallGenerator < Rails::Generators::Base
9
9
  route "resource :session, controller: 'rails_jwt_auth/sessions', only: [:create, :destroy]"
10
10
  route "resource :registration, controller: 'rails_jwt_auth/registrations', only: [:create, :update, :destroy]"
11
11
 
12
- route "resource :confirmation, controller: 'rails_jwt_auth/confirmations', only: [:show, :create]"
12
+ route "resource :confirmation, controller: 'rails_jwt_auth/confirmations', only: [:create, :update]"
13
13
  route "resource :password, controller: 'rails_jwt_auth/passwords', only: [:create, :update]"
14
14
  end
15
15
  end
@@ -1,3 +1,3 @@
1
1
  module RailsJwtAuth
2
- VERSION = '0.3.2'
2
+ VERSION = '0.4.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.3.2
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - rjurado