tramway-auth 1.2.1.1 → 2.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/controllers/concerns/tramway/auth_management.rb +15 -17
- data/app/controllers/tramway/auth/web/sessions_controller.rb +7 -11
- data/app/controllers/tramway/auth/web/sign_ups_controller.rb +9 -8
- data/app/forms/tramway/auth/session_form.rb +0 -4
- data/app/forms/tramway/auth/sign_up_form.rb +5 -0
- data/app/helpers/tramway/auth/application_helper.rb +6 -0
- data/config/routes.rb +2 -1
- data/lib/tramway/auth/version.rb +1 -1
- data/lib/tramway/auth.rb +6 -3
- metadata +2 -2
- data/app/views/tramway/auth/web/sessions/new.html.haml +0 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4adfdbe574a9d31bc8077b374b70157cfda825f0600269a4224b5ff177649f5f
|
4
|
+
data.tar.gz: 83bfe0c4bbaa456ced5403604f7d451ba1a77267300d0d7eb084c7ceadd613e2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ac20f69be6eda14d8563147ae5642dd056c36faf70269c8cbb03c0b9433902cd75b437e6760253930925aa2662ef41b00a0fbada4b05277b060837b95192f99b
|
7
|
+
data.tar.gz: 42dcdfc8047a1ff5f13bf6985d3b101404deae427f85e5c3d7be798c3013978b0d0f9b1ce8823bb4302d56bd19f3b9c96f1c47c64e2736c8b749f47f3e36e465
|
@@ -3,33 +3,31 @@
|
|
3
3
|
module Tramway
|
4
4
|
module AuthManagement
|
5
5
|
def sign_in(user)
|
6
|
-
session[
|
6
|
+
session[user_id_key(user.class)] = user.id
|
7
7
|
end
|
8
8
|
|
9
|
-
def sign_out
|
10
|
-
session[
|
9
|
+
def sign_out(user_class = ::Tramway::User::User)
|
10
|
+
session[user_id_key(user_class.constantize)] = nil
|
11
11
|
end
|
12
12
|
|
13
|
-
def signed_in?
|
14
|
-
current_user
|
13
|
+
def signed_in?(user_class = ::Tramway::User::User)
|
14
|
+
current_user(user_class)
|
15
15
|
end
|
16
16
|
|
17
|
-
def authenticate_user!
|
18
|
-
redirect_to new_session_path unless signed_in?
|
17
|
+
def authenticate_user!(user_class = ::Tramway::User::User)
|
18
|
+
redirect_to new_session_path unless signed_in?(user_class)
|
19
19
|
end
|
20
20
|
|
21
|
-
def
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
end
|
26
|
-
else
|
27
|
-
redirect_to '/auth/session/new'
|
28
|
-
end
|
21
|
+
def current_user(user_class = ::Tramway::User::User)
|
22
|
+
user = user_class.find_by id: session[user_id_key(user_class)]
|
23
|
+
return false unless user
|
24
|
+
"#{user_class}Decorator".constantize.decorate user
|
29
25
|
end
|
30
26
|
|
31
|
-
|
32
|
-
|
27
|
+
private
|
28
|
+
|
29
|
+
def user_id_key(user_class)
|
30
|
+
"#{user_class.to_s.underscore}_id".to_sym
|
33
31
|
end
|
34
32
|
end
|
35
33
|
end
|
@@ -5,30 +5,26 @@ module Tramway::Auth
|
|
5
5
|
class SessionsController < ::Tramway::Auth::Web::ApplicationController
|
6
6
|
before_action :redirect_if_signed_in, except: :destroy
|
7
7
|
|
8
|
-
def new
|
9
|
-
@application = Tramway::Core.application&.model_class&.first || Tramway::Core.application
|
10
|
-
@session_form = ::Tramway::Auth::SessionForm.new ::Tramway::User::User.new
|
11
|
-
end
|
12
|
-
|
13
8
|
def create
|
14
|
-
@session_form = ::Tramway::Auth::SessionForm.new
|
9
|
+
@session_form = ::Tramway::Auth::SessionForm.new params[:model].constantize.active.find_by email: params[:user][:email]
|
15
10
|
if @session_form.validate params[:user]
|
16
11
|
sign_in @session_form.model
|
17
|
-
redirect_to ::Tramway::Auth.
|
12
|
+
redirect_to [params[:success_redirect], '?', { flash: :success_user_sign_in }.to_query].join || ::Tramway::Auth.root_path_for(@session_form.model.class)
|
18
13
|
else
|
19
|
-
|
14
|
+
redirect_to [params[:error_redirect], '?', { flash: :error_user_sign_in }.to_query].join || ::Tramway::Auth.root_path_for(@session_form.model.class)
|
20
15
|
end
|
21
16
|
end
|
22
17
|
|
23
18
|
def destroy
|
24
|
-
|
25
|
-
|
19
|
+
root_path = ::Tramway::Auth.root_path_for(current_user.class)
|
20
|
+
sign_out params[:model]
|
21
|
+
redirect_to params[:redirect] || root_path
|
26
22
|
end
|
27
23
|
|
28
24
|
private
|
29
25
|
|
30
26
|
def redirect_if_signed_in
|
31
|
-
redirect_to ::Tramway::Auth.
|
27
|
+
redirect_to ::Tramway::Auth.root_path_for(current_user.class) if params[:model].present? && signed_in?(params[:model].constantize) && request.env['PATH_INFO'] != ::Tramway::Auth.root_path_for(current_user.class)
|
32
28
|
end
|
33
29
|
end
|
34
30
|
end
|
@@ -4,19 +4,20 @@ class Tramway::Auth::Web::SignUpsController < Tramway::Auth::Web::ApplicationCon
|
|
4
4
|
before_action :check_authenticable_models
|
5
5
|
|
6
6
|
def create
|
7
|
-
@form = "
|
8
|
-
if @form.submit params[:
|
9
|
-
additional_params = { flash: :
|
10
|
-
url = if params[:
|
11
|
-
[params[:
|
7
|
+
@form = "Public::#{model_class}SignUpForm".constantize.new model_class.new
|
8
|
+
if @form.submit params[:user]
|
9
|
+
additional_params = { flash: :success_user_sign_up }
|
10
|
+
url = if params[:success_redirect].present?
|
11
|
+
[params[:success_redirect], '?', additional_params.to_query].join
|
12
12
|
else
|
13
13
|
Rails.application.routes.url_helpers.root_path(flash: :success)
|
14
14
|
end
|
15
|
+
sign_in @form.model if @form.class.sign_in_after
|
15
16
|
redirect_to url
|
16
17
|
else
|
17
|
-
additional_params = { flash: :
|
18
|
-
url = if params[:
|
19
|
-
[params[:
|
18
|
+
additional_params = { flash: :error_user_sign_up, errors: @form.errors.messages, record: @form.attributes }
|
19
|
+
url = if params[:error_redirect].present?
|
20
|
+
[params[:error_redirect], '?', additional_params.to_query].join
|
20
21
|
else
|
21
22
|
Rails.application.routes.url_helpers.root_path(**additional_params)
|
22
23
|
end
|
@@ -7,6 +7,12 @@ module Tramway
|
|
7
7
|
include ::FontAwesome5::Rails::IconHelper
|
8
8
|
include Tramway::Core::TitleHelper
|
9
9
|
include Tramway::Admin::NavbarHelper
|
10
|
+
include Tramway::Admin::CasesHelper
|
11
|
+
include Tramway::Admin::RussianCasesHelper
|
12
|
+
|
13
|
+
def decorator_class(model_name = nil)
|
14
|
+
"#{model_name || model_class}Decorator".constantize
|
15
|
+
end
|
10
16
|
end
|
11
17
|
end
|
12
18
|
end
|
data/config/routes.rb
CHANGED
data/lib/tramway/auth/version.rb
CHANGED
data/lib/tramway/auth.rb
CHANGED
@@ -28,10 +28,13 @@ module Tramway
|
|
28
28
|
@layout_path ||= 'tramway/user/application'
|
29
29
|
end
|
30
30
|
|
31
|
-
|
31
|
+
def root_path_for=(**options)
|
32
|
+
@root_path ||= {}
|
33
|
+
@root_path.merge! options
|
34
|
+
end
|
32
35
|
|
33
|
-
def
|
34
|
-
@root_path || '/'
|
36
|
+
def root_path_for(user_class)
|
37
|
+
@root_path&.dig(user_class) || '/'
|
35
38
|
end
|
36
39
|
end
|
37
40
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tramway-auth
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Pavel Kalashnikov
|
@@ -29,11 +29,11 @@ files:
|
|
29
29
|
- app/controllers/tramway/auth/web/sessions_controller.rb
|
30
30
|
- app/controllers/tramway/auth/web/sign_ups_controller.rb
|
31
31
|
- app/forms/tramway/auth/session_form.rb
|
32
|
+
- app/forms/tramway/auth/sign_up_form.rb
|
32
33
|
- app/helpers/tramway/auth/application_helper.rb
|
33
34
|
- app/jobs/tramway/auth/application_job.rb
|
34
35
|
- app/mailers/tramway/auth/application_mailer.rb
|
35
36
|
- app/models/tramway/auth/application_record.rb
|
36
|
-
- app/views/tramway/auth/web/sessions/new.html.haml
|
37
37
|
- config/locales/en/helpers.yml
|
38
38
|
- config/locales/en/locale.yml
|
39
39
|
- config/locales/ru/helpers.yml
|
@@ -1,7 +0,0 @@
|
|
1
|
-
- title
|
2
|
-
.row
|
3
|
-
.col-md-6
|
4
|
-
= simple_form_for @session_form.model, url: session_path, method: :post, html: { class: 'form-horizontal' } do |f|
|
5
|
-
= f.input :email, as: :string
|
6
|
-
= f.input :password
|
7
|
-
= f.button :submit, t('helpers.links.enter'), class: 'btn btn-success'
|