rails_jwt_auth 0.3.2 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +2 -2
- data/app/controllers/rails_jwt_auth/confirmations_controller.rb +19 -17
- data/app/controllers/rails_jwt_auth/passwords_controller.rb +9 -5
- data/app/controllers/rails_jwt_auth/sessions_controller.rb +8 -8
- data/lib/generators/rails_jwt_auth/install_generator.rb +1 -1
- data/lib/rails_jwt_auth/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3494e45b64c0d552272f8e20af88201294d4bf68
|
4
|
+
data.tar.gz: 3930404dd79c4d8c6807451579289f13085c4199
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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:
|
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
|
3
|
-
|
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
|
-
|
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:
|
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
|
-
|
4
|
-
|
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.
|
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
|
-
|
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
|
35
|
-
|
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
|
47
|
-
|
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: [:
|
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
|