kaze 0.5.0 → 0.7.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (123) hide show
  1. checksums.yaml +4 -4
  2. data/lib/kaze/commands/install_command.rb +18 -4
  3. data/lib/kaze/commands/installs_hotwire_stack.rb +5 -2
  4. data/lib/kaze/commands/installs_inertia_stacks.rb +13 -3
  5. data/lib/kaze/version.rb +1 -1
  6. data/stubs/default/app/forms/auth/login_form.rb +2 -8
  7. data/stubs/default/app/forms/update_profile_information_form.rb +1 -1
  8. data/stubs/default/app/models/auth.rb +57 -0
  9. data/stubs/default/app/models/current.rb +1 -1
  10. data/stubs/default/app/validators/current_password_validator.rb +1 -1
  11. data/stubs/default/app/views/layouts/mailer.html.erb +367 -372
  12. data/stubs/default/app/views/layouts/mailer.text.erb +1 -4
  13. data/stubs/default/app/views/user_mailer/reset_password.html.erb +21 -26
  14. data/stubs/default/test/factories/users.rb +7 -0
  15. data/stubs/default/test/integration/auth/authentication_test.rb +43 -0
  16. data/stubs/default/test/integration/auth/password_reset_test.rb +41 -0
  17. data/stubs/default/test/integration/auth/registration_test.rb +21 -0
  18. data/stubs/default/test/integration/password_update_test.rb +28 -0
  19. data/stubs/default/test/integration/profile_test.rb +51 -0
  20. data/stubs/default/test/test_helper.rb +38 -0
  21. data/stubs/hotwire/app/components/dropdown_component.html.erb +17 -18
  22. data/stubs/hotwire/app/components/modal_component.html.erb +55 -59
  23. data/stubs/hotwire/app/controllers/application_controller.rb +1 -0
  24. data/stubs/hotwire/app/controllers/auth/authenticated_session_controller.rb +10 -7
  25. data/stubs/hotwire/app/controllers/auth/new_password_controller.rb +3 -1
  26. data/stubs/hotwire/app/controllers/auth/password_reset_link_controller.rb +3 -1
  27. data/stubs/hotwire/app/controllers/auth/registered_user_controller.rb +4 -2
  28. data/stubs/hotwire/app/controllers/concerns/authenticate.rb +5 -20
  29. data/stubs/hotwire/app/controllers/concerns/redirect_if_authenticated.rb +19 -0
  30. data/stubs/hotwire/app/controllers/concerns/set_current_auth.rb +9 -0
  31. data/stubs/hotwire/app/controllers/password_controller.rb +1 -1
  32. data/stubs/hotwire/app/controllers/profile_controller.rb +6 -4
  33. data/stubs/hotwire/app/controllers/welcome_controller.rb +1 -1
  34. data/stubs/hotwire/app/javascript/application.js +3 -3
  35. data/stubs/hotwire/app/views/auth/forgot_password.html.erb +12 -17
  36. data/stubs/hotwire/app/views/auth/login.html.erb +0 -9
  37. data/stubs/hotwire/app/views/auth/register.html.erb +0 -13
  38. data/stubs/hotwire/app/views/auth/reset_password.html.erb +0 -7
  39. data/stubs/hotwire/app/views/dashboard/index.html.erb +9 -10
  40. data/stubs/hotwire/app/views/layouts/_navigation.html.erb +77 -87
  41. data/stubs/hotwire/app/views/layouts/application.html.erb +0 -9
  42. data/stubs/hotwire/app/views/layouts/guest.html.erb +0 -6
  43. data/stubs/hotwire/app/views/profile/edit.html.erb +19 -22
  44. data/stubs/hotwire/app/views/profile/partials/_delete_user_form.html.erb +32 -42
  45. data/stubs/hotwire/app/views/profile/partials/_update_password_form.html.erb +42 -55
  46. data/stubs/hotwire/app/views/profile/partials/_update_profile_information_form.html.erb +36 -46
  47. data/stubs/hotwire/app/views/welcome/index.html.erb +34 -46
  48. data/stubs/hotwire/config/tailwind.config.js +2 -2
  49. data/stubs/inertia-common/app/controllers/application_controller.rb +1 -0
  50. data/stubs/inertia-common/app/controllers/auth/authenticated_session_controller.rb +10 -7
  51. data/stubs/inertia-common/app/controllers/auth/new_password_controller.rb +3 -1
  52. data/stubs/inertia-common/app/controllers/auth/password_reset_link_controller.rb +3 -1
  53. data/stubs/inertia-common/app/controllers/auth/registered_user_controller.rb +4 -2
  54. data/stubs/inertia-common/app/controllers/concerns/authenticate.rb +5 -20
  55. data/stubs/inertia-common/app/controllers/concerns/handle_inertia_requests.rb +1 -1
  56. data/stubs/inertia-common/app/controllers/concerns/redirect_if_authenticated.rb +19 -0
  57. data/stubs/inertia-common/app/controllers/concerns/set_current_auth.rb +9 -0
  58. data/stubs/inertia-common/app/controllers/password_controller.rb +1 -1
  59. data/stubs/inertia-common/app/controllers/profile_controller.rb +5 -3
  60. data/stubs/inertia-common/app/controllers/welcome_controller.rb +1 -1
  61. data/stubs/inertia-common/test/integration/password_update_test.rb +28 -0
  62. data/stubs/inertia-common/test/integration/profile_test.rb +51 -0
  63. data/stubs/inertia-react-ts/app/javascript/Components/ApplicationLogo.tsx +13 -9
  64. data/stubs/inertia-react-ts/app/javascript/Components/Checkbox.tsx +12 -12
  65. data/stubs/inertia-react-ts/app/javascript/Components/DangerButton.tsx +20 -15
  66. data/stubs/inertia-react-ts/app/javascript/Components/Dropdown.tsx +115 -88
  67. data/stubs/inertia-react-ts/app/javascript/Components/InputError.tsx +14 -7
  68. data/stubs/inertia-react-ts/app/javascript/Components/InputLabel.tsx +15 -7
  69. data/stubs/inertia-react-ts/app/javascript/Components/Modal.tsx +60 -60
  70. data/stubs/inertia-react-ts/app/javascript/Components/NavLink.tsx +21 -16
  71. data/stubs/inertia-react-ts/app/javascript/Components/PrimaryButton.tsx +20 -15
  72. data/stubs/inertia-react-ts/app/javascript/Components/ResponsiveNavLink.tsx +19 -14
  73. data/stubs/inertia-react-ts/app/javascript/Components/SecondaryButton.tsx +22 -16
  74. data/stubs/inertia-react-ts/app/javascript/Components/TextInput.tsx +32 -24
  75. data/stubs/inertia-react-ts/app/javascript/Layouts/AuthenticatedLayout.tsx +157 -117
  76. data/stubs/inertia-react-ts/app/javascript/Layouts/GuestLayout.tsx +15 -15
  77. data/stubs/inertia-react-ts/app/javascript/Pages/Auth/ForgotPassword.tsx +52 -49
  78. data/stubs/inertia-react-ts/app/javascript/Pages/Auth/Login.tsx +90 -82
  79. data/stubs/inertia-react-ts/app/javascript/Pages/Auth/Register.tsx +118 -115
  80. data/stubs/inertia-react-ts/app/javascript/Pages/Auth/ResetPassword.tsx +63 -60
  81. data/stubs/inertia-react-ts/app/javascript/Pages/Dashboard.tsx +23 -17
  82. data/stubs/inertia-react-ts/app/javascript/Pages/Profile/Edit.tsx +31 -27
  83. data/stubs/inertia-react-ts/app/javascript/Pages/Profile/Partials/DeleteUserForm.tsx +109 -99
  84. data/stubs/inertia-react-ts/app/javascript/Pages/Profile/Partials/UpdatePasswordForm.tsx +121 -113
  85. data/stubs/inertia-react-ts/app/javascript/Pages/Profile/Partials/UpdateProfileInformationForm.tsx +76 -69
  86. data/stubs/inertia-react-ts/app/javascript/Pages/Welcome.tsx +87 -63
  87. data/stubs/inertia-react-ts/app/javascript/entrypoints/application.tsx +32 -25
  88. data/stubs/inertia-react-ts/app/views/layouts/application.html.erb +0 -4
  89. data/stubs/inertia-react-ts/config/tailwind.config.js +2 -2
  90. data/stubs/inertia-react-ts/vite.config.ts +2 -5
  91. data/stubs/inertia-vue-ts/app/javascript/Components/ApplicationLogo.vue +10 -6
  92. data/stubs/inertia-vue-ts/app/javascript/Components/Checkbox.vue +18 -18
  93. data/stubs/inertia-vue-ts/app/javascript/Components/DangerButton.vue +5 -5
  94. data/stubs/inertia-vue-ts/app/javascript/Components/Dropdown.vue +60 -57
  95. data/stubs/inertia-vue-ts/app/javascript/Components/DropdownLink.vue +9 -9
  96. data/stubs/inertia-vue-ts/app/javascript/Components/InputError.vue +7 -7
  97. data/stubs/inertia-vue-ts/app/javascript/Components/InputLabel.vue +6 -6
  98. data/stubs/inertia-vue-ts/app/javascript/Components/Modal.vue +84 -74
  99. data/stubs/inertia-vue-ts/app/javascript/Components/NavLink.vue +12 -12
  100. data/stubs/inertia-vue-ts/app/javascript/Components/PrimaryButton.vue +5 -5
  101. data/stubs/inertia-vue-ts/app/javascript/Components/ResponsiveNavLink.vue +12 -12
  102. data/stubs/inertia-vue-ts/app/javascript/Components/SecondaryButton.vue +13 -13
  103. data/stubs/inertia-vue-ts/app/javascript/Components/TextInput.vue +13 -13
  104. data/stubs/inertia-vue-ts/app/javascript/Layouts/AuthenticatedLayout.vue +168 -136
  105. data/stubs/inertia-vue-ts/app/javascript/Layouts/GuestLayout.vue +15 -13
  106. data/stubs/inertia-vue-ts/app/javascript/Pages/Auth/ForgotPassword.vue +56 -49
  107. data/stubs/inertia-vue-ts/app/javascript/Pages/Auth/Login.vue +78 -72
  108. data/stubs/inertia-vue-ts/app/javascript/Pages/Auth/Register.vue +101 -97
  109. data/stubs/inertia-vue-ts/app/javascript/Pages/Auth/ResetPassword.vue +71 -68
  110. data/stubs/inertia-vue-ts/app/javascript/Pages/Dashboard.vue +22 -14
  111. data/stubs/inertia-vue-ts/app/javascript/Pages/Profile/Edit.vue +34 -30
  112. data/stubs/inertia-vue-ts/app/javascript/Pages/Profile/Partials/DeleteUserForm.vue +87 -83
  113. data/stubs/inertia-vue-ts/app/javascript/Pages/Profile/Partials/UpdatePasswordForm.vue +105 -98
  114. data/stubs/inertia-vue-ts/app/javascript/Pages/Profile/Partials/UpdateProfileInformationForm.vue +69 -59
  115. data/stubs/inertia-vue-ts/app/javascript/Pages/Welcome.vue +74 -47
  116. data/stubs/inertia-vue-ts/app/views/layouts/application.html.erb +0 -4
  117. data/stubs/inertia-vue-ts/config/tailwind.config.js +2 -2
  118. data/stubs/inertia-vue-ts/vite.config.ts +2 -5
  119. metadata +18 -6
  120. data/stubs/hotwire/bin/vite +0 -27
  121. data/stubs/inertia-common/Procfile.dev +0 -3
  122. /data/stubs/{hotwire → default}/Procfile.dev +0 -0
  123. /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: d47e0df09c4dc843e721f9df107ffcf181cab7f3922233b9b82ca6ecd1eafa20
