tramway-api 1.0.3 → 1.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: 6ca6fc2c599d996783de1ac8a07383ca7ceec44451ab39d51f30ef1431a5ca61
4
- data.tar.gz: 15c2670773edde1c527b422817e354d333de13b8da3664f1c05345c8d32d9926
3
+ metadata.gz: 9dd077883596f2b69e87b35d326323415bf8c5184636caf46ab18d8377d01494
4
+ data.tar.gz: 7618b6d6fc2b0b45282747a5042fdf2976dcb2e66896e301ac6fde8d43c41331
5
5
  SHA512:
6
- metadata.gz: d9545ecbf121766e12b0ae76f1c527f9ce2d40288c033e6174e78e9c515551d7b0c5d314ebeb853568002a90abf9e82ec05c20418d7710acff826f86c5f477d3
7
- data.tar.gz: a5ebb28926fc86784e31d6b581b2b15974dff66c5fb8cf7f9bb3ca066b63ee6673d1e347444d82fafbb63a83718aa5de230d60b8a04d88c7ad1cd9287ad90f5b
6
+ metadata.gz: 5e93025a3e5f55e928a60879a4552440f5f8eb198c8af379419d776d8d1dfe735eaf7a87d4cda09bb3461633f581e4d32828aecf33b80b43d70b24a8cb0b7857
7
+ data.tar.gz: 974204ec735f413a47e1469443d1f2638346dea60792be83f438868de0d4c411b10a99f19fedaabfa0a9176519017c78c9546099d6701d0911ee6eebfca47a83
@@ -34,12 +34,20 @@ module Tramway
34
34
  if Tramway::Api.user_based_model.respond_to? :from_token_request
35
35
  Tramway::Api.user_based_model.active.from_token_request request
36
36
  else
37
- params[:auth] && Tramway::Api.user_based_model.active.find_by(email: auth_params[:email])
37
+ params[:auth] && find_user_by_auth_attributes
38
38
  end
39
39
  end
40
40
 
41
+ def find_user_by_auth_attributes
42
+ Tramway::Api.auth_attributes.each do |attribute|
43
+ object = Tramway::Api.user_based_model.active.where.not(attribute => nil).find_by(attribute => auth_params[:login])
44
+ return object if object
45
+ end
46
+ nil
47
+ end
48
+
41
49
  def auth_params
42
- params[:auth]&.permit :email, :password
50
+ params[:auth]&.permit(:login, :password)
43
51
  end
44
52
  end
45
53
  end
@@ -1,5 +1,5 @@
1
1
  module Tramway
2
2
  module Api
3
- VERSION = '1.0.3'
3
+ VERSION = '1.1'
4
4
  end
5
5
  end
data/lib/tramway/api.rb CHANGED
@@ -3,12 +3,20 @@ require 'tramway/api/engine'
3
3
  module Tramway
4
4
  module Api
5
5
  class << self
6
+ def auth_config
7
+ @@auth_config ||= { user_model: ::Tramway::User::User, auth_attributes: :email }
8
+ end
9
+
10
+ def auth_config=(**params)
11
+ @@auth_config = params
12
+ end
13
+
6
14
  def user_based_model
7
- @@user_based_model ||= ::Tramway::User::User
15
+ @@auth_config[:user_model]
8
16
  end
9
17
 
10
- def user_based_model=(model_class)
11
- @@user_based_model = model_class
18
+ def auth_attributes
19
+ @@auth_config[:auth_attributes]
12
20
  end
13
21
 
14
22
  def set_available_models(**models)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tramway-api
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.3
4
+ version: '1.1'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Pavel Kalashnikov
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-06-26 00:00:00.000000000 Z
11
+ date: 2019-07-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: knock
@@ -100,7 +100,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
100
100
  version: '0'
101
101
  requirements: []
102
102
  rubyforge_project:
103
- rubygems_version: 2.7.7
103
+ rubygems_version: 2.7.6
104
104
  signing_key:
105
105
  specification_version: 4
106
106
  summary: Engine for api