devise_token_auth 0.1.32.beta10 → 0.1.32
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 +33 -31
- data/app/controllers/devise_token_auth/confirmations_controller.rb +2 -0
- data/app/controllers/devise_token_auth/omniauth_callbacks_controller.rb +2 -0
- data/app/controllers/devise_token_auth/passwords_controller.rb +25 -14
- data/app/controllers/devise_token_auth/registrations_controller.rb +22 -11
- data/app/controllers/devise_token_auth/sessions_controller.rb +15 -9
- data/app/controllers/devise_token_auth/token_validations_controller.rb +2 -1
- data/app/models/devise_token_auth/concerns/user.rb +19 -14
- data/app/validators/email_validator.rb +1 -1
- data/config/locales/en.yml +30 -0
- data/config/locales/es.yml +30 -0
- data/config/locales/fr.yml +30 -0
- data/lib/devise_token_auth/engine.rb +10 -8
- data/lib/devise_token_auth/version.rb +1 -1
- data/lib/generators/devise_token_auth/install_generator.rb +28 -0
- data/lib/generators/devise_token_auth/templates/devise_token_auth.rb +6 -0
- data/lib/generators/devise_token_auth/templates/devise_token_auth_create_users.rb.erb +2 -2
- data/test/controllers/custom/custom_confirmations_controller_test.rb +26 -0
- data/test/controllers/custom/custom_omniauth_callbacks_controller_test.rb +29 -0
- data/test/controllers/custom/custom_passwords_controller_test.rb +66 -0
- data/test/controllers/custom/custom_registrations_controller_test.rb +1 -1
- data/test/controllers/custom/custom_sessions_controller_test.rb +30 -0
- data/test/controllers/custom/custom_token_validations_controller_test.rb +29 -0
- data/test/controllers/devise_token_auth/passwords_controller_test.rb +159 -10
- data/test/controllers/devise_token_auth/registrations_controller_test.rb +249 -58
- data/test/controllers/devise_token_auth/sessions_controller_test.rb +80 -1
- data/test/controllers/devise_token_auth/token_validations_controller_test.rb +17 -0
- data/test/dummy/app/controllers/application_controller.rb +1 -0
- data/test/dummy/app/controllers/custom/confirmations_controller.rb +13 -0
- data/test/dummy/app/controllers/custom/omniauth_callbacks_controller.rb +13 -0
- data/test/dummy/app/controllers/custom/passwords_controller.rb +35 -0
- data/test/dummy/app/controllers/custom/sessions_controller.rb +23 -0
- data/test/dummy/app/controllers/custom/token_validations_controller.rb +13 -0
- data/test/dummy/app/models/unconfirmable_user.rb +8 -0
- data/test/dummy/config/application.rb +1 -0
- data/test/dummy/config/routes.rb +8 -1
- data/test/dummy/db/migrate/20140715061447_devise_token_auth_create_users.rb +7 -1
- data/test/dummy/db/migrate/20140715061805_devise_token_auth_create_mangs.rb +7 -1
- data/test/dummy/db/migrate/20140928231203_devise_token_auth_create_evil_users.rb +7 -1
- data/test/dummy/db/migrate/20141222035835_devise_token_auth_create_only_email_users.rb +7 -1
- data/test/dummy/db/migrate/20141222053502_devise_token_auth_create_unregisterable_users.rb +7 -1
- data/test/dummy/db/migrate/20150409095712_devise_token_auth_create_nice_users.rb +7 -1
- data/test/dummy/db/migrate/20150708104536_devise_token_auth_create_unconfirmable_users.rb +60 -0
- data/test/dummy/db/schema.rb +89 -64
- data/test/dummy/db/test.sqlite3 +0 -0
- data/test/dummy/lib/migration_database_helper.rb +29 -0
- data/test/dummy/log/test.log +41319 -29566
- data/test/dummy/tmp/generators/config/initializers/devise_token_auth.rb +6 -0
- data/test/dummy/tmp/generators/config/routes.rb +4 -0
- data/test/dummy/tmp/generators/db/migrate/{20150617175802_devise_token_auth_create_users.rb → 20150729144233_devise_token_auth_create_users.rb} +1 -1
- data/test/fixtures/unconfirmable_users.yml +9 -0
- data/test/fixtures/users.yml +12 -0
- data/test/models/user_test.rb +21 -0
- metadata +39 -13
- data/config/locales/devise.en.yml +0 -59
- data/test/dummy/db/development.sqlite3 +0 -0
- data/test/dummy/log/development.log +0 -473
- data/test/dummy/tmp/generators/app/controllers/application_controller.rb +0 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0e28de2ceef16d684a4307e2f18f647f7a0421d0
|
4
|
+
data.tar.gz: ddd67c0685fcef8fc0b47524342f8a89994eb814
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4ae5e76e7e77ce36862c03dcd02579ac84ba38958bbbccfdc1c844f69019235124a560d55174cd48db035d340ca9b1dff1ca66d2a212f472314a2caccac600c0
|
7
|
+
data.tar.gz: af21c98c27ffaf6beafedc4d4fdc28e75aca53044bf2f6ad0fbfe3a3b56f96aa5f22a89c08bd31f8966c24d5e86093f3f42a6733a8049c6683bfa2455423862b
|
data/README.md
CHANGED
@@ -50,8 +50,8 @@ Please read the [issue reporting guidelines](#issue-reporting) before posting is
|
|
50
50
|
* [Using Multiple User Classes](#using-multiple-models)
|
51
51
|
* [Excluding Modules](#excluding-modules)
|
52
52
|
* [Custom Controller Overrides](#custom-controller-overrides)
|
53
|
-
* [Email Template Overrides](#email-template-overrides)
|
54
53
|
* [Passing blocks to Controllers](#passing-blocks-controllers)
|
54
|
+
* [Email Template Overrides](#email-template-overrides)
|
55
55
|
* [Issue Reporting Guidelines](#issue-reporting)
|
56
56
|
* [FAQ](#faq)
|
57
57
|
* [Conceptual Diagrams](#conceptual)
|
@@ -99,7 +99,7 @@ This generator accepts the following optional arguments:
|
|
99
99
|
| Argument | Default | Description |
|
100
100
|
|---|---|---|
|
101
101
|
| USER_CLASS | `User` | The name of the class to use for user authentication. |
|
102
|
-
| MOUNT_PATH | `auth` | The path at which to mount the authentication routes. [Read more](#usage). |
|
102
|
+
| MOUNT_PATH | `auth` | The path at which to mount the authentication routes. [Read more](#usage-tldr). |
|
103
103
|
|
104
104
|
The following events will take place when using the install generator:
|
105
105
|
|
@@ -134,14 +134,14 @@ The following routes are available for use by your client. These routes live rel
|
|
134
134
|
|:-----|:-------|:--------|
|
135
135
|
| / | POST | Email registration. Accepts **`email`**, **`password`**, and **`password_confirmation`** params. A verification email will be sent to the email address provided. Accepted params can be customized using the [`devise_parameter_sanitizer`](https://github.com/plataformatec/devise#strong-parameters) system. |
|
136
136
|
| / | DELETE | Account deletion. This route will destroy users identified by their **`uid`** and **`auth_token`** headers. |
|
137
|
-
| / | PUT | Account updates. This route will update an existing user's account settings. The default accepted params are **`password`** and **`password_confirmation`**, but this can be customized using the [`devise_parameter_sanitizer`](https://github.com/plataformatec/devise#strong-parameters) system. |
|
137
|
+
| / | PUT | Account updates. This route will update an existing user's account settings. The default accepted params are **`password`** and **`password_confirmation`**, but this can be customized using the [`devise_parameter_sanitizer`](https://github.com/plataformatec/devise#strong-parameters) system. If **`config.check_current_password_before_update`** is set to `:attributes` the **`current_password`** param is checked before any update, if it is set to `:password` the **`current_password`** param is checked only if the request updates user password. |
|
138
138
|
| /sign_in | POST | Email authentication. Accepts **`email`** and **`password`** as params. This route will return a JSON representation of the `User` model on successful login. |
|
139
139
|
| /sign_out | DELETE | Use this route to end the user's current session. This route will invalidate the user's authentication token. |
|
140
140
|
| /:provider | GET | Set this route as the destination for client authentication. Ideally this will happen in an external window or popup. [Read more](#omniauth-authentication). |
|
141
141
|
| /:provider/callback | GET/POST | Destination for the oauth2 provider's callback uri. `postMessage` events containing the authenticated user's data will be sent back to the main client window from this page. [Read more](#omniauth-authentication). |
|
142
|
-
| /validate_token | GET | Use this route to validate tokens on return visits to the client. Accepts **`uid`** and **`
|
142
|
+
| /validate_token | GET | Use this route to validate tokens on return visits to the client. Accepts **`uid`** and **`access-token`** as params. These values should correspond to the columns in your `User` table of the same names. |
|
143
143
|
| /password | POST | Use this route to send a password reset confirmation email to users that registered by email. Accepts **`email`** and **`redirect_url`** as params. The user matching the `email` param will be sent instructions on how to reset their password. `redirect_url` is the url to which the user will be redirected after visiting the link contained in the email. |
|
144
|
-
| /password | PUT | Use this route to change users' passwords. Accepts **`password`** and **`password_confirmation`** as params. This route is only valid for users that registered by email (OAuth2 users will receive an error). |
|
144
|
+
| /password | PUT | Use this route to change users' passwords. Accepts **`password`** and **`password_confirmation`** as params. This route is only valid for users that registered by email (OAuth2 users will receive an error). It also checks **`current_password`** if **`config.check_current_password_before_update`** is not set `false` (disabled by default). |
|
145
145
|
| /password/edit | GET | Verify user by password reset token. This route is the destination URL for password reset confirmation. This route must contain **`reset_password_token`** and **`redirect_url`** params. These values will be set automatically by the confirmation email that is generated by the password reset request. |
|
146
146
|
|
147
147
|
[Jump here](#usage-cont) for more usage information.
|
@@ -420,7 +420,7 @@ Models that include the `DeviseTokenAuth::Concerns::User` concern will have acce
|
|
420
420
|
client_id = request.headers['client']
|
421
421
|
token = request.headers['access-token']
|
422
422
|
|
423
|
-
@
|
423
|
+
@resource.valid_token?(token, client_id)
|
424
424
|
~~~
|
425
425
|
|
426
426
|
* **`create_new_auth_token`**: creates a new auth token with all of the necessary metadata. Accepts `client` as an optional argument. Will generate a new `client` if none is provided. Returns the authentication headers that should be sent by the client as an object.
|
@@ -431,7 +431,7 @@ Models that include the `DeviseTokenAuth::Concerns::User` concern will have acce
|
|
431
431
|
client_id = request.headers['client']
|
432
432
|
|
433
433
|
# update token, generate updated auth headers for response
|
434
|
-
new_auth_header = @
|
434
|
+
new_auth_header = @resource.create_new_auth_token(client_id)
|
435
435
|
|
436
436
|
# update response with the header that will be required by the next request
|
437
437
|
response.headers.merge!(new_auth_header)
|
@@ -446,13 +446,13 @@ Models that include the `DeviseTokenAuth::Concerns::User` concern will have acce
|
|
446
446
|
token = SecureRandom.urlsafe_base64(nil, false)
|
447
447
|
|
448
448
|
# store client + token in user's token hash
|
449
|
-
@
|
449
|
+
@resource.tokens[client_id] = {
|
450
450
|
token: BCrypt::Password.create(token),
|
451
451
|
expiry: (Time.now + DeviseTokenAuth.token_lifespan).to_i
|
452
452
|
}
|
453
453
|
|
454
454
|
# generate auth headers for response
|
455
|
-
new_auth_header = @
|
455
|
+
new_auth_header = @resource.build_auth_header(token, client_id)
|
456
456
|
|
457
457
|
# update response with the header that will be required by the next request
|
458
458
|
response.headers.merge!(new_auth_header)
|
@@ -502,7 +502,7 @@ This gem supports the use of multiple user models. One possible use case is to a
|
|
502
502
|
~~~
|
503
503
|
|
504
504
|
1. Configure any `Admin` restricted controllers. Controllers will now have access to the methods [described here](#methods):
|
505
|
-
* `before_action
|
505
|
+
* `before_action :authenticate_admin!`
|
506
506
|
* `current_admin`
|
507
507
|
* `admin_signed_in?`
|
508
508
|
|
@@ -608,7 +608,7 @@ For example, the default behavior of the [`validate_token`](https://github.com/l
|
|
608
608
|
~~~ruby
|
609
609
|
# config/routes.rb
|
610
610
|
Rails.application.routes.draw do
|
611
|
-
...
|
611
|
+
...
|
612
612
|
mount_devise_token_auth_for 'User', at: 'auth', controllers: {
|
613
613
|
token_validations: 'overrides/token_validations'
|
614
614
|
}
|
@@ -619,10 +619,10 @@ module Overrides
|
|
619
619
|
class TokenValidationsController < DeviseTokenAuth::TokenValidationsController
|
620
620
|
|
621
621
|
def validate_token
|
622
|
-
# @
|
623
|
-
if @
|
622
|
+
# @resource will have been set by set_user_by_token concern
|
623
|
+
if @resource
|
624
624
|
render json: {
|
625
|
-
data: @
|
625
|
+
data: @resource.as_json(methods: :calculate_operating_thetan)
|
626
626
|
}
|
627
627
|
else
|
628
628
|
render json: {
|
@@ -650,6 +650,24 @@ mount_devise_token_auth_for 'User', at: 'auth', controllers: {
|
|
650
650
|
|
651
651
|
**Note:** Controller overrides must implement the expected actions of the controllers that they replace.
|
652
652
|
|
653
|
+
## Passing blocks to Controllers
|
654
|
+
|
655
|
+
It may be that you simply want to _add_ behavior to existing controllers without having to re-implement their behavior completely. In this case, you can do so by creating a new controller that inherits from any of DeviseTokenAuth's controllers, overriding whichever methods you'd like to add behavior to by passing a block to `super`:
|
656
|
+
|
657
|
+
```ruby
|
658
|
+
class Custom::RegistrationsController < DeviseTokenAuth::RegistrationsController
|
659
|
+
|
660
|
+
def create
|
661
|
+
super do |resource|
|
662
|
+
resource.do_something(extra)
|
663
|
+
end
|
664
|
+
end
|
665
|
+
|
666
|
+
end
|
667
|
+
```
|
668
|
+
|
669
|
+
Your block will be performed just before the controller would usually render a successful response.
|
670
|
+
|
653
671
|
## Email Template Overrides
|
654
672
|
|
655
673
|
You will probably want to override the default email templates for email sign-up and password-reset confirmation. Run the following command to copy the email templates into your app:
|
@@ -667,22 +685,6 @@ These files may be edited to suit your taste.
|
|
667
685
|
|
668
686
|
**Note:** if you choose to modify these templates, do not modify the `link_to` blocks unless you absolutely know what you are doing.
|
669
687
|
|
670
|
-
## Passing blocks to RegistrationController
|
671
|
-
|
672
|
-
If you simply want to add behaviour to the existing Registration controller, you can do so by creating a new controller that inherits from it, and override the `create`, `update` or `destroy` methods, and passing a block to super:
|
673
|
-
|
674
|
-
```ruby
|
675
|
-
class Custom::RegistrationsController < DeviseTokenAuth::RegistrationsController
|
676
|
-
|
677
|
-
def create
|
678
|
-
super do |resource|
|
679
|
-
resource.add_something(extra)
|
680
|
-
end
|
681
|
-
end
|
682
|
-
|
683
|
-
end
|
684
|
-
```
|
685
|
-
|
686
688
|
# Issue Reporting
|
687
689
|
|
688
690
|
When posting issues, please include the following information to speed up the troubleshooting process:
|
@@ -798,7 +800,7 @@ This gem automatically manages batch requests. You can change the time buffer fo
|
|
798
800
|
This gem takes the following steps to ensure security.
|
799
801
|
|
800
802
|
This gem uses auth tokens that are:
|
801
|
-
* [changed after every request](#about-token-management),
|
803
|
+
* [changed after every request](#about-token-management) (can be [turned off](https://github.com/lynndylanhurley/devise_token_auth/#initializer-settings)),
|
802
804
|
* [of cryptographic strength](http://ruby-doc.org/stdlib-2.1.0/libdoc/securerandom/rdoc/SecureRandom.html),
|
803
805
|
* hashed using [BCrypt](https://github.com/codahale/bcrypt-ruby) (not stored in plain-text),
|
804
806
|
* securely compared (to protect against timing attacks),
|
@@ -9,7 +9,7 @@ module DeviseTokenAuth
|
|
9
9
|
unless resource_params[:email]
|
10
10
|
return render json: {
|
11
11
|
success: false,
|
12
|
-
errors: [
|
12
|
+
errors: [I18n.t("devise_token_auth.passwords.missing_email")]
|
13
13
|
}, status: 401
|
14
14
|
end
|
15
15
|
|
@@ -22,7 +22,7 @@ module DeviseTokenAuth
|
|
22
22
|
unless redirect_url
|
23
23
|
return render json: {
|
24
24
|
success: false,
|
25
|
-
errors: [
|
25
|
+
errors: [I18n.t("devise_token_auth.passwords.missing_redirect_url")]
|
26
26
|
}, status: 401
|
27
27
|
end
|
28
28
|
|
@@ -32,7 +32,7 @@ module DeviseTokenAuth
|
|
32
32
|
return render json: {
|
33
33
|
status: 'error',
|
34
34
|
data: @resource.as_json,
|
35
|
-
errors: ["
|
35
|
+
errors: [I18n.t("devise_token_auth.passwords.not_allowed_redirect_url", redirect_url: redirect_url)]
|
36
36
|
}, status: 403
|
37
37
|
end
|
38
38
|
end
|
@@ -57,6 +57,7 @@ module DeviseTokenAuth
|
|
57
57
|
error_status = 400
|
58
58
|
|
59
59
|
if @resource
|
60
|
+
yield if block_given?
|
60
61
|
@resource.send_reset_password_instructions({
|
61
62
|
email: email,
|
62
63
|
provider: 'email',
|
@@ -67,14 +68,13 @@ module DeviseTokenAuth
|
|
67
68
|
if @resource.errors.empty?
|
68
69
|
render json: {
|
69
70
|
success: true,
|
70
|
-
message: "
|
71
|
-
"instructions for resetting your password."
|
71
|
+
message: I18n.t("devise_token_auth.passwords.sended", email: email)
|
72
72
|
}
|
73
73
|
else
|
74
74
|
errors = @resource.errors
|
75
75
|
end
|
76
76
|
else
|
77
|
-
errors = ["
|
77
|
+
errors = [I18n.t("devise_token_auth.passwords.user_not_found", email: email)]
|
78
78
|
error_status = 404
|
79
79
|
end
|
80
80
|
|
@@ -105,9 +105,10 @@ module DeviseTokenAuth
|
|
105
105
|
}
|
106
106
|
|
107
107
|
# ensure that user is confirmed
|
108
|
-
@resource.skip_confirmation!
|
108
|
+
@resource.skip_confirmation! if @resource.devise_modules.include?(:confirmable) && !@resource.confirmed_at
|
109
109
|
|
110
110
|
@resource.save!
|
111
|
+
yield if block_given?
|
111
112
|
|
112
113
|
redirect_to(@resource.build_auth_url(params[:redirect_url], {
|
113
114
|
token: token,
|
@@ -116,7 +117,9 @@ module DeviseTokenAuth
|
|
116
117
|
config: params[:config]
|
117
118
|
}))
|
118
119
|
else
|
119
|
-
|
120
|
+
render json: {
|
121
|
+
success: false
|
122
|
+
}, status: 404
|
120
123
|
end
|
121
124
|
end
|
122
125
|
|
@@ -133,8 +136,7 @@ module DeviseTokenAuth
|
|
133
136
|
unless @resource.provider == 'email'
|
134
137
|
return render json: {
|
135
138
|
success: false,
|
136
|
-
errors: ["
|
137
|
-
"your #{@resource.provider.humanize} account instead."]
|
139
|
+
errors: [I18n.t("devise_token_auth.passwords.password_not_required", provider: @resource.provider.humanize)]
|
138
140
|
}, status: 422
|
139
141
|
end
|
140
142
|
|
@@ -142,16 +144,17 @@ module DeviseTokenAuth
|
|
142
144
|
unless password_resource_params[:password] and password_resource_params[:password_confirmation]
|
143
145
|
return render json: {
|
144
146
|
success: false,
|
145
|
-
errors: [
|
147
|
+
errors: [I18n.t("devise_token_auth.passwords.missing_passwords")]
|
146
148
|
}, status: 422
|
147
149
|
end
|
148
150
|
|
149
|
-
if @resource.
|
151
|
+
if @resource.send(resource_update_method, password_resource_params)
|
152
|
+
yield if block_given?
|
150
153
|
return render json: {
|
151
154
|
success: true,
|
152
155
|
data: {
|
153
156
|
user: @resource,
|
154
|
-
message: "
|
157
|
+
message: I18n.t("devise_token_auth.passwords.successfully_updated")
|
155
158
|
}
|
156
159
|
}
|
157
160
|
else
|
@@ -162,12 +165,20 @@ module DeviseTokenAuth
|
|
162
165
|
end
|
163
166
|
end
|
164
167
|
|
168
|
+
def resource_update_method
|
169
|
+
if DeviseTokenAuth.check_current_password_before_update != false
|
170
|
+
"update_with_password"
|
171
|
+
else
|
172
|
+
"update_attributes"
|
173
|
+
end
|
174
|
+
end
|
175
|
+
|
165
176
|
def password_resource_params
|
166
177
|
params.permit(devise_parameter_sanitizer.for(:account_update))
|
167
178
|
end
|
168
179
|
|
169
180
|
def resource_params
|
170
|
-
params.permit(:email, :password, :password_confirmation, :reset_password_token)
|
181
|
+
params.permit(:email, :password, :password_confirmation, :current_password, :reset_password_token)
|
171
182
|
end
|
172
183
|
|
173
184
|
end
|
@@ -11,7 +11,7 @@ module DeviseTokenAuth
|
|
11
11
|
|
12
12
|
# honor devise configuration for case_insensitive_keys
|
13
13
|
if resource_class.case_insensitive_keys.include?(:email)
|
14
|
-
@resource.email = sign_up_params[:email].downcase
|
14
|
+
@resource.email = sign_up_params[:email].try :downcase
|
15
15
|
else
|
16
16
|
@resource.email = sign_up_params[:email]
|
17
17
|
end
|
@@ -27,7 +27,7 @@ module DeviseTokenAuth
|
|
27
27
|
return render json: {
|
28
28
|
status: 'error',
|
29
29
|
data: @resource.as_json,
|
30
|
-
errors: ["
|
30
|
+
errors: [I18n.t("devise_token_auth.registrations.missing_confirm_success_url")]
|
31
31
|
}, status: 403
|
32
32
|
end
|
33
33
|
|
@@ -37,7 +37,7 @@ module DeviseTokenAuth
|
|
37
37
|
return render json: {
|
38
38
|
status: 'error',
|
39
39
|
data: @resource.as_json,
|
40
|
-
errors: ["
|
40
|
+
errors: [I18n.t("devise_token_auth.registrations.redirect_url_not_allowed", redirect_url: redirect_url)]
|
41
41
|
}, status: 403
|
42
42
|
end
|
43
43
|
end
|
@@ -87,15 +87,14 @@ module DeviseTokenAuth
|
|
87
87
|
render json: {
|
88
88
|
status: 'error',
|
89
89
|
data: @resource.as_json,
|
90
|
-
errors: ["
|
90
|
+
errors: [I18n.t("devise_token_auth.registrations.email_already_exists", email: @resource.email)]
|
91
91
|
}, status: 403
|
92
92
|
end
|
93
93
|
end
|
94
94
|
|
95
95
|
def update
|
96
96
|
if @resource
|
97
|
-
|
98
|
-
if @resource.update_attributes(account_update_params)
|
97
|
+
if @resource.send(resource_update_method, account_update_params)
|
99
98
|
yield @resource if block_given?
|
100
99
|
render json: {
|
101
100
|
status: 'success',
|
@@ -110,7 +109,7 @@ module DeviseTokenAuth
|
|
110
109
|
else
|
111
110
|
render json: {
|
112
111
|
status: 'error',
|
113
|
-
errors: ["
|
112
|
+
errors: [I18n.t("devise_token_auth.registrations.user_not_found")]
|
114
113
|
}, status: 404
|
115
114
|
end
|
116
115
|
end
|
@@ -122,12 +121,12 @@ module DeviseTokenAuth
|
|
122
121
|
|
123
122
|
render json: {
|
124
123
|
status: 'success',
|
125
|
-
message: "
|
124
|
+
message: I18n.t("devise_token_auth.registrations.account_with_uid_destroyed", uid: @resource.uid)
|
126
125
|
}
|
127
126
|
else
|
128
127
|
render json: {
|
129
128
|
status: 'error',
|
130
|
-
errors: ["
|
129
|
+
errors: [I18n.t("devise_token_auth.registrations.account_to_destroy_not_found")]
|
131
130
|
}, status: 404
|
132
131
|
end
|
133
132
|
end
|
@@ -142,12 +141,24 @@ module DeviseTokenAuth
|
|
142
141
|
|
143
142
|
private
|
144
143
|
|
144
|
+
def resource_update_method
|
145
|
+
if DeviseTokenAuth.check_current_password_before_update == :attributes
|
146
|
+
"update_with_password"
|
147
|
+
elsif DeviseTokenAuth.check_current_password_before_update == :password and account_update_params.has_key?(:password)
|
148
|
+
"update_with_password"
|
149
|
+
elsif account_update_params.has_key?(:current_password)
|
150
|
+
"update_with_password"
|
151
|
+
else
|
152
|
+
"update_attributes"
|
153
|
+
end
|
154
|
+
end
|
155
|
+
|
145
156
|
def validate_sign_up_params
|
146
|
-
validate_post_data sign_up_params,
|
157
|
+
validate_post_data sign_up_params, I18n.t("errors.validate_sign_up_params")
|
147
158
|
end
|
148
159
|
|
149
160
|
def validate_account_update_params
|
150
|
-
validate_post_data account_update_params,
|
161
|
+
validate_post_data account_update_params, I18n.t("errors.validate_account_update_params")
|
151
162
|
end
|
152
163
|
|
153
164
|
def validate_post_data which, message
|
@@ -4,6 +4,12 @@ module DeviseTokenAuth
|
|
4
4
|
before_filter :set_user_by_token, :only => [:destroy]
|
5
5
|
after_action :reset_session, :only => [:destroy]
|
6
6
|
|
7
|
+
def new
|
8
|
+
render json: {
|
9
|
+
errors: [ I18n.t("devise_token_auth.sessions.not_supported")]
|
10
|
+
}, status: 405
|
11
|
+
end
|
12
|
+
|
7
13
|
def create
|
8
14
|
# Check
|
9
15
|
field = (resource_params.keys.map(&:to_sym) & resource_class.authentication_keys).first
|
@@ -25,7 +31,7 @@ module DeviseTokenAuth
|
|
25
31
|
@resource = resource_class.where(q, q_value).first
|
26
32
|
end
|
27
33
|
|
28
|
-
if @resource and valid_params?(field, q_value) and @resource.valid_password?(resource_params[:password]) and @resource.
|
34
|
+
if @resource and valid_params?(field, q_value) and @resource.valid_password?(resource_params[:password]) and (!@resource.respond_to?(:active_for_authentication?) or @resource.active_for_authentication?)
|
29
35
|
# create client id
|
30
36
|
@client_id = SecureRandom.urlsafe_base64(nil, false)
|
31
37
|
@token = SecureRandom.urlsafe_base64(nil, false)
|
@@ -38,23 +44,21 @@ module DeviseTokenAuth
|
|
38
44
|
|
39
45
|
sign_in(:user, @resource, store: false, bypass: false)
|
40
46
|
|
47
|
+
yield if block_given?
|
48
|
+
|
41
49
|
render json: {
|
42
50
|
data: @resource.token_validation_response
|
43
51
|
}
|
44
52
|
|
45
|
-
elsif @resource and not @resource.
|
53
|
+
elsif @resource and not (!@resource.respond_to?(:active_for_authentication?) or @resource.active_for_authentication?)
|
46
54
|
render json: {
|
47
55
|
success: false,
|
48
|
-
errors: [
|
49
|
-
"A confirmation email was sent to your account at #{@resource.email}. "+
|
50
|
-
"You must follow the instructions in the email before your account "+
|
51
|
-
"can be activated"
|
52
|
-
]
|
56
|
+
errors: [ I18n.t("devise_token_auth.sessions.not_confirmed", email: @resource.email) ]
|
53
57
|
}, status: 401
|
54
58
|
|
55
59
|
else
|
56
60
|
render json: {
|
57
|
-
errors: ["
|
61
|
+
errors: [I18n.t("devise_token_auth.sessions.bad_credentials")]
|
58
62
|
}, status: 401
|
59
63
|
end
|
60
64
|
end
|
@@ -69,13 +73,15 @@ module DeviseTokenAuth
|
|
69
73
|
user.tokens.delete(client_id)
|
70
74
|
user.save!
|
71
75
|
|
76
|
+
yield if block_given?
|
77
|
+
|
72
78
|
render json: {
|
73
79
|
success:true
|
74
80
|
}, status: 200
|
75
81
|
|
76
82
|
else
|
77
83
|
render json: {
|
78
|
-
errors: ["
|
84
|
+
errors: [I18n.t("devise_token_auth.sessions.user_not_found")]
|
79
85
|
}, status: 404
|
80
86
|
end
|
81
87
|
end
|