From d133750802a83946a4e09de8433f3dda0e17af4e Mon Sep 17 00:00:00 2001 From: Aidan Cornelius-Bell Date: Mon, 23 Sep 2024 10:31:47 +0930 Subject: [PATCH] Confirmable on devise --- Gemfile | 1 + Gemfile.lock | 8 +++ app/assets/stylesheets/application.css | 28 +++++++++- app/models/user.rb | 3 +- app/views/devise/base_template.html.erb | 23 ++------ app/views/devise/confirmations/new.html.erb | 27 +++++----- .../mailer/confirmation_instructions.html.erb | 10 +++- app/views/devise/registrations/edit.html.erb | 25 ++++++--- app/views/devise/shared/_links.html.erb | 50 ++++++++++-------- app/views/layouts/application.html.erb | 6 ++- {app/controllers => config}/.DS_Store | Bin 6148 -> 6148 bytes config/environments/development.rb | 3 ++ config/environments/production.rb | 1 + config/initializers/devise.rb | 2 +- ...0240923002439_add_confirmable_to_devise.rb | 16 ++++++ db/schema.rb | 7 ++- 16 files changed, 141 insertions(+), 69 deletions(-) copy {app/controllers => config}/.DS_Store (97%) create mode 100644 db/migrate/20240923002439_add_confirmable_to_devise.rb diff --git a/Gemfile b/Gemfile index 53921c9..65bc375 100644 --- a/Gemfile +++ b/Gemfile @@ -50,6 +50,7 @@ end group :development do # Use console on exceptions pages [https://github.com/rails/web-console] gem "web-console" + gem "letter_opener" end group :test do diff --git a/Gemfile.lock b/Gemfile.lock index a891a36..23fc602 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -92,6 +92,8 @@ GEM rack-test (>= 0.6.3) regexp_parser (>= 1.5, < 3.0) xpath (~> 3.2) + childprocess (5.1.0) + logger (~> 1.5) concurrent-ruby (1.3.4) connection_pool (2.4.1) crass (1.0.6) @@ -137,6 +139,11 @@ GEM kaminari-core (= 1.2.2) kaminari-core (1.2.2) language_server-protocol (3.17.0.3) + launchy (3.0.1) + addressable (~> 2.8) + childprocess (~> 5.0) + letter_opener (1.10.0) + launchy (>= 2.2, < 4) logger (1.6.1) loofah (2.22.0) crass (~> 1.0.2) @@ -322,6 +329,7 @@ DEPENDENCIES httparty jsonapi-serializer kaminari + letter_opener mysql2 (~> 0.5) puma (>= 5.0) rails (~> 7.2.1) diff --git a/app/assets/stylesheets/application.css b/app/assets/stylesheets/application.css index d2da70f..2109333 100644 --- a/app/assets/stylesheets/application.css +++ b/app/assets/stylesheets/application.css @@ -246,6 +246,11 @@ hr { border-left: none; } +.devise-links { + padding-top: 1rem; + border-top: 1px solid var(--accent-a); +} + footer { margin-top: 3rem; border-top: 1px solid var(--accent-a); @@ -408,6 +413,7 @@ button, input[type="submit"], .button { color: var(--link-color); border-radius: 0.25rem; margin-right: 0.5rem; + cursor: pointer; } .button.small { @@ -420,7 +426,7 @@ button, input[type="submit"], .button { color: var(--body-text); } -.button:hover { +button:hover, input[type="submit"]:hover, .button:hover { opacity: 0.8; text-decoration: none; } @@ -436,6 +442,26 @@ ul .post-item a:visited { color: var(--accent-c); } +.marquee { + position: relative; + width: 100vw; + max-width: 100%; + height: 18px; + overflow-x: hidden; +} + +.track { + position: absolute; + white-space: nowrap; + will-change: transform; + animation: marquee 32s linear infinite; +} + +@keyframes marquee { + from { transform: translateX(0); } + to { transform: translateX(-50%); } +} + @media (max-width: 480px) { .container, diff --git a/app/models/user.rb b/app/models/user.rb index 2363f92..9c650ff 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -2,7 +2,8 @@ class User < ApplicationRecord # Include default devise modules. Others available are: # :confirmable, :lockable, :timeoutable, :trackable and :omniauthable devise :database_authenticatable, :registerable, - :recoverable, :rememberable, :validatable + :recoverable, :rememberable, :validatable, + :confirmable validates :first_name, presence: true validates :last_name, presence: true diff --git a/app/views/devise/base_template.html.erb b/app/views/devise/base_template.html.erb index 318e63c..7c29747 100644 --- a/app/views/devise/base_template.html.erb +++ b/app/views/devise/base_template.html.erb @@ -3,8 +3,9 @@ <%= yield(:form_content) %> - @@ -37,28 +38,12 @@ } .actions { margin-top: 20px; - text-align: center; - } - .actions input[type="submit"] { - background-color: #007bff; - color: white; - padding: 10px 20px; - border: none; - border-radius: 4px; - cursor: pointer; - } - .actions input[type="submit"]:hover { - background-color: #0056b3; } .links { margin-top: 20px; - text-align: center; } .links a { - color: #007bff; text-decoration: none; - } - .links a:hover { - text-decoration: underline; + margin-bottom: 4px; } \ No newline at end of file diff --git a/app/views/devise/confirmations/new.html.erb b/app/views/devise/confirmations/new.html.erb index b12dd0c..4681e7c 100644 --- a/app/views/devise/confirmations/new.html.erb +++ b/app/views/devise/confirmations/new.html.erb @@ -1,16 +1,19 @@ -

