diff --git a/.gitignore b/.gitignore index 0fe39d9..aa25aa8 100755 --- a/.gitignore +++ b/.gitignore @@ -11,6 +11,8 @@ # Ignore the default SQLite database. /db/*.sqlite3 /db/*.sqlite3-journal +/db/test.sqlite3-shm +/db/test.sqlite3-wal # Ignore all logfiles and tempfiles. /log/* diff --git a/Gemfile b/Gemfile index 00ef2fb..0c8c90a 100644 --- a/Gemfile +++ b/Gemfile @@ -3,7 +3,7 @@ source 'https://rubygems.org' ruby '3.1.4' # Bundle edge Rails instead: gem 'rails', github: 'rails/rails' -gem 'rails', '~> 7.0.4' +gem 'rails', '~> 7.1.3' # Use SCSS for stylesheets gem 'sassc-rails', '~> 2.1.2' # Use Uglifier as compressor for JavaScript assets @@ -14,7 +14,7 @@ gem 'uglifier', '>= 1.3.0' # Use jquery as the JavaScript library gem 'jquery-rails' # Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder -gem 'jbuilder', '~> 2.5' +gem 'jbuilder', '~> 2.11' # bundle exec rake doc:rails generates the API under doc/api. # gem 'sdoc', '~> 0.4.0', group: :doc @@ -28,12 +28,12 @@ gem 'bcrypt', '~> 3.1.7' # gem 'capistrano-rails', group: :development # Use debugger -# gem 'debugger', group: [:development, :test] +gem 'debug', group: [:development, :test] gem 'haml' gem 'haml-rails' gem 'bootstrap', '~> 4.6.1' -gem 'sprockets-rails', '~> 3.4.2' +gem 'sprockets-rails', '~> 3.5.1' # gem 'font-awesome-sass', '~> 4.2.0' gem 'font-awesome-rails', '~> 4.7.0.0' @@ -44,10 +44,10 @@ gem 'turbo-rails' gem 'importmap-rails' # Reduces boot times through caching; required in config/boot.rb -gem 'bootsnap', '>= 1.1.0', require: false +gem 'bootsnap', '>= 1.18.0', require: false group :development, :test do - gem 'rspec-rails', '~> 5.0' + gem 'rspec-rails', '~> 6.0' end group :test do @@ -65,4 +65,5 @@ group :production do gem 'rails_12factor' end -gem 'puma', '< 7' +gem 'puma', '>= 5.0' +gem "redis", ">= 4.0.1" diff --git a/Gemfile.lock b/Gemfile.lock index 1937319..8fabf6e 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,77 +1,88 @@ GEM remote: https://rubygems.org/ specs: - actioncable (7.0.7.2) - actionpack (= 7.0.7.2) - activesupport (= 7.0.7.2) + actioncable (7.1.3.4) + actionpack (= 7.1.3.4) + activesupport (= 7.1.3.4) nio4r (~> 2.0) websocket-driver (>= 0.6.1) - actionmailbox (7.0.7.2) - actionpack (= 7.0.7.2) - activejob (= 7.0.7.2) - activerecord (= 7.0.7.2) - activestorage (= 7.0.7.2) - activesupport (= 7.0.7.2) + zeitwerk (~> 2.6) + actionmailbox (7.1.3.4) + actionpack (= 7.1.3.4) + activejob (= 7.1.3.4) + activerecord (= 7.1.3.4) + activestorage (= 7.1.3.4) + activesupport (= 7.1.3.4) mail (>= 2.7.1) net-imap net-pop net-smtp - actionmailer (7.0.7.2) - actionpack (= 7.0.7.2) - actionview (= 7.0.7.2) - activejob (= 7.0.7.2) - activesupport (= 7.0.7.2) + actionmailer (7.1.3.4) + actionpack (= 7.1.3.4) + actionview (= 7.1.3.4) + activejob (= 7.1.3.4) + activesupport (= 7.1.3.4) mail (~> 2.5, >= 2.5.4) net-imap net-pop net-smtp - rails-dom-testing (~> 2.0) - actionpack (7.0.7.2) - actionview (= 7.0.7.2) - activesupport (= 7.0.7.2) - rack (~> 2.0, >= 2.2.4) + rails-dom-testing (~> 2.2) + actionpack (7.1.3.4) + actionview (= 7.1.3.4) + activesupport (= 7.1.3.4) + nokogiri (>= 1.8.5) + racc + rack (>= 2.2.4) + rack-session (>= 1.0.1) rack-test (>= 0.6.3) - rails-dom-testing (~> 2.0) - rails-html-sanitizer (~> 1.0, >= 1.2.0) - actiontext (7.0.7.2) - actionpack (= 7.0.7.2) - activerecord (= 7.0.7.2) - activestorage (= 7.0.7.2) - activesupport (= 7.0.7.2) + rails-dom-testing (~> 2.2) + rails-html-sanitizer (~> 1.6) + actiontext (7.1.3.4) + actionpack (= 7.1.3.4) + activerecord (= 7.1.3.4) + activestorage (= 7.1.3.4) + activesupport (= 7.1.3.4) globalid (>= 0.6.0) nokogiri (>= 1.8.5) - actionview (7.0.7.2) - activesupport (= 7.0.7.2) + actionview (7.1.3.4) + activesupport (= 7.1.3.4) builder (~> 3.1) - erubi (~> 1.4) - rails-dom-testing (~> 2.0) - rails-html-sanitizer (~> 1.1, >= 1.2.0) - activejob (7.0.7.2) - activesupport (= 7.0.7.2) + erubi (~> 1.11) + rails-dom-testing (~> 2.2) + rails-html-sanitizer (~> 1.6) + activejob (7.1.3.4) + activesupport (= 7.1.3.4) globalid (>= 0.3.6) - activemodel (7.0.7.2) - activesupport (= 7.0.7.2) - activerecord (7.0.7.2) - activemodel (= 7.0.7.2) - activesupport (= 7.0.7.2) - activestorage (7.0.7.2) - actionpack (= 7.0.7.2) - activejob (= 7.0.7.2) - activerecord (= 7.0.7.2) - activesupport (= 7.0.7.2) + activemodel (7.1.3.4) + activesupport (= 7.1.3.4) + activerecord (7.1.3.4) + activemodel (= 7.1.3.4) + activesupport (= 7.1.3.4) + timeout (>= 0.4.0) + activestorage (7.1.3.4) + actionpack (= 7.1.3.4) + activejob (= 7.1.3.4) + activerecord (= 7.1.3.4) + activesupport (= 7.1.3.4) marcel (~> 1.0) - mini_mime (>= 1.1.0) - activesupport (7.0.7.2) + activesupport (7.1.3.4) + base64 + bigdecimal concurrent-ruby (~> 1.0, >= 1.0.2) + connection_pool (>= 2.2.5) + drb i18n (>= 1.6, < 2) minitest (>= 5.1) + mutex_m tzinfo (~> 2.0) addressable (2.8.5) public_suffix (>= 2.0.2, < 6.0) autoprefixer-rails (10.4.13.0) execjs (~> 2) + base64 (0.2.0) bcrypt (3.1.19) - bootsnap (1.16.0) + bigdecimal (3.1.8) + bootsnap (1.18.3) msgpack (~> 1.2) bootstrap (4.6.2) autoprefixer-rails (>= 9.1.0) @@ -79,7 +90,7 @@ GEM sassc-rails (>= 2.0.0) bootstrap-datepicker-rails (1.10.0.1) railties (>= 3.0) - builder (3.2.4) + builder (3.3.0) capybara (3.39.2) addressable matrix @@ -89,17 +100,22 @@ GEM rack-test (>= 0.6.3) regexp_parser (>= 1.5, < 3.0) xpath (~> 3.2) - concurrent-ruby (1.2.2) + concurrent-ruby (1.3.3) + connection_pool (2.4.1) crass (1.0.6) - date (3.3.3) - diff-lcs (1.5.0) - erubi (1.12.0) + date (3.3.4) + debug (1.9.2) + irb (~> 1.10) + reline (>= 0.3.8) + diff-lcs (1.5.1) + drb (2.2.1) + erubi (1.13.0) execjs (2.8.1) ffi (1.15.5) font-awesome-rails (4.7.0.8) railties (>= 3.2, < 8.0) - globalid (1.1.0) - activesupport (>= 5.0) + globalid (1.2.1) + activesupport (>= 6.1) haml (6.1.2) temple (>= 0.8.2) thor @@ -109,11 +125,15 @@ GEM activesupport (>= 5.1) haml (>= 4.0.6) railties (>= 5.1) - i18n (1.14.1) + i18n (1.14.5) concurrent-ruby (~> 1.0) importmap-rails (1.2.1) actionpack (>= 6.0.0) railties (>= 6.0.0) + io-console (0.7.2) + irb (1.14.0) + rdoc (>= 4.0.0) + reline (>= 0.4.2) jbuilder (2.11.5) actionview (>= 5.0.0) activesupport (>= 5.0.0) @@ -121,7 +141,7 @@ GEM rails-dom-testing (>= 1, < 3) railties (>= 4.2.0) thor (>= 0.14, < 2.0) - loofah (2.21.3) + loofah (2.22.0) crass (~> 1.0.2) nokogiri (>= 1.12.0) mail (2.8.1) @@ -129,49 +149,56 @@ GEM net-imap net-pop net-smtp - marcel (1.0.2) + marcel (1.0.4) matrix (0.4.2) - method_source (1.0.0) mini_mime (1.1.5) - mini_portile2 (2.8.4) - minitest (5.19.0) + mini_portile2 (2.8.7) + minitest (5.24.1) msgpack (1.7.2) - net-imap (0.3.7) + mutex_m (0.2.0) + net-imap (0.4.14) date net-protocol net-pop (0.1.2) net-protocol - net-protocol (0.2.1) + net-protocol (0.2.2) timeout - net-smtp (0.3.3) + net-smtp (0.5.0) net-protocol - nio4r (2.5.9) - nokogiri (1.15.4) + nio4r (2.7.3) + nokogiri (1.16.6) mini_portile2 (~> 2.8.2) racc (~> 1.4) pg (1.5.3) popper_js (1.16.1) + psych (5.1.2) + stringio public_suffix (5.0.3) puma (6.3.1) nio4r (~> 2.0) - racc (1.7.1) - rack (2.2.8) + racc (1.8.0) + rack (3.1.6) + rack-session (2.0.0) + rack (>= 3.0.0) rack-test (2.1.0) rack (>= 1.3) - rails (7.0.7.2) - actioncable (= 7.0.7.2) - actionmailbox (= 7.0.7.2) - actionmailer (= 7.0.7.2) - actionpack (= 7.0.7.2) - actiontext (= 7.0.7.2) - actionview (= 7.0.7.2) - activejob (= 7.0.7.2) - activemodel (= 7.0.7.2) - activerecord (= 7.0.7.2) - activestorage (= 7.0.7.2) - activesupport (= 7.0.7.2) + rackup (2.1.0) + rack (>= 3) + webrick (~> 1.8) + rails (7.1.3.4) + actioncable (= 7.1.3.4) + actionmailbox (= 7.1.3.4) + actionmailer (= 7.1.3.4) + actionpack (= 7.1.3.4) + actiontext (= 7.1.3.4) + actionview (= 7.1.3.4) + activejob (= 7.1.3.4) + activemodel (= 7.1.3.4) + activerecord (= 7.1.3.4) + activestorage (= 7.1.3.4) + activesupport (= 7.1.3.4) bundler (>= 1.15.0) - railties (= 7.0.7.2) + railties (= 7.1.3.4) rails-dom-testing (2.2.0) activesupport (>= 5.0.0) minitest @@ -184,32 +211,41 @@ GEM rails_stdout_logging rails_serve_static_assets (0.0.5) rails_stdout_logging (0.0.5) - railties (7.0.7.2) - actionpack (= 7.0.7.2) - activesupport (= 7.0.7.2) - method_source + railties (7.1.3.4) + actionpack (= 7.1.3.4) + activesupport (= 7.1.3.4) + irb + rackup (>= 1.0.0) rake (>= 12.2) - thor (~> 1.0) - zeitwerk (~> 2.5) - rake (13.0.6) + thor (~> 1.0, >= 1.2.2) + zeitwerk (~> 2.6) + rake (13.2.1) + rdoc (6.7.0) + psych (>= 4.0.0) + redis (5.2.0) + redis-client (>= 0.22.0) + redis-client (0.22.2) + connection_pool regexp_parser (2.8.1) - rspec-core (3.12.2) - rspec-support (~> 3.12.0) - rspec-expectations (3.12.3) + reline (0.5.9) + io-console (~> 0.5) + rspec-core (3.13.0) + rspec-support (~> 3.13.0) + rspec-expectations (3.13.1) diff-lcs (>= 1.2.0, < 2.0) - rspec-support (~> 3.12.0) - rspec-mocks (3.12.6) + rspec-support (~> 3.13.0) + rspec-mocks (3.13.1) diff-lcs (>= 1.2.0, < 2.0) - rspec-support (~> 3.12.0) - rspec-rails (5.1.2) - actionpack (>= 5.2) - activesupport (>= 5.2) - railties (>= 5.2) - rspec-core (~> 3.10) - rspec-expectations (~> 3.10) - rspec-mocks (~> 3.10) - rspec-support (~> 3.10) - rspec-support (3.12.1) + rspec-support (~> 3.13.0) + rspec-rails (6.1.3) + actionpack (>= 6.1) + activesupport (>= 6.1) + railties (>= 6.1) + rspec-core (~> 3.13) + rspec-expectations (~> 3.13) + rspec-mocks (~> 3.13) + rspec-support (~> 3.13) + rspec-support (3.13.1) sassc (2.4.0) ffi (~> 1.9) sassc-rails (2.1.2) @@ -222,16 +258,17 @@ GEM sprockets (4.2.0) concurrent-ruby (~> 1.0) rack (>= 2.2.4, < 4) - sprockets-rails (3.4.2) - actionpack (>= 5.2) - activesupport (>= 5.2) + sprockets-rails (3.5.1) + actionpack (>= 6.1) + activesupport (>= 6.1) sprockets (>= 3.0.0) sqlite3 (1.6.3) mini_portile2 (~> 2.8.0) + stringio (3.1.1) temple (0.10.2) - thor (1.2.2) + thor (1.3.1) tilt (2.2.0) - timeout (0.4.0) + timeout (0.4.1) turbo-rails (1.4.0) actionpack (>= 6.0.0) activejob (>= 6.0.0) @@ -240,36 +277,39 @@ GEM concurrent-ruby (~> 1.0) uglifier (4.2.0) execjs (>= 0.3.0, < 3) + webrick (1.8.1) websocket-driver (0.7.6) websocket-extensions (>= 0.1.0) websocket-extensions (0.1.5) xpath (3.2.0) nokogiri (~> 1.8) - zeitwerk (2.6.11) + zeitwerk (2.6.16) PLATFORMS ruby DEPENDENCIES bcrypt (~> 3.1.7) - bootsnap (>= 1.1.0) + bootsnap (>= 1.18.0) bootstrap (~> 4.6.1) bootstrap-datepicker-rails capybara (>= 2.15) + debug font-awesome-rails (~> 4.7.0.0) haml haml-rails importmap-rails - jbuilder (~> 2.5) + jbuilder (~> 2.11) jquery-rails pg (>= 0.18, < 2.0) - puma (< 7) - rails (~> 7.0.4) + puma (>= 5.0) + rails (~> 7.1.3) rails_12factor - rspec-rails (~> 5.0) + redis (>= 4.0.1) + rspec-rails (~> 6.0) sassc-rails (~> 2.1.2) spring - sprockets-rails (~> 3.4.2) + sprockets-rails (~> 3.5.1) sqlite3 turbo-rails uglifier (>= 1.3.0) diff --git a/app/controllers/sessions_controller.rb b/app/controllers/sessions_controller.rb index cae261e..b897cd9 100755 --- a/app/controllers/sessions_controller.rb +++ b/app/controllers/sessions_controller.rb @@ -7,9 +7,12 @@ def new def create user = User.where(email: params[:email]).take if user && user.authenticate(params[:password]) + if user.auth_token.nil? + user.password = params[:password] + user.regenerate_auth_token + end session[:user_id] = user.id - redirect_to root_url - flash[:notice] = "Login successful" + redirect_to root_url, notice: "Login successful" else flash.now.alert = "Please try again!" render :new, status: :unprocessable_entity diff --git a/app/models/user.rb b/app/models/user.rb index e49516b..2f34e0c 100755 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -3,6 +3,7 @@ class User < ActiveRecord::Base has_many :visits has_secure_password validations: false + has_secure_token :auth_token, length: 36, on: :initialize validates :password, presence: true diff --git a/config/application.rb b/config/application.rb index 870066e..411448b 100755 --- a/config/application.rb +++ b/config/application.rb @@ -9,7 +9,7 @@ module SessionsToDo class Application < Rails::Application # Initialize configuration defaults for originally generated Rails version. - config.load_defaults 7.0 + config.load_defaults 7.1 # Configuration for the application, engines, and railties goes here. # diff --git a/db/migrate/20240710002655_add_auth_token_to_user.rb b/db/migrate/20240710002655_add_auth_token_to_user.rb new file mode 100644 index 0000000..f8bc418 --- /dev/null +++ b/db/migrate/20240710002655_add_auth_token_to_user.rb @@ -0,0 +1,6 @@ +class AddAuthTokenToUser < ActiveRecord::Migration[7.0] + def change + add_column :users, :auth_token, :string + add_index :users, :auth_token, unique: true + end +end diff --git a/db/schema.rb b/db/schema.rb index aba74a0..2d692b0 100755 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema[7.0].define(version: 2022_02_20_065248) do +ActiveRecord::Schema[7.0].define(version: 2024_07_10_002655) do create_table "tasks", force: :cascade do |t| t.string "name", limit: 255 t.string "comment", limit: 255 @@ -28,6 +28,8 @@ t.string "password_digest", limit: 255 t.datetime "created_at", precision: nil t.datetime "updated_at", precision: nil + t.string "auth_token" + t.index ["auth_token"], name: "index_users_on_auth_token", unique: true end create_table "visits", force: :cascade do |t| diff --git a/spec/rails_helper.rb b/spec/rails_helper.rb index 59827d6..7ba2a6a 100755 --- a/spec/rails_helper.rb +++ b/spec/rails_helper.rb @@ -28,7 +28,7 @@ RSpec.configure do |config| # Remove this line if you're not using ActiveRecord or ActiveRecord fixtures - config.fixture_path = "#{::Rails.root}/spec/fixtures" + # config.fixture_path = "#{::Rails.root}/spec/fixtures" # If you're not using ActiveRecord, or you'd prefer not to run each of your # examples within a transaction, remove the following line or assign false