kaze 0.5.0 → 0.7.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/kaze/commands/install_command.rb +18 -4
- data/lib/kaze/commands/installs_hotwire_stack.rb +5 -2
- data/lib/kaze/commands/installs_inertia_stacks.rb +13 -3
- data/lib/kaze/version.rb +1 -1
- data/stubs/default/app/forms/auth/login_form.rb +2 -8
- data/stubs/default/app/forms/update_profile_information_form.rb +1 -1
- data/stubs/default/app/models/auth.rb +57 -0
- data/stubs/default/app/models/current.rb +1 -1
- data/stubs/default/app/validators/current_password_validator.rb +1 -1
- data/stubs/default/app/views/layouts/mailer.html.erb +367 -372
- data/stubs/default/app/views/layouts/mailer.text.erb +1 -4
- data/stubs/default/app/views/user_mailer/reset_password.html.erb +21 -26
- data/stubs/default/test/factories/users.rb +7 -0
- data/stubs/default/test/integration/auth/authentication_test.rb +43 -0
- data/stubs/default/test/integration/auth/password_reset_test.rb +41 -0
- data/stubs/default/test/integration/auth/registration_test.rb +21 -0
- data/stubs/default/test/integration/password_update_test.rb +28 -0
- data/stubs/default/test/integration/profile_test.rb +51 -0
- data/stubs/default/test/test_helper.rb +38 -0
- data/stubs/hotwire/app/components/dropdown_component.html.erb +17 -18
- data/stubs/hotwire/app/components/modal_component.html.erb +55 -59
- data/stubs/hotwire/app/controllers/application_controller.rb +1 -0
- data/stubs/hotwire/app/controllers/auth/authenticated_session_controller.rb +10 -7
- data/stubs/hotwire/app/controllers/auth/new_password_controller.rb +3 -1
- data/stubs/hotwire/app/controllers/auth/password_reset_link_controller.rb +3 -1
- data/stubs/hotwire/app/controllers/auth/registered_user_controller.rb +4 -2
- data/stubs/hotwire/app/controllers/concerns/authenticate.rb +5 -20
- data/stubs/hotwire/app/controllers/concerns/redirect_if_authenticated.rb +19 -0
- data/stubs/hotwire/app/controllers/concerns/set_current_auth.rb +9 -0
- data/stubs/hotwire/app/controllers/password_controller.rb +1 -1
- data/stubs/hotwire/app/controllers/profile_controller.rb +6 -4
- data/stubs/hotwire/app/controllers/welcome_controller.rb +1 -1
- data/stubs/hotwire/app/javascript/application.js +3 -3
- data/stubs/hotwire/app/views/auth/forgot_password.html.erb +12 -17
- data/stubs/hotwire/app/views/auth/login.html.erb +0 -9
- data/stubs/hotwire/app/views/auth/register.html.erb +0 -13
- data/stubs/hotwire/app/views/auth/reset_password.html.erb +0 -7
- data/stubs/hotwire/app/views/dashboard/index.html.erb +9 -10
- data/stubs/hotwire/app/views/layouts/_navigation.html.erb +77 -87
- data/stubs/hotwire/app/views/layouts/application.html.erb +0 -9
- data/stubs/hotwire/app/views/layouts/guest.html.erb +0 -6
- data/stubs/hotwire/app/views/profile/edit.html.erb +19 -22
- data/stubs/hotwire/app/views/profile/partials/_delete_user_form.html.erb +32 -42
- data/stubs/hotwire/app/views/profile/partials/_update_password_form.html.erb +42 -55
- data/stubs/hotwire/app/views/profile/partials/_update_profile_information_form.html.erb +36 -46
- data/stubs/hotwire/app/views/welcome/index.html.erb +34 -46
- data/stubs/hotwire/config/tailwind.config.js +2 -2
- data/stubs/inertia-common/app/controllers/application_controller.rb +1 -0
- data/stubs/inertia-common/app/controllers/auth/authenticated_session_controller.rb +10 -7
- data/stubs/inertia-common/app/controllers/auth/new_password_controller.rb +3 -1
- data/stubs/inertia-common/app/controllers/auth/password_reset_link_controller.rb +3 -1
- data/stubs/inertia-common/app/controllers/auth/registered_user_controller.rb +4 -2
- data/stubs/inertia-common/app/controllers/concerns/authenticate.rb +5 -20
- data/stubs/inertia-common/app/controllers/concerns/handle_inertia_requests.rb +1 -1
- data/stubs/inertia-common/app/controllers/concerns/redirect_if_authenticated.rb +19 -0
- data/stubs/inertia-common/app/controllers/concerns/set_current_auth.rb +9 -0
- data/stubs/inertia-common/app/controllers/password_controller.rb +1 -1
- data/stubs/inertia-common/app/controllers/profile_controller.rb +5 -3
- data/stubs/inertia-common/app/controllers/welcome_controller.rb +1 -1
- data/stubs/inertia-common/test/integration/password_update_test.rb +28 -0
- data/stubs/inertia-common/test/integration/profile_test.rb +51 -0
- data/stubs/inertia-react-ts/app/javascript/Components/ApplicationLogo.tsx +13 -9
- data/stubs/inertia-react-ts/app/javascript/Components/Checkbox.tsx +12 -12
- data/stubs/inertia-react-ts/app/javascript/Components/DangerButton.tsx +20 -15
- data/stubs/inertia-react-ts/app/javascript/Components/Dropdown.tsx +115 -88
- data/stubs/inertia-react-ts/app/javascript/Components/InputError.tsx +14 -7
- data/stubs/inertia-react-ts/app/javascript/Components/InputLabel.tsx +15 -7
- data/stubs/inertia-react-ts/app/javascript/Components/Modal.tsx +60 -60
- data/stubs/inertia-react-ts/app/javascript/Components/NavLink.tsx +21 -16
- data/stubs/inertia-react-ts/app/javascript/Components/PrimaryButton.tsx +20 -15
- data/stubs/inertia-react-ts/app/javascript/Components/ResponsiveNavLink.tsx +19 -14
- data/stubs/inertia-react-ts/app/javascript/Components/SecondaryButton.tsx +22 -16
- data/stubs/inertia-react-ts/app/javascript/Components/TextInput.tsx +32 -24
- data/stubs/inertia-react-ts/app/javascript/Layouts/AuthenticatedLayout.tsx +157 -117
- data/stubs/inertia-react-ts/app/javascript/Layouts/GuestLayout.tsx +15 -15
- data/stubs/inertia-react-ts/app/javascript/Pages/Auth/ForgotPassword.tsx +52 -49
- data/stubs/inertia-react-ts/app/javascript/Pages/Auth/Login.tsx +90 -82
- data/stubs/inertia-react-ts/app/javascript/Pages/Auth/Register.tsx +118 -115
- data/stubs/inertia-react-ts/app/javascript/Pages/Auth/ResetPassword.tsx +63 -60
- data/stubs/inertia-react-ts/app/javascript/Pages/Dashboard.tsx +23 -17
- data/stubs/inertia-react-ts/app/javascript/Pages/Profile/Edit.tsx +31 -27
- data/stubs/inertia-react-ts/app/javascript/Pages/Profile/Partials/DeleteUserForm.tsx +109 -99
- data/stubs/inertia-react-ts/app/javascript/Pages/Profile/Partials/UpdatePasswordForm.tsx +121 -113
- data/stubs/inertia-react-ts/app/javascript/Pages/Profile/Partials/UpdateProfileInformationForm.tsx +76 -69
- data/stubs/inertia-react-ts/app/javascript/Pages/Welcome.tsx +87 -63
- data/stubs/inertia-react-ts/app/javascript/entrypoints/application.tsx +32 -25
- data/stubs/inertia-react-ts/app/views/layouts/application.html.erb +0 -4
- data/stubs/inertia-react-ts/config/tailwind.config.js +2 -2
- data/stubs/inertia-react-ts/vite.config.ts +2 -5
- data/stubs/inertia-vue-ts/app/javascript/Components/ApplicationLogo.vue +10 -6
- data/stubs/inertia-vue-ts/app/javascript/Components/Checkbox.vue +18 -18
- data/stubs/inertia-vue-ts/app/javascript/Components/DangerButton.vue +5 -5
- data/stubs/inertia-vue-ts/app/javascript/Components/Dropdown.vue +60 -57
- data/stubs/inertia-vue-ts/app/javascript/Components/DropdownLink.vue +9 -9
- data/stubs/inertia-vue-ts/app/javascript/Components/InputError.vue +7 -7
- data/stubs/inertia-vue-ts/app/javascript/Components/InputLabel.vue +6 -6
- data/stubs/inertia-vue-ts/app/javascript/Components/Modal.vue +84 -74
- data/stubs/inertia-vue-ts/app/javascript/Components/NavLink.vue +12 -12
- data/stubs/inertia-vue-ts/app/javascript/Components/PrimaryButton.vue +5 -5
- data/stubs/inertia-vue-ts/app/javascript/Components/ResponsiveNavLink.vue +12 -12
- data/stubs/inertia-vue-ts/app/javascript/Components/SecondaryButton.vue +13 -13
- data/stubs/inertia-vue-ts/app/javascript/Components/TextInput.vue +13 -13
- data/stubs/inertia-vue-ts/app/javascript/Layouts/AuthenticatedLayout.vue +168 -136
- data/stubs/inertia-vue-ts/app/javascript/Layouts/GuestLayout.vue +15 -13
- data/stubs/inertia-vue-ts/app/javascript/Pages/Auth/ForgotPassword.vue +56 -49
- data/stubs/inertia-vue-ts/app/javascript/Pages/Auth/Login.vue +78 -72
- data/stubs/inertia-vue-ts/app/javascript/Pages/Auth/Register.vue +101 -97
- data/stubs/inertia-vue-ts/app/javascript/Pages/Auth/ResetPassword.vue +71 -68
- data/stubs/inertia-vue-ts/app/javascript/Pages/Dashboard.vue +22 -14
- data/stubs/inertia-vue-ts/app/javascript/Pages/Profile/Edit.vue +34 -30
- data/stubs/inertia-vue-ts/app/javascript/Pages/Profile/Partials/DeleteUserForm.vue +87 -83
- data/stubs/inertia-vue-ts/app/javascript/Pages/Profile/Partials/UpdatePasswordForm.vue +105 -98
- data/stubs/inertia-vue-ts/app/javascript/Pages/Profile/Partials/UpdateProfileInformationForm.vue +69 -59
- data/stubs/inertia-vue-ts/app/javascript/Pages/Welcome.vue +74 -47
- data/stubs/inertia-vue-ts/app/views/layouts/application.html.erb +0 -4
- data/stubs/inertia-vue-ts/config/tailwind.config.js +2 -2
- data/stubs/inertia-vue-ts/vite.config.ts +2 -5
- metadata +18 -6
- data/stubs/hotwire/bin/vite +0 -27
- data/stubs/inertia-common/Procfile.dev +0 -3
- /data/stubs/{hotwire → default}/Procfile.dev +0 -0
- /data/stubs/hotwire/app/javascript/{alpinejs.js → alpinejs.stub} +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d575337712c9b2651ca597a59bb56dfea851cf552ff3d1e4878d2182b6bff4a5
|
4
|
+
data.tar.gz: 8e91a3772f93eba05dbe2e656a087c015789ccf75b70b5132fd2ba419009effc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a2562af016d65f894dd72e473a4b159bbf27799018872f4c5b4d29c8fb3290af031c3f5b2f487a3f2ef8552ed95247c2ad2a78cdbb31c62a91583376e1ca051c
|
7
|
+
data.tar.gz: 5d110365415c3d2878dbfb8c4f364af7200f5cfba500731ced7c47fbdde0680d9d27ac28e4c1c681f8804d28c397d5754fcde08ec4d6ecb7a973c313ebe5127b
|
@@ -62,18 +62,32 @@ class Kaze::Commands::InstallCommand < Thor
|
|
62
62
|
end
|
63
63
|
end
|
64
64
|
|
65
|
+
def install_tests
|
66
|
+
ensure_directory_exists("#{Dir.pwd}/test/factories")
|
67
|
+
ensure_directory_exists("#{Dir.pwd}/test/integration")
|
68
|
+
FileUtils.copy_file("#{File.dirname(__FILE__)}/../../../stubs/default/test/test_helper.rb", "#{Dir.pwd}/test/test_helper.rb")
|
69
|
+
FileUtils.copy_entry("#{File.dirname(__FILE__)}/../../../stubs/default/test/factories", "#{Dir.pwd}/test/factories")
|
70
|
+
FileUtils.copy_entry("#{File.dirname(__FILE__)}/../../../stubs/default/test/integration", "#{Dir.pwd}/test/integration")
|
71
|
+
end
|
72
|
+
|
65
73
|
def ensure_directory_exists(path)
|
66
74
|
FileUtils.mkdir_p(path) unless File.directory?(path)
|
67
75
|
end
|
68
76
|
|
69
77
|
def run_command(command)
|
70
78
|
Open3.popen3(command) do |stdin, stdout, stderr, wait_thr|
|
71
|
-
Thread.new do
|
72
|
-
|
79
|
+
stdout_thread = Thread.new do
|
80
|
+
while (line = stdout.gets) do
|
81
|
+
say line
|
82
|
+
end
|
73
83
|
end
|
74
|
-
Thread.new do
|
75
|
-
|
84
|
+
stderr_thread = Thread.new do
|
85
|
+
while (line = stderr.gets) do
|
86
|
+
say line, :red
|
87
|
+
end
|
76
88
|
end
|
89
|
+
stdout_thread.join
|
90
|
+
stderr_thread.join
|
77
91
|
wait_thr.value
|
78
92
|
end
|
79
93
|
end
|
@@ -6,6 +6,7 @@ module Kaze::Commands::InstallsHotwireStack
|
|
6
6
|
return unless remove_gems([ 'sprockets-rails', 'stimulus-rails' ])
|
7
7
|
return unless install_gems([ 'propshaft', 'view_component', 'tailwindcss-rails', 'turbo-rails', 'dotenv', 'bcrypt' ])
|
8
8
|
return unless install_gems([ 'hotwire-livereload' ], 'development')
|
9
|
+
return unless install_gems([ 'factory_bot_rails', 'faker' ], 'development, test')
|
9
10
|
|
10
11
|
# Controllers...
|
11
12
|
FileUtils.copy_entry("#{File.dirname(__FILE__)}/../../../stubs/hotwire/app/controllers", "#{Dir.pwd}/app/controllers")
|
@@ -37,10 +38,12 @@ module Kaze::Commands::InstallsHotwireStack
|
|
37
38
|
ensure_directory_exists("#{Dir.pwd}/app/components")
|
38
39
|
FileUtils.copy_entry("#{File.dirname(__FILE__)}/../../../stubs/hotwire/app/components", "#{Dir.pwd}/app/components")
|
39
40
|
ensure_directory_exists("#{Dir.pwd}/app/javascript")
|
40
|
-
FileUtils.
|
41
|
+
FileUtils.copy_file("#{File.dirname(__FILE__)}/../../../stubs/hotwire/app/javascript/application.js", "#{Dir.pwd}/app/javascript/application.js")
|
42
|
+
FileUtils.copy_file("#{File.dirname(__FILE__)}/../../../stubs/hotwire/app/javascript/alpinejs.stub", "#{Dir.pwd}/app/javascript/alpinejs.js")
|
41
43
|
FileUtils.copy_file("#{File.dirname(__FILE__)}/../../../stubs/hotwire/config/importmap.rb", "#{Dir.pwd}/config/importmap.rb")
|
42
44
|
|
43
45
|
# Tests...
|
46
|
+
install_tests
|
44
47
|
|
45
48
|
# Routes...
|
46
49
|
FileUtils.copy_file("#{File.dirname(__FILE__)}/../../../stubs/default/config/routes.rb", "#{Dir.pwd}/config/routes.rb")
|
@@ -53,7 +56,7 @@ module Kaze::Commands::InstallsHotwireStack
|
|
53
56
|
FileUtils.copy_file("#{File.dirname(__FILE__)}/../../../stubs/default/app/assets/stylesheets/application.tailwind.css", "#{Dir.pwd}/app/assets/stylesheets/application.tailwind.css")
|
54
57
|
FileUtils.copy_file("#{File.dirname(__FILE__)}/../../../stubs/hotwire/config/tailwind.config.js", "#{Dir.pwd}/config/tailwind.config.js")
|
55
58
|
FileUtils.copy_file("#{File.dirname(__FILE__)}/../../../stubs/default/bin/dev", "#{Dir.pwd}/bin/dev")
|
56
|
-
FileUtils.copy_file("#{File.dirname(__FILE__)}/../../../stubs/
|
59
|
+
FileUtils.copy_file("#{File.dirname(__FILE__)}/../../../stubs/default/Procfile.dev", "#{Dir.pwd}/Procfile.dev")
|
57
60
|
run_command('rails tailwindcss:build')
|
58
61
|
|
59
62
|
say ''
|
@@ -5,6 +5,7 @@ module Kaze::Commands::InstallsInertiaStacks
|
|
5
5
|
# Gems...
|
6
6
|
return unless remove_gems([ 'sprockets-rails', 'turbo-rails', 'stimulus-rails' ])
|
7
7
|
return unless install_gems([ 'propshaft', 'tailwindcss-rails', 'inertia_rails', 'vite_rails', 'dotenv', 'bcrypt', 'js-routes' ])
|
8
|
+
return unless install_gems([ 'factory_bot_rails', 'faker' ], 'development, test')
|
8
9
|
|
9
10
|
# NPM Packages...
|
10
11
|
FileUtils.copy_file("#{File.dirname(__FILE__)}/../../../stubs/inertia-react-ts/package.json", "#{Dir.pwd}/package.json")
|
@@ -40,6 +41,8 @@ module Kaze::Commands::InstallsInertiaStacks
|
|
40
41
|
FileUtils.copy_entry("#{File.dirname(__FILE__)}/../../../stubs/inertia-react-ts/app/javascript", "#{Dir.pwd}/app/javascript")
|
41
42
|
|
42
43
|
# Tests...
|
44
|
+
install_tests
|
45
|
+
FileUtils.copy_entry("#{File.dirname(__FILE__)}/../../../stubs/inertia-common/test/integration", "#{Dir.pwd}/test/integration")
|
43
46
|
|
44
47
|
# Routes...
|
45
48
|
FileUtils.copy_file("#{File.dirname(__FILE__)}/../../../stubs/default/config/routes.rb", "#{Dir.pwd}/config/routes.rb")
|
@@ -56,8 +59,10 @@ module Kaze::Commands::InstallsInertiaStacks
|
|
56
59
|
FileUtils.copy_file("#{File.dirname(__FILE__)}/../../../stubs/inertia-react-ts/vite.config.ts", "#{Dir.pwd}/vite.config.ts")
|
57
60
|
FileUtils.copy_file("#{File.dirname(__FILE__)}/../../../stubs/default/bin/dev", "#{Dir.pwd}/bin/dev")
|
58
61
|
FileUtils.copy_file("#{File.dirname(__FILE__)}/../../../stubs/inertia-common/bin/vite", "#{Dir.pwd}/bin/vite")
|
59
|
-
FileUtils.copy_file("#{File.dirname(__FILE__)}/../../../stubs/
|
62
|
+
FileUtils.copy_file("#{File.dirname(__FILE__)}/../../../stubs/default/Procfile.dev", "#{Dir.pwd}/Procfile.dev")
|
63
|
+
File.write("#{Dir.pwd}/Procfile.dev", "#{File.read("#{Dir.pwd}/Procfile.dev")}\nvite: bin/vite dev\n")
|
60
64
|
run_command('rails generate js_routes:middleware')
|
65
|
+
run_command('rails tailwindcss:build')
|
61
66
|
|
62
67
|
say ''
|
63
68
|
say 'Installing and building Node dependencies.', :magenta
|
@@ -78,8 +83,9 @@ module Kaze::Commands::InstallsInertiaStacks
|
|
78
83
|
|
79
84
|
def install_inertia_vue_stack
|
80
85
|
# Gems...
|
81
|
-
return unless remove_gems([ 'sprockets-rails' ])
|
86
|
+
return unless remove_gems([ 'sprockets-rails', 'turbo-rails', 'stimulus-rails' ])
|
82
87
|
return unless install_gems([ 'propshaft', 'tailwindcss-rails', 'inertia_rails', 'vite_rails', 'dotenv', 'bcrypt', 'js-routes' ])
|
88
|
+
return unless install_gems([ 'factory_bot_rails', 'faker' ], 'development, test')
|
83
89
|
|
84
90
|
# NPM Packages...
|
85
91
|
FileUtils.copy_file("#{File.dirname(__FILE__)}/../../../stubs/inertia-vue-ts/package.json", "#{Dir.pwd}/package.json")
|
@@ -115,6 +121,8 @@ module Kaze::Commands::InstallsInertiaStacks
|
|
115
121
|
FileUtils.copy_entry("#{File.dirname(__FILE__)}/../../../stubs/inertia-vue-ts/app/javascript", "#{Dir.pwd}/app/javascript")
|
116
122
|
|
117
123
|
# Tests...
|
124
|
+
install_tests
|
125
|
+
FileUtils.copy_entry("#{File.dirname(__FILE__)}/../../../stubs/inertia-common/test/integration", "#{Dir.pwd}/test/integration")
|
118
126
|
|
119
127
|
# Routes...
|
120
128
|
FileUtils.copy_file("#{File.dirname(__FILE__)}/../../../stubs/default/config/routes.rb", "#{Dir.pwd}/config/routes.rb")
|
@@ -131,8 +139,10 @@ module Kaze::Commands::InstallsInertiaStacks
|
|
131
139
|
FileUtils.copy_file("#{File.dirname(__FILE__)}/../../../stubs/inertia-vue-ts/vite.config.ts", "#{Dir.pwd}/vite.config.ts")
|
132
140
|
FileUtils.copy_file("#{File.dirname(__FILE__)}/../../../stubs/default/bin/dev", "#{Dir.pwd}/bin/dev")
|
133
141
|
FileUtils.copy_file("#{File.dirname(__FILE__)}/../../../stubs/inertia-common/bin/vite", "#{Dir.pwd}/bin/vite")
|
134
|
-
FileUtils.copy_file("#{File.dirname(__FILE__)}/../../../stubs/
|
142
|
+
FileUtils.copy_file("#{File.dirname(__FILE__)}/../../../stubs/default/Procfile.dev", "#{Dir.pwd}/Procfile.dev")
|
143
|
+
File.write("#{Dir.pwd}/Procfile.dev", "#{File.read("#{Dir.pwd}/Procfile.dev")}\nvite: bin/vite dev\n")
|
135
144
|
run_command('rails generate js_routes:middleware')
|
145
|
+
run_command('rails tailwindcss:build')
|
136
146
|
|
137
147
|
say ''
|
138
148
|
say 'Installing and building Node dependencies.', :magenta
|
data/lib/kaze/version.rb
CHANGED
@@ -5,14 +5,8 @@ class Auth::LoginForm < ApplicationForm
|
|
5
5
|
validates :password, presence: true
|
6
6
|
|
7
7
|
def authenticate
|
8
|
-
return
|
8
|
+
return if invalid?
|
9
9
|
|
10
|
-
|
11
|
-
|
12
|
-
return user if user.present?
|
13
|
-
|
14
|
-
errors.add(:email, message: 'These credentials do not match our records.')
|
15
|
-
|
16
|
-
nil
|
10
|
+
errors.add(:email, message: 'These credentials do not match our records.') unless Current.auth.attempt(email: email, password: password)
|
17
11
|
end
|
18
12
|
end
|
@@ -2,5 +2,5 @@ class UpdateProfileInformationForm < ApplicationForm
|
|
2
2
|
attr_accessor :name, :email
|
3
3
|
|
4
4
|
validates :name, presence: true
|
5
|
-
validates :email, presence: true, lowercase: true, email: true, uniqueness: { model: User, attribute: :email, conditions: -> { where.not(id: Current.user.id) } }
|
5
|
+
validates :email, presence: true, lowercase: true, email: true, uniqueness: { model: User, attribute: :email, conditions: -> { where.not(id: Current.auth.user.id) } }
|
6
6
|
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
class Auth
|
2
|
+
attr_reader :name, :session, :user
|
3
|
+
|
4
|
+
def initialize(name, session)
|
5
|
+
@name = name
|
6
|
+
@session = session
|
7
|
+
end
|
8
|
+
|
9
|
+
def get_user
|
10
|
+
return @user unless @user.nil?
|
11
|
+
|
12
|
+
id = @session[get_name]
|
13
|
+
|
14
|
+
@user = User.find_by(id: id) unless id.nil?
|
15
|
+
|
16
|
+
@user
|
17
|
+
end
|
18
|
+
|
19
|
+
def get_name
|
20
|
+
"login_#{@name}_#{Digest::SHA1.hexdigest(self.class.name)}"
|
21
|
+
end
|
22
|
+
|
23
|
+
def check?
|
24
|
+
not get_user.nil?
|
25
|
+
end
|
26
|
+
|
27
|
+
def attempt(credentials = {})
|
28
|
+
user = User.authenticate_by(credentials)
|
29
|
+
|
30
|
+
return false if user.nil?
|
31
|
+
|
32
|
+
login user
|
33
|
+
|
34
|
+
true
|
35
|
+
end
|
36
|
+
|
37
|
+
def login(user)
|
38
|
+
update_session user.id
|
39
|
+
|
40
|
+
set_user user
|
41
|
+
end
|
42
|
+
|
43
|
+
def set_user(user)
|
44
|
+
@user = user
|
45
|
+
end
|
46
|
+
|
47
|
+
def logout
|
48
|
+
@session[get_name] = nil
|
49
|
+
@user = nil
|
50
|
+
end
|
51
|
+
|
52
|
+
private
|
53
|
+
|
54
|
+
def update_session(id)
|
55
|
+
@session[get_name] = id
|
56
|
+
end
|
57
|
+
end
|
@@ -1,5 +1,5 @@
|
|
1
1
|
class CurrentPasswordValidator < ActiveModel::EachValidator
|
2
2
|
def validate_each(record, attribute, value)
|
3
|
-
record.errors.add attribute, 'The password is incorrect.' unless Current.user&.authenticate(value)
|
3
|
+
record.errors.add attribute, 'The password is incorrect.' unless Current.auth.user&.authenticate(value)
|
4
4
|
end
|
5
5
|
end
|