Resend confirmation instructions

+<% content_for :title do %>Resend email confirmation<% end %> -<%= form_for(resource, as: resource_name, url: confirmation_path(resource_name), html: { method: :post }) do |f| %> - <%= render "devise/shared/error_messages", resource: resource %> +<% content_for :form_content do %> -
- <%= f.label :email %>
- <%= f.email_field :email, autofocus: true, autocomplete: "email", value: (resource.pending_reconfirmation? ? resource.unconfirmed_email : resource.email) %> -
- -
- <%= f.submit "Resend confirmation instructions" %> -
+ <%= form_for(resource, as: resource_name, url: confirmation_path(resource_name), html: { method: :post }) do |f| %> + <%= render "devise/shared/error_messages", resource: resource %> + +
+ <%= f.label :email %>
+ <%= f.email_field :email, autofocus: true, autocomplete: "email", value: (resource.pending_reconfirmation? ? resource.unconfirmed_email : resource.email) %> +
+ +
+ <%= f.submit "Resend confirmation instructions" %> +
+ <% end %> <% end %> -<%= render "devise/shared/links" %> +<%= render template: 'devise/base_template' %> \ No newline at end of file diff --git a/app/views/devise/mailer/confirmation_instructions.html.erb b/app/views/devise/mailer/confirmation_instructions.html.erb index dc55f64..f738f58 100644 --- a/app/views/devise/mailer/confirmation_instructions.html.erb +++ b/app/views/devise/mailer/confirmation_instructions.html.erb @@ -1,5 +1,11 @@ -

Welcome <%= @email %>!

+

Welcome to mind reader.

-

You can confirm your account email through the link below:

+

You are receiving this email at <%= @email %> to confirm you really own this address. This is for spam prevention purposes.

+ +

If you made an account on mind reader you can confirm your account email through the link below:

<%= link_to 'Confirm my account', confirmation_url(@resource, confirmation_token: @token) %>

+ +

If you did not make an account you can safely disregard this message and you will not receive further emails.

+ +

Best wishes,
Aidan.

diff --git a/app/views/devise/registrations/edit.html.erb b/app/views/devise/registrations/edit.html.erb index 378de89..3d35d10 100644 --- a/app/views/devise/registrations/edit.html.erb +++ b/app/views/devise/registrations/edit.html.erb @@ -1,12 +1,20 @@ -<% content_for :title do %>Edit <%= resource_name.to_s.humanize %><% end %> +<% content_for :title do %>Edit your registration<% end %> <% content_for :form_content do %> +

Welcome back, <%= resource.first_name %>. Your email address is <%= resource.confirmed? ? "confirmed":"not yet confirmed, please check your email soon" %>.

+ +

Are you looking to get emails with new dispatches? You still need to register and confirm your email by following instructions here.

+ +

On this page below you can modify your registration.

+ +
+ <%= form_for(resource, as: resource_name, url: registration_path(resource_name), html: { method: :put }) do |f| %> <%= render "devise/shared/error_messages", resource: resource %>
<%= f.label :first_name %> - <%= f.text_field :first_name, autofocus: true %> + <%= f.text_field :first_name %>
@@ -45,15 +53,16 @@ <%= f.submit "Update" %>
<% end %> - + <%= button_to "Log out", destroy_user_session_path, method: :delete %> <% if current_user&.admin? %> - +

Keys to the kingdom

+

As an author and administrator of mind reader you cannot delete your account here. You need to remove administrative privileges first, then you may modify your account.

+

Privilege destruction can only be done from the rails console.

<% else %>

Cancel my account

- -
Unhappy? <%= button_to "Cancel my account", registration_path(resource_name), data: { confirm: "Are you sure?", turbo_confirm: "Are you sure?" }, method: :delete %>
- - <%= link_to "Back", :back %> +

If you wish, you may delete your registration with this website. Please be aware, by doing this you will lose access to any content you have purchased or been granted. You will not be unsubscribed from dispatches at the same email address as this is a separate system.

+

Please see this page to learn how to unsubscribe from emails.

+

<%= button_to "Cancel my account", registration_path(resource_name), data: { confirm: "Are you sure?", turbo_confirm: "Are you sure?" }, method: :delete %>

<% end %> <% end %> diff --git a/app/views/devise/shared/_links.html.erb b/app/views/devise/shared/_links.html.erb index 7a75304..1e70ae7 100644 --- a/app/views/devise/shared/_links.html.erb +++ b/app/views/devise/shared/_links.html.erb @@ -1,25 +1,29 @@ -<%- if controller_name != 'sessions' %> - <%= link_to "Log in", new_session_path(resource_name) %>
-<% end %> +<% if current_user %> -<%- if devise_mapping.registerable? && controller_name != 'registrations' %> - <%= link_to "Sign up", new_registration_path(resource_name) %>
-<% end %> - -<%- if devise_mapping.recoverable? && controller_name != 'passwords' && controller_name != 'registrations' %> - <%= link_to "Forgot your password?", new_password_path(resource_name) %>
-<% end %> - -<%- if devise_mapping.confirmable? && controller_name != 'confirmations' %> - <%= link_to "Didn't receive confirmation instructions?", new_confirmation_path(resource_name) %>
-<% end %> - -<%- if devise_mapping.lockable? && resource_class.unlock_strategy_enabled?(:email) && controller_name != 'unlocks' %> - <%= link_to "Didn't receive unlock instructions?", new_unlock_path(resource_name) %>
-<% end %> - -<%- if devise_mapping.omniauthable? %> - <%- resource_class.omniauth_providers.each do |provider| %> - <%= button_to "Sign in with #{OmniAuth::Utils.camelize(provider)}", omniauth_authorize_path(resource_name, provider), data: { turbo: false } %>
+<% else %> + <%- if controller_name != 'sessions' %> + <%= link_to "Log in", new_session_path(resource_name), class: "button" %>
+ <% end %> + + <%- if devise_mapping.registerable? && controller_name != 'registrations' %> + <%= link_to "Sign up", new_registration_path(resource_name), class: "button" %>
+ <% end %> + + <%- if devise_mapping.recoverable? && controller_name != 'passwords' && controller_name != 'registrations' %> + <%= link_to "Forgot your password?", new_password_path(resource_name), class: "button" %>
+ <% end %> + + <%- if devise_mapping.confirmable? && controller_name != 'confirmations' %> + <%= link_to "Didn't receive confirmation instructions?", new_confirmation_path(resource_name), class: "button" %>
+ <% end %> + + <%- if devise_mapping.lockable? && resource_class.unlock_strategy_enabled?(:email) && controller_name != 'unlocks' %> + <%= link_to "Didn't receive unlock instructions?", new_unlock_path(resource_name), class: "button" %>
+ <% end %> + + <%- if devise_mapping.omniauthable? %> + <%- resource_class.omniauth_providers.each do |provider| %> + <%= button_to "Sign in with #{OmniAuth::Utils.camelize(provider)}", omniauth_authorize_path(resource_name, provider), data: { turbo: false } %>
+ <% end %> <% end %> -<% end %> +<% end %> \ No newline at end of file diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index ed63592..bc10708 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -26,6 +26,9 @@ <% end %> + <% if !Rails.env.production? %> +
NOT PROD NOT PROD NOT PROD NOT PROD NOT PROD NOT PROD NOT PROD NOT PROD NOT PROD NOT PROD NOT PROD NOT PROD NOT PROD NOT PROD NOT PROD NOT PROD NOT PROD NOT PROD NOT PROD NOT PROD NOT PROD NOT PROD NOT PROD NOT PROD NOT PROD NOT PROD NOT PROD NOT PROD NOT PROD NOT PROD NOT PROD NOT PROD NOT PROD NOT PROD NOT PROD NOT PROD NOT PROD NOT PROD NOT PROD NOT PROD NOT PROD NOT PROD NOT PROD NOT PROD NOT PROD NOT PROD NOT PROD NOT PROD
+ <% end %> <% if notice or alert %>

Notice:

@@ -37,7 +40,8 @@ <%= yield %>
-

© <%= Time.current.year %> <%= link_to "Aidan Cornelius-Bell", "https://aidan.cornelius-bell.com" %>, CC-NC-SA. <% if current_user&.first_name? %>Welcome back, <%= link_to current_user.first_name, edit_user_registration_path %>. <% if current_user&.admin? %>You hold the keys to the kingdom.<% end %><% end %>

+ +

© <%= Time.current.year %> <%= link_to "Aidan Cornelius-Bell", "https://aidan.cornelius-bell.com" %>, CC-NC-SA.

This site is managed from the sovereign Yarta of the Kaurna Miyurna, with respect and gratitude for the custodianship of Elders past and present of the many Countries it may appear upon.

For legal purposes: any views expressed directly on this website are my own and not reflective of those of any employers, colleagues or affiliates. Links provided remain the views and intellectual property of their respective owners.

diff --git a/app/controllers/.DS_Store b/config/.DS_Store similarity index 97% copy from app/controllers/.DS_Store copy to config/.DS_Store index 315c1665a4684e485a1757f3c7fc54257a4f7f4d..9aae28b1ff9de6b5e450ad3483100cce6d670a38 100644 GIT binary patch delta 71 zcmZoMXfc@JFUrWkzyQPo3=BmK`3!jsxeTccc@qz+OM@hMKpciLhD>BhhLVjN!`LS_ LaBpVk_{$Ff^+6B) delta 77 zcmZoMXfc@JFTljWz`)4BAiz+ZoRpuR!#Gi2V&Vaj$p#`UO3Vz23=Cph^yg ZWQKf(JRq6MP{fe8aakDqW_FIh`~b#26C?lt diff --git a/config/environments/development.rb b/config/environments/development.rb index 02e1624..3f95c9f 100644 --- a/config/environments/development.rb +++ b/config/environments/development.rb @@ -42,6 +42,9 @@ Rails.application.configure do config.action_mailer.perform_caching = false config.action_mailer.default_url_options = { host: "localhost", port: 3000 } + + config.action_mailer.delivery_method = :letter_opener + config.action_mailer.perform_deliveries = true # Print deprecation notices to the Rails logger. config.active_support.deprecation = :log diff --git a/config/environments/production.rb b/config/environments/production.rb index 56bbb57..a2d4a91 100644 --- a/config/environments/production.rb +++ b/config/environments/production.rb @@ -84,6 +84,7 @@ Rails.application.configure do port: ENV['SMTP_PORT'], user_name: ENV['SMTP_USERNAME'], password: ENV['SMTP_PASSWORD'], + host: 'acb.boo', authentication: 'plain', enable_starttls: true } diff --git a/config/initializers/devise.rb b/config/initializers/devise.rb index a7adb89..0e96b38 100644 --- a/config/initializers/devise.rb +++ b/config/initializers/devise.rb @@ -143,7 +143,7 @@ Devise.setup do |config| # without confirming their account. # Default is 0.days, meaning the user cannot access the website without # confirming their account. - # config.allow_unconfirmed_access_for = 2.days + config.allow_unconfirmed_access_for = 2.days # A period that the user is allowed to confirm their account before their # token becomes invalid. For example, if set to 3.days, the user can confirm diff --git a/db/migrate/20240923002439_add_confirmable_to_devise.rb b/db/migrate/20240923002439_add_confirmable_to_devise.rb new file mode 100644 index 0000000..575ab60 --- /dev/null +++ b/db/migrate/20240923002439_add_confirmable_to_devise.rb @@ -0,0 +1,16 @@ +class AddConfirmableToDevise < ActiveRecord::Migration[7.2] + def up + add_column :users, :confirmation_token, :string + add_column :users, :confirmed_at, :datetime + add_column :users, :confirmation_sent_at, :datetime + add_column :users, :unconfirmed_email, :string + add_index :users, :confirmation_token, unique: true + + # Update existing users to confirmed + User.update_all(confirmed_at: DateTime.now) + end + + def down + remove_columns :users, :confirmation_token, :confirmed_at, :confirmation_sent_at, :unconfirmed_email + end +end diff --git a/db/schema.rb b/db/schema.rb index 4bd6274..4bb6322 100644 --- 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.2].define(version: 2024_09_14_223207) do +ActiveRecord::Schema[7.2].define(version: 2024_09_23_002439) do create_table "api_keys", charset: "utf8mb4", collation: "utf8mb4_0900_ai_ci", force: :cascade do |t| t.string "key" t.datetime "created_at", null: false @@ -54,6 +54,11 @@ ActiveRecord::Schema[7.2].define(version: 2024_09_14_223207) do t.boolean "admin", default: false t.datetime "created_at", null: false t.datetime "updated_at", null: false + t.string "confirmation_token" + t.datetime "confirmed_at" + t.datetime "confirmation_sent_at" + t.string "unconfirmed_email" + t.index ["confirmation_token"], name: "index_users_on_confirmation_token", unique: true t.index ["email"], name: "index_users_on_email", unique: true t.index ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true end -- 2.39.5