mirror of
https://github.com/SrIzan10/hc-harbor.git
synced 2026-05-01 10:45:21 +00:00
Speed up sign-in mail sending
This commit is contained in:
@@ -36,16 +36,13 @@ class SessionsController < ApplicationController
|
||||
def email
|
||||
email = params[:email].downcase
|
||||
|
||||
# Use a transaction to ensure both user and email are created atomically
|
||||
email_address = ActiveRecord::Base.transaction do
|
||||
EmailAddress.find_by(email: email) || begin
|
||||
user = User.create!
|
||||
user.email_addresses.create!(email: email)
|
||||
end
|
||||
if Rails.env.production?
|
||||
HandleEmailSigninJob.perform_later(email)
|
||||
else
|
||||
HandleEmailSigninJob.perform_now(email)
|
||||
end
|
||||
|
||||
LoopsMailer.sign_in_email(email_address).deliver_later
|
||||
redirect_to root_path(sign_in_email: true)
|
||||
redirect_to root_path(sign_in_email: true), notice: "Check your email for a sign-in link!"
|
||||
end
|
||||
|
||||
def token
|
||||
|
||||
14
app/jobs/handle_email_signin_job.rb
Normal file
14
app/jobs/handle_email_signin_job.rb
Normal file
@@ -0,0 +1,14 @@
|
||||
class HandleEmailSigninJob < ApplicationJob
|
||||
queue_as :default
|
||||
|
||||
def perform(email)
|
||||
email_address = ActiveRecord::Base.transaction do
|
||||
EmailAddress.find_by(email: email) || begin
|
||||
user = User.create!
|
||||
user.email_addresses.create!(email: email)
|
||||
end
|
||||
end
|
||||
|
||||
LoopsMailer.sign_in_email(email_address).deliver_now
|
||||
end
|
||||
end
|
||||
@@ -1,14 +1,17 @@
|
||||
class LoopsMailer < ApplicationMailer
|
||||
# Override the default mailer settings to use Loops.so SMTP
|
||||
self.delivery_method = :smtp
|
||||
self.smtp_settings = {
|
||||
address: "smtp.loops.so",
|
||||
port: 587,
|
||||
user_name: "loops",
|
||||
password: ENV["LOOPS_API_KEY"],
|
||||
authentication: "plain",
|
||||
enable_starttls: true
|
||||
}
|
||||
if Rails.env.development? && ENV["LOOPS_API_KEY"].nil?
|
||||
self.delivery_method = :letter_opener
|
||||
else
|
||||
self.delivery_method = :smtp
|
||||
self.smtp_settings = {
|
||||
address: "smtp.loops.so",
|
||||
port: 587,
|
||||
user_name: "loops",
|
||||
password: ENV["LOOPS_API_KEY"],
|
||||
authentication: "plain",
|
||||
enable_starttls: true
|
||||
}
|
||||
end
|
||||
|
||||
def sign_in_email(email_address)
|
||||
@email = email_address.email
|
||||
|
||||
Reference in New Issue
Block a user