mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-05 22:26:07 +00:00
Handle user password with turbo stream
This commit is contained in:
@@ -1,8 +1,6 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class UserPasswordsController < Spree::UserPasswordsController
|
||||
include CablecarResponses
|
||||
|
||||
layout 'darkswarm'
|
||||
|
||||
def create
|
||||
@@ -11,27 +9,20 @@ class UserPasswordsController < Spree::UserPasswordsController
|
||||
self.resource = resource_class.send_reset_password_instructions(raw_params[resource_name])
|
||||
|
||||
if resource.errors.empty?
|
||||
render cable_ready: cable_car.inner_html(
|
||||
"#forgot-feedback",
|
||||
partial("layouts/alert", locals: { type: "success", message: t(:password_reset_sent) })
|
||||
)
|
||||
@message, @type = [t(:password_reset_sent), :success]
|
||||
render :create
|
||||
else
|
||||
render status: :not_found, cable_ready: cable_car.inner_html(
|
||||
"#forgot-feedback",
|
||||
partial("layouts/alert", locals: { type: "alert", message: t(:email_not_found) })
|
||||
)
|
||||
@message, @type = [t(:email_not_found), :alert]
|
||||
render :create, status: :not_found
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def render_unconfirmed_response
|
||||
render status: :unprocessable_entity, cable_ready: cable_car.inner_html(
|
||||
"#forgot-feedback",
|
||||
partial("layouts/alert",
|
||||
locals: { type: "alert", message: t(:email_unconfirmed),
|
||||
unconfirmed: true, tab: "forgot" })
|
||||
)
|
||||
@message, @type, @unconfirmed, @tab = [t(:email_unconfirmed), :alert, true, 'forgot']
|
||||
|
||||
render :create, status: :unprocessable_entity
|
||||
end
|
||||
|
||||
def user_unconfirmed?
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
#forgot-tab
|
||||
= form_with url: spree_user_password_path, scope: :spree_user, data: { remote: "true" } do |form|
|
||||
= form_with url: spree_user_password_path, scope: :spree_user, data: { turbo: true } do |form|
|
||||
.row
|
||||
.large-12.columns#forgot-feedback
|
||||
|
||||
.row
|
||||
.large-12.columns
|
||||
= form.label :email, t(:signup_email)
|
||||
= form.email_field :email, { tabindex: 1, inputmode: "email", "data-login-modal-target": "email", "data-action": "input->login-modal#emailOnInput" }
|
||||
= form.email_field :email, { tabindex: 1, inputmode: "email" }
|
||||
.row
|
||||
.large-12.columns
|
||||
= form.submit t(:reset_password), { class: "button primary", tabindex: 2 }
|
||||
|
||||
2
app/views/user_passwords/create.turbo_stream.haml
Normal file
2
app/views/user_passwords/create.turbo_stream.haml
Normal file
@@ -0,0 +1,2 @@
|
||||
= turbo_stream.update 'forgot-feedback' do
|
||||
= render partial: 'layouts/alert', locals: { type: @type, message: @message, tab: @tab, unconfirmed: @unconfirmed, email: params.dig(:spree_user, :email) }
|
||||
@@ -14,20 +14,20 @@ RSpec.describe UserPasswordsController do
|
||||
|
||||
describe "create" do
|
||||
it "returns 404 if user is not found" do
|
||||
spree_post :create, spree_user: { email: "xxxxxxxxxx@example.com" }
|
||||
spree_post :create, spree_user: { email: "xxxxxxxxxx@example.com" }, format: :turbo_stream
|
||||
expect(response).to have_http_status :not_found
|
||||
expect(response.body).to match 'Email address not found'
|
||||
end
|
||||
|
||||
it "returns 422 if user is registered but not confirmed" do
|
||||
spree_post :create, spree_user: { email: unconfirmed_user.email }
|
||||
spree_post :create, spree_user: { email: unconfirmed_user.email }, format: :turbo_stream
|
||||
expect(response).to have_http_status :unprocessable_entity
|
||||
expect(response.body).to match "You must confirm your email \
|
||||
address before you can reset your password."
|
||||
end
|
||||
|
||||
it "returns 200 when password reset was successful" do
|
||||
spree_post :create, spree_user: { email: user.email }
|
||||
spree_post :create, spree_user: { email: user.email }, format: :turbo_stream
|
||||
expect(response).to have_http_status :ok
|
||||
expect(response.body).to match "An email with instructions on resetting \
|
||||
your password has been sent!"
|
||||
|
||||
Reference in New Issue
Block a user