model_driven_api 2.3.17 → 2.4.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: aa5e1a3c1035f1a2c765dfc5969845af3c80d70a2e0063e2f42b140b636b751a
4
- data.tar.gz: 461d22a194727f614e60227f2ed886b0f8fe92e27a984ed13e8b33f5e73db2e8
3
+ metadata.gz: 3acd8a7365111aab30d8ff8d2b99b42205e30d379c8a3e1d4ed67afed159058c
4
+ data.tar.gz: 73d6cca889e4bf7aa08816567e52f274576f1e67cefb1e233c3f2e820c389086
5
5
  SHA512:
6
- metadata.gz: a401038c58d3bf9386e5020b4552040a013c5c6867c2df16ae831ebaf90ae7c22a0ed75187bd2f09fcadf00d48958ec314e288fe74767471d2432eaef6f95e39
7
- data.tar.gz: 4b03ebfbc44d9158198f1a455a5a294a5436e31af3488714b0a0fd153771aa38f2907d613a4b76a552dcbf463a6c6969821bac3a79a77e4777fd0be5b86dc745
6
+ metadata.gz: 4cc64b956182b5dbfcc7c0778c18da6e94b5f52525868595f4a8fdfd2c1bc3149b4d9b667ba89d21549ae7668d4251c95e0b57bbfe6a6b71319fc0de06793749
7
+ data.tar.gz: 4d175e1264cc0db245fe67e80bee381dcf05ee1402ee3ce6c42717a6db8abe852294b6608c2a10f4569a31c2337695ae5038760b661a9d3078748cbf1e7fceb6
@@ -23,7 +23,7 @@ class AuthenticateUser
23
23
  # Since this is a new login and I don't care from where it comes, new logins always
24
24
  # Invalidate older tokens
25
25
  UsedToken.where(user_id: api_user.id).update(is_valid: false) if ENV["ALLOW_MULTISESSIONS"] == "false"
26
- return result
26
+ return {jwt: result, user: current_u}
27
27
  end
28
28
  nil
29
29
  end
@@ -84,7 +84,8 @@ class Api::V2::ApplicationController < ActionController::API
84
84
  return render json: result, status: 200 if status == true
85
85
 
86
86
  # Normal Update Action
87
- @record.update_attributes!(@body)
87
+ # Raisl 6 vs Rails 6.1
88
+ @record.respond_to?('update_attributes!') ? @record.update_attributes!(@body) : @record.update!(@body)
88
89
  render json: @record.to_json(json_attrs), status: 200
89
90
  end
90
91
 
@@ -5,8 +5,9 @@ class Api::V2::AuthenticationController < ActionController::API
5
5
  command = !params[:atoken].blank? && User.column_names.include?("access_token") ? AuthenticateUser.call(access_token: params[:atoken]) : AuthenticateUser.call(email: params[:auth][:email], password: params[:auth][:password])
6
6
 
7
7
  if command.success?
8
- response.headers['Token'] = command.result
9
- head :ok
8
+ response.headers['Token'] = command.result[:jwt]
9
+ # head :ok
10
+ render json: command.result[:user].to_json(User.json_attrs), status: 200
10
11
  end
11
12
  end
12
13
  end
@@ -3,13 +3,14 @@ class JsonWebToken
3
3
  def encode(payload, expiry = 15.minutes.from_now.to_i)
4
4
  result = ::JWT.encode(payload.merge(exp: expiry), ::Rails.application.credentials.dig(:secret_key_base).presence||ENV["SECRET_KEY_BASE"])
5
5
  # Store the created token into the DB for later checks if is invalid
6
- UsedToken.create(token: result, user_id: payload[:user_id])
6
+ # In a public environment management, without login, it has no interest, so I don't pollute the DB
7
+ UsedToken.find_or_create_by(token: result, user_id: payload[:user_id]) if ENV["ALLOW_MULTISESSIONS"] == "false"
7
8
  result
8
9
  end
9
10
 
10
11
  def decode(token)
11
12
  # Check if the passed token is present and valid into the UsedToken
12
- raise "Token is invalidated by new login" unless UsedToken.exists?(token: token, is_valid: true)
13
+ raise "Token is invalidated by new login" unless UsedToken.exists?(token: token, is_valid: true) if ENV["ALLOW_MULTISESSIONS"] == "false"
13
14
  body = ::JWT.decode(token, ::Rails.application.credentials.dig(:secret_key_base).presence||ENV["SECRET_KEY_BASE"])[0]
14
15
  ::HashWithIndifferentAccess.new body
15
16
  rescue
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: model_driven_api
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.3.17
4
+ version: 2.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gabriele Tassoni
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-05-28 00:00:00.000000000 Z
11
+ date: 2021-09-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thecore_backend_commons