Handle unconfirmed email message in UserSessionsController

This commit is contained in:
Matt-Yorkley
2022-02-15 09:43:40 +00:00
parent ddfda4011d
commit 4fbaa65534

View File

@@ -13,6 +13,7 @@ module Spree
helper 'spree/base'
prepend_before_action :handle_unconfirmed_email
before_action :set_checkout_redirect, only: :create
after_action :ensure_valid_locale_persisted, only: :create
@@ -49,6 +50,22 @@ module Spree
Spree.t(:login)
end
def handle_unconfirmed_email
render_unconfirmed_response if email_unconfirmed?
end
def email_unconfirmed?
Spree::User.where(email: params.dig(:spree_user, :email), confirmed_at: nil).exists?
end
def render_unconfirmed_response
render status: :unprocessable_entity, operations: cable_car.inner_html(
"#login-feedback",
partial("layouts/alert",
locals: { type: "alert", message: t(:email_unconfirmed), unconfirmed: true })
)
end
def ensure_valid_locale_persisted
# When creating a new user session we have to wait until after a successful
# login to be able to persist a selected locale on the current user