Files
openfoodnetwork/app/controllers/user_passwords_controller.rb
Jean-Baptiste Bellet 6f8ab56d2e Replace deprecated call render operations:
```
DEPRECATED: CableReady's `render operations:` call has been renamed to `render cable_ready:`. Please update your render call.
```
2023-04-05 14:19:34 +10:00

42 lines
1.2 KiB
Ruby

# frozen_string_literal: true
class UserPasswordsController < Spree::UserPasswordsController
include CablecarResponses
layout 'darkswarm'
def create
return render_unconfirmed_response if user_unconfirmed?
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) })
)
else
render status: :not_found, cable_ready: cable_car.inner_html(
"#forgot-feedback",
partial("layouts/alert", locals: { type: "alert", message: t(:email_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" })
)
end
def user_unconfirmed?
user = Spree::User.find_by(email: params.dig(:spree_user, :email))
user && !user.confirmed?
end
end