4
- data.tar.gz: a932b205c852cf2825867f11b9a4d0c7f580a798be9b14c96b2745a705109105
3
+ metadata.gz: d575337712c9b2651ca597a59bb56dfea851cf552ff3d1e4878d2182b6bff4a5
4
+ data.tar.gz: 8e91a3772f93eba05dbe2e656a087c015789ccf75b70b5132fd2ba419009effc
5
5
  SHA512:
6
- metadata.gz: 5ab37093d08694cbdacd55fab7328c8c1c8042996605dffd16b48d709007377c5479c8a95085e611ff195961caee9b64815b13e9323134a981d81f11e776e3c2
7
- data.tar.gz: beb37ead1dd42947264d72f58a93b113795a0361cf9979d7f5166273702b2c515c262a67be9be218f5dc185a0f9897367c34bc0fc3167d1076aa5483558a00b8
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
- stdout.each { |line| say line }
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
- stderr.each { |line| say line, :red }
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.copy_entry("#{File.dirname(__FILE__)}/../../../stubs/hotwire/app/javascript", "#{Dir.pwd}/app/javascript")
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/hotwire/Procfile.dev", "#{Dir.pwd}/Procfile.dev")
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/inertia-common/Procfile.dev", "#{Dir.pwd}/Procfile.dev")
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/inertia-common/Procfile.dev", "#{Dir.pwd}/Procfile.dev")
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
@@ -1,3 +1,3 @@
1
1
  module Kaze
2
- VERSION = "0.5.0"
2
+ VERSION = '0.7.0'
3
3
  end
@@ -5,14 +5,8 @@ class Auth::LoginForm < ApplicationForm
5
5
  validates :password, presence: true
6
6
 
7
7
  def authenticate
8
- return nil if invalid?
8
+ return if invalid?
9
9
 
10
- user = User.authenticate_by(email: email, password: password)
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,3 +1,3 @@
1
1
  class Current < ActiveSupport::CurrentAttributes
2
- attribute :user
2
+ attribute :auth
3
3
  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