rails_jwt_auth 0.10.1 → 0.11.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: 9083240a409a087f0f57dd2792250c2ca1f13168
4
- data.tar.gz: 94714ce5e75eef2e534896bd86959b56ae317a23
3
+ metadata.gz: eb1e415a9ec09f06237ed0aa2a020044cc72c8ea
4
+ data.tar.gz: e8772b6b9e8e711d4803ee63ce3fdaf21e6b374b
5
5
  SHA512:
6
- metadata.gz: 4442dc3282a93ed5e97bee72fff31c34c8904a340e2534535a9c682e77f40b550275de9f89281123c943e7fede7387fb69f4cc0b242a4e216df1f3ee3e0633bf
7
- data.tar.gz: 05077ac1ef3d49c0016653333ef40e6d91fb46abd6a75335cb3aef873ff771efe5f3a334fe12cdfe4b0c20e34b9b0b190bf3fd0de613d9e2e373ef63f4385367
6
+ metadata.gz: 232806debf45ed172ff4db611bb25ce530f5c0312e51de21c4995af25133963bd1045f4078ebf1c646872e5e151ed9b6092d32ab07647abc6641f13ef129f39e
7
+ data.tar.gz: 50cca6d19567f8c2ceb2c80b338fd9ee3a34edb20c237378f52e955c66620de6e9371f9a0bea73b2c8b48d24ead03a2ca4f042df0ca6127cb2a382c38f7c0431
data/README.md CHANGED
@@ -352,6 +352,31 @@ And edit route resource to use it:
352
352
  resource :registration, controller: 'registrations', only: [:create, :update, :destroy]
353
353
  ```
354
354
 
355
+ ## Edit user information
356
+
357
+ This is a controller example that allows users to edit their `email` and `password`.
358
+
359
+ ```ruby
360
+ class CurrentUserController < ApplicationController
361
+ before_action 'authenticate!'
362
+
363
+ def update
364
+ if update_params[:password]
365
+ current_user.update_with_password(update_params)
366
+ else
367
+ current_user.update_attributes(update_params)
368
+ end
369
+ end
370
+
371
+ private
372
+
373
+ def update_params
374
+ params.require(:user).permit(:email, :current_password, :password)
375
+ end
376
+ end
377
+
378
+ ```
379
+
355
380
  ## Custom responses
356
381
 
357
382
  You can overwrite `RailsJwtAuth::RenderHelper` to customize controllers responses.
@@ -24,6 +24,18 @@ module RailsJwtAuth
24
24
  end
25
25
  end
26
26
 
27
+ def update_with_password(params)
28
+ if (current_password = params.delete(:current_password)).blank?
29
+ errors.add(:current_password, I18n.t('rails_jwt_auth.errors.blank'))
30
+ false
31
+ elsif authenticate(current_password)
32
+ update_attributes(params)
33
+ else
34
+ errors.add(:current_password, I18n.t('rails_jwt_auth.errors.invalid'))
35
+ false
36
+ end
37
+ end
38
+
27
39
  module ClassMethods
28
40
  def get_by_token(token)
29
41
  if defined?(Mongoid) && ancestors.include?(Mongoid::Document)
@@ -11,4 +11,5 @@ en:
11
11
  create_session: "invalid %{field} / password"
12
12
  expired: "has expired, please request a new one"
13
13
  invalid: "invalid"
14
+ blank: "blank"
14
15
  not_found: "not found"
@@ -1,3 +1,3 @@
1
1
  module RailsJwtAuth
2
- VERSION = '0.10.1'
2
+ VERSION = '0.11.0'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails_jwt_auth
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.10.1
4
+ version: 0.11.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - rjurado
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-03-29 00:00:00.000000000 Z
11
+ date: 2017-03-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails