]> gitweb.mndrdr.org Git - arelpe.git/commitdiff
Confirmable on devise
authorAidan Cornelius-Bell <[email protected]>
Mon, 23 Sep 2024 01:01:47 +0000 (10:31 +0930)
committerAidan Cornelius-Bell <[email protected]>
Mon, 23 Sep 2024 01:01:47 +0000 (10:31 +0930)
16 files changed:
Gemfile
Gemfile.lock
app/assets/stylesheets/application.css
app/models/user.rb
app/views/devise/base_template.html.erb
app/views/devise/confirmations/new.html.erb
app/views/devise/mailer/confirmation_instructions.html.erb
app/views/devise/registrations/edit.html.erb
app/views/devise/shared/_links.html.erb
app/views/layouts/application.html.erb
config/.DS_Store [copied from app/controllers/.DS_Store with 97% similarity]
config/environments/development.rb
config/environments/production.rb
config/initializers/devise.rb
db/migrate/20240923002439_add_confirmable_to_devise.rb [new file with mode: 0644]
db/schema.rb

diff --git a/Gemfile b/Gemfile
index 53921c92079e02c5d11b6492d3a7248ecf5c2de8..65bc37562750281690c99a3775b3d2c96fbe0dce 100644 (file)
--- 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
index a891a36097ba89da06945992d9a4e35ca9aca87d..23fc602e14a5c749aab511b40e7e5ad4c5d7aa5c 100644 (file)
@@ -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)
index d2da70f9132fe0537ec4c476fb70536c1f0f94d0..21093338e56af62cbbac6f807ef200aa438d02f0 100644 (file)
@@ -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,
index 2363f92cf35f141a523643a47728e6a14d8123cd..9c650ff0689b00451161b452a16be83a25c3b082 100644 (file)
@@ -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
index 318e63c6d27ea8475f3d269332701c9b3edeb183..7c29747e1eb1b40f2ad552015df676ff7eb955c8 100644 (file)
@@ -3,8 +3,9 @@
   
   <%= yield(:form_content) %>
   
-  <div class="links">
-       <%= render "devise/shared/links" %> <%= link_to "Home", root_url %>
+  <div class="devise-links links">
+       <%= render "devise/shared/links" %>
+    <%= link_to "Home", root_url, class: "button" %>
   </div>
 </div>
 
   }
   .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;
   }
 </style>
\ No newline at end of file
index b12dd0cbeb01b541fee181ba59c10e6e64cffad4..4681e7c2488237ac02c3d4ed62e5eccd984e87f4 100644 (file)
@@ -1,16 +1,19 @@
-<h2>Resend confirmation instructions</h2>
+<% 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 %>
 
-  <div class="field">
-    <%= f.label :email %><br />
-    <%= f.email_field :email, autofocus: true, autocomplete: "email", value: (resource.pending_reconfirmation? ? resource.unconfirmed_email : resource.email) %>
-  </div>
-
-  <div class="actions">
-    <%= f.submit "Resend confirmation instructions" %>
-  </div>
+  <%= form_for(resource, as: resource_name, url: confirmation_path(resource_name), html: { method: :post }) do |f| %>
+    <%= render "devise/shared/error_messages", resource: resource %>
+  
+    <div class="field">
+      <%= f.label :email %><br />
+      <%= f.email_field :email, autofocus: true, autocomplete: "email", value: (resource.pending_reconfirmation? ? resource.unconfirmed_email : resource.email) %>
+    </div>
+  
+    <div class="actions">
+      <%= f.submit "Resend confirmation instructions" %>
+    </div>
+  <% end %>
 <% end %>
 
-<%= render "devise/shared/links" %>
+<%= render template: 'devise/base_template' %>
\ No newline at end of file
index dc55f64f69e2541d12e6ffd6e3f4a413e8b828b2..f738f581c2864f09ca91dc3012d63bd0f1674553 100644 (file)
@@ -1,5 +1,11 @@
-<p>Welcome <%= @email %>!</p>
+<p>Welcome to <em>mind reader</em>.</p>
 
-<p>You can confirm your account email through the link below:</p>
+<p>You are receiving this email at <code><%= @email %></code> to confirm you really own this address. This is for spam prevention purposes.</p>
+
+<p>If you made an account on <em>mind reader</em> you can confirm your account email through the link below:</p>
 
 <p><%= link_to 'Confirm my account', confirmation_url(@resource, confirmation_token: @token) %></p>
+
+<p>If you did not make an account you can safely disregard this message and you will not receive further emails.</p>
+
+<p>Best wishes,<br>Aidan.</p>
index 378de894228be6e4c6c5b90a53ec5b51063dd6e2..3d35d10d43135af789fbacfcd707609d0eec0416 100644 (file)
@@ -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 %>
+  <p>Welcome back, <%= resource.first_name %>. Your email address is <%= resource.confirmed? ? "confirmed":"not yet confirmed, please check your email soon" %>.</p>
+  
+  <p>Are you looking to get emails with new dispatches? You still need to register and confirm your email by following <a href="/about">instructions here</a>.</p>
+  
+  <p>On this page below you can modify your registration.</p>
+
+  <hr> 
+  
   <%= form_for(resource, as: resource_name, url: registration_path(resource_name), html: { method: :put }) do |f| %>
     <%= render "devise/shared/error_messages", resource: resource %>
 
     <div class="field">
       <%= f.label :first_name %>
-      <%= f.text_field :first_name, autofocus: true %>
+      <%= f.text_field :first_name %>
     </div>
 
     <div class="field">
       <%= f.submit "Update" %>
     </div>
   <% end %>
-
+  <%= button_to "Log out", destroy_user_session_path, method: :delete %>
   <% if current_user&.admin? %>
-  
+  <h3>Keys to the kingdom</h3>
+  <p>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.</p>
+  <p>Privilege destruction can only be done from the rails console.</p>
   <% else %>
   <h3>Cancel my account</h3>
-
-  <div>Unhappy? <%= button_to "Cancel my account", registration_path(resource_name), data: { confirm: "Are you sure?", turbo_confirm: "Are you sure?" }, method: :delete %></div>
-
-  <%= link_to "Back", :back %>
+  <p>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 <em>not</em> be unsubscribed from dispatches at the same email address as this is a separate system.</p>
+  <p>Please see this page to learn how to <a href="/about">unsubscribe from emails</a>.</p>
+  <p><%= button_to "Cancel my account", registration_path(resource_name), data: { confirm: "Are you sure?", turbo_confirm: "Are you sure?" }, method: :delete %></p>
   <% end %>
 <% end %>
 
index 7a75304badb53b2b15261fddc46e4cb9823c367d..1e70ae70933d14a8c8c7e36550c00331a32c6679 100644 (file)
@@ -1,25 +1,29 @@
-<%- if controller_name != 'sessions' %>
-  <%= link_to "Log in", new_session_path(resource_name) %><br />
-<% end %>
+<% if current_user %>
 
-<%- if devise_mapping.registerable? && controller_name != 'registrations' %>
-  <%= link_to "Sign up", new_registration_path(resource_name) %><br />
-<% end %>
-
-<%- if devise_mapping.recoverable? && controller_name != 'passwords' && controller_name != 'registrations' %>
-  <%= link_to "Forgot your password?", new_password_path(resource_name) %><br />
-<% end %>
-
-<%- if devise_mapping.confirmable? && controller_name != 'confirmations' %>
-  <%= link_to "Didn't receive confirmation instructions?", new_confirmation_path(resource_name) %><br />
-<% 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) %><br />
-<% 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 } %><br />
+<% else %>
+  <%- if controller_name != 'sessions' %>
+    <%= link_to "Log in", new_session_path(resource_name), class: "button" %><br />
+  <% end %>
+  
+  <%- if devise_mapping.registerable? && controller_name != 'registrations' %>
+    <%= link_to "Sign up", new_registration_path(resource_name), class: "button" %><br />
+  <% end %>
+  
+  <%- if devise_mapping.recoverable? && controller_name != 'passwords' && controller_name != 'registrations' %>
+    <%= link_to "Forgot your password?", new_password_path(resource_name), class: "button" %><br />
+  <% end %>
+  
+  <%- if devise_mapping.confirmable? && controller_name != 'confirmations' %>
+    <%= link_to "Didn't receive confirmation instructions?", new_confirmation_path(resource_name), class: "button" %><br />
+  <% 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" %><br />
+  <% 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 } %><br />
+    <% end %>
   <% end %>
-<% end %>
+<% end %>
\ No newline at end of file
index ed635920906cb71970bfda489afa2262f5592d8f..bc10708958768656c061cf26f43b87492f22d12b 100644 (file)
@@ -26,6 +26,9 @@
     <script src="/simplemde.min.js"></script>
     <% end %>
   </head>
+  <% if !Rails.env.production? %>
+    <div class="marquee"><div class="track">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</div></div>
+  <% end %> 
   <% if notice or alert %>
     <div class="notice">
       <h3>Notice:</h3>
@@ -37,7 +40,8 @@
     <%= yield %>
 
     <footer>
-      <p>© <%= 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 %></p>
+      <p class="account"><% 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 %><% else %> You are not logged in. <%= link_to "Change that?", new_user_session_path %><% end %></span></p>
+      <p>© <%= Time.current.year %> <%= link_to "Aidan Cornelius-Bell", "https://aidan.cornelius-bell.com" %>, CC-NC-SA.</p>
       <p>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.</p>
       <p>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.</p>
     </footer>
similarity index 97%
copy from app/controllers/.DS_Store
copy to config/.DS_Store
index 315c1665a4684e485a1757f3c7fc54257a4f7f4d..9aae28b1ff9de6b5e450ad3483100cce6d670a38 100644 (file)
Binary files a/app/controllers/.DS_Store and b/config/.DS_Store differ
index 02e1624c9a17b5a5dd5ffadfd5d014c58ad5a003..3f95c9fa36c92861fe6f9f1e401ee93119fc7846 100644 (file)
@@ -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
index 56bbb57fa84be2fefaf394cf8107b6ff631ebe0c..a2d4a9180d54fe7d003bb05d0884a2e737bea7fa 100644 (file)
@@ -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
   }
index a7adb89bb85132b370ef547a2ddc67415dcc16e0..0e96b38b4e98d36a8b78b8c3cf09b12284248944 100644 (file)
@@ -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 (file)
index 0000000..575ab60
--- /dev/null
@@ -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
index 4bd62748162d7f8458b7684fa5b2d3547be94c85..4bb6322df1e7329b98a0fd094b4aa37b823d8ee9 100644 (file)
@@ -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