2026-02-28 18:57:51 +00:00
|
|
|
defmodule BerrypodWeb.ContactController do
|
|
|
|
|
use BerrypodWeb, :controller
|
|
|
|
|
|
|
|
|
|
alias Berrypod.ContactNotifier
|
|
|
|
|
|
2026-03-08 08:58:43 +00:00
|
|
|
plug BerrypodWeb.Plugs.RateLimit, [type: :api] when action == :create
|
|
|
|
|
|
2026-02-28 18:57:51 +00:00
|
|
|
@doc """
|
|
|
|
|
Handles contact form submission (no-JS fallback).
|
|
|
|
|
"""
|
|
|
|
|
def create(conn, params) do
|
|
|
|
|
case ContactNotifier.deliver_contact_message(params) do
|
|
|
|
|
{:ok, _} ->
|
|
|
|
|
conn
|
|
|
|
|
|> put_flash(:info, "Message sent! We'll get back to you soon.")
|
|
|
|
|
|> redirect(to: ~p"/contact")
|
|
|
|
|
|
|
|
|
|
{:error, :invalid_params} ->
|
|
|
|
|
conn
|
|
|
|
|
|> put_flash(:error, "Please fill in all required fields.")
|
|
|
|
|
|> redirect(to: ~p"/contact")
|
|
|
|
|
|
|
|
|
|
{:error, _} ->
|
|
|
|
|
conn
|
|
|
|
|
|> put_flash(:error, "Sorry, something went wrong. Please try again.")
|
|
|
|
|
|> redirect(to: ~p"/contact")
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|