tramway-api 1.6 → 1.6.0.1
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
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0f21707e10ef82a1c378250e9c82339400ee41739d7a6009001ecd1c8a17c4e0
|
4
|
+
data.tar.gz: 22732d5ad75036e1bf59831171f4d82af30f95805432900df283566b2b24619c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 313b31746731d79afe528f6100daa910260707e03c4d68d5c0961b6a046591d485006a58e3438b9b3bf4c1dcb7b79009511834b7a58905e293834d679c47bb66
|
7
|
+
data.tar.gz: 6b9a2570cd6b8e68d039de8706d9923651081c010f0a4cebce5347a06f442033b2c3833b7c07194bd4eea3b9bb3a2b7b81d629078d18380df4488f35b90ba63f
|
@@ -51,6 +51,12 @@ module Tramway
|
|
51
51
|
def auth_params
|
52
52
|
params[:auth]&.permit(:login, :password)
|
53
53
|
end
|
54
|
+
|
55
|
+
def current_user
|
56
|
+
Tramway::Api.user_based_models.map do |user_based_model|
|
57
|
+
send("current_#{user_based_model.name.underscore}")
|
58
|
+
end.compact.first
|
59
|
+
end
|
54
60
|
end
|
55
61
|
end
|
56
62
|
end
|
@@ -68,9 +68,7 @@ module Tramway::Api::V1
|
|
68
68
|
|
69
69
|
def authenticate_user_if_needed
|
70
70
|
if action_name.in? Tramway::Api::available_models[model_class.to_s][:closed]&.map(&:to_s) || []
|
71
|
-
|
72
|
-
send("current_#{user_based_model.name.underscore}").present?
|
73
|
-
end.include? true
|
71
|
+
current_user
|
74
72
|
end
|
75
73
|
end
|
76
74
|
|
@@ -5,9 +5,9 @@ class Tramway::Api::V1::UsersController < ::Tramway::Api::V1::ApplicationControl
|
|
5
5
|
include Tramway::ClassNameHelpers
|
6
6
|
|
7
7
|
def create
|
8
|
-
user_form = sign_up_form_class_name(
|
8
|
+
user_form = sign_up_form_class_name(user_based_model).new user_based_model.new
|
9
9
|
# Implement JSON API spec here
|
10
|
-
if user_form.submit snake_case params[
|
10
|
+
if user_form.submit snake_case params[user_based_model.name.underscore]
|
11
11
|
token = ::Knock::AuthToken.new(payload: { sub: user_form.model.uid }).token
|
12
12
|
# FIXME refactor this bullshit
|
13
13
|
serialized_user = OpenStruct.new(
|
@@ -31,4 +31,8 @@ class Tramway::Api::V1::UsersController < ::Tramway::Api::V1::ApplicationControl
|
|
31
31
|
def sign_up_form_class_name(model_class)
|
32
32
|
form_class_name "#{model_class}SignUp"
|
33
33
|
end
|
34
|
+
|
35
|
+
def user_based_model
|
36
|
+
params[:user_based_model].constantize if params[:user_based_model].in? Tramway::Api.user_based_models.map(&:to_s)
|
37
|
+
end
|
34
38
|
end
|
data/lib/tramway/api/version.rb
CHANGED