2026-02-24 08:40:08 +00:00
|
|
|
defmodule BerrypodWeb.OrderLookupController do
|
|
|
|
|
use BerrypodWeb, :controller
|
|
|
|
|
|
2026-02-24 23:10:15 +00:00
|
|
|
alias Berrypod.Orders
|
|
|
|
|
alias Berrypod.Orders.OrderNotifier
|
|
|
|
|
|
2026-02-24 08:40:08 +00:00
|
|
|
@salt "order_lookup"
|
|
|
|
|
@max_age 3_600
|
|
|
|
|
|
2026-02-24 23:10:15 +00:00
|
|
|
@doc """
|
|
|
|
|
Looks up orders by email and sends a verification link (no-JS fallback).
|
|
|
|
|
"""
|
|
|
|
|
def lookup(conn, %{"email" => email}) when is_binary(email) and email != "" do
|
|
|
|
|
orders = Orders.list_orders_by_email(email)
|
|
|
|
|
|
|
|
|
|
if orders == [] do
|
|
|
|
|
conn
|
|
|
|
|
|> put_flash(
|
|
|
|
|
:error,
|
|
|
|
|
"No orders found for that address. Make sure you use the same email you checked out with."
|
|
|
|
|
)
|
integrate R module and add url editor ui
Replaces hardcoded paths with R module throughout:
- Shop components: layout nav, cart, product links
- Controllers: cart, checkout, contact, seo, order lookup
- Shop pages: collection, product, search, checkout success, etc.
- Site context: nav item url resolution
Admin URL management:
- Settings page: prefix editor with validation feedback
- Page renderer: url_editor component for page URLs
- CSS for url editor styling
Test updates for cache isolation
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-04-01 00:36:17 +01:00
|
|
|
|> redirect(to: R.contact())
|
2026-02-24 23:10:15 +00:00
|
|
|
else
|
|
|
|
|
token = generate_token(email)
|
|
|
|
|
link = BerrypodWeb.Endpoint.url() <> ~p"/orders/verify/#{token}"
|
|
|
|
|
OrderNotifier.deliver_order_lookup(email, link)
|
|
|
|
|
|
|
|
|
|
conn
|
|
|
|
|
|> put_flash(
|
|
|
|
|
:info,
|
|
|
|
|
"We've sent a link to your email address. It'll expire after an hour."
|
|
|
|
|
)
|
integrate R module and add url editor ui
Replaces hardcoded paths with R module throughout:
- Shop components: layout nav, cart, product links
- Controllers: cart, checkout, contact, seo, order lookup
- Shop pages: collection, product, search, checkout success, etc.
- Site context: nav item url resolution
Admin URL management:
- Settings page: prefix editor with validation feedback
- Page renderer: url_editor component for page URLs
- CSS for url editor styling
Test updates for cache isolation
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-04-01 00:36:17 +01:00
|
|
|
|> redirect(to: R.contact())
|
2026-02-24 23:10:15 +00:00
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def lookup(conn, _params) do
|
|
|
|
|
conn
|
|
|
|
|
|> put_flash(:error, "Please enter your email address.")
|
integrate R module and add url editor ui
Replaces hardcoded paths with R module throughout:
- Shop components: layout nav, cart, product links
- Controllers: cart, checkout, contact, seo, order lookup
- Shop pages: collection, product, search, checkout success, etc.
- Site context: nav item url resolution
Admin URL management:
- Settings page: prefix editor with validation feedback
- Page renderer: url_editor component for page URLs
- CSS for url editor styling
Test updates for cache isolation
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-04-01 00:36:17 +01:00
|
|
|
|> redirect(to: R.contact())
|
2026-02-24 23:10:15 +00:00
|
|
|
end
|
|
|
|
|
|
2026-02-24 08:40:08 +00:00
|
|
|
def verify(conn, %{"token" => token}) do
|
|
|
|
|
case Phoenix.Token.verify(BerrypodWeb.Endpoint, @salt, token, max_age: @max_age) do
|
|
|
|
|
{:ok, email} ->
|
|
|
|
|
conn
|
|
|
|
|
|> put_session(:order_lookup_email, email)
|
integrate R module and add url editor ui
Replaces hardcoded paths with R module throughout:
- Shop components: layout nav, cart, product links
- Controllers: cart, checkout, contact, seo, order lookup
- Shop pages: collection, product, search, checkout success, etc.
- Site context: nav item url resolution
Admin URL management:
- Settings page: prefix editor with validation feedback
- Page renderer: url_editor component for page URLs
- CSS for url editor styling
Test updates for cache isolation
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-04-01 00:36:17 +01:00
|
|
|
|> redirect(to: R.orders())
|
2026-02-24 08:40:08 +00:00
|
|
|
|
|
|
|
|
{:error, :expired} ->
|
|
|
|
|
conn
|
|
|
|
|
|> put_flash(:error, "That link has expired. Please request a new one.")
|
integrate R module and add url editor ui
Replaces hardcoded paths with R module throughout:
- Shop components: layout nav, cart, product links
- Controllers: cart, checkout, contact, seo, order lookup
- Shop pages: collection, product, search, checkout success, etc.
- Site context: nav item url resolution
Admin URL management:
- Settings page: prefix editor with validation feedback
- Page renderer: url_editor component for page URLs
- CSS for url editor styling
Test updates for cache isolation
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-04-01 00:36:17 +01:00
|
|
|
|> redirect(to: R.contact())
|
2026-02-24 08:40:08 +00:00
|
|
|
|
|
|
|
|
{:error, _} ->
|
|
|
|
|
conn
|
|
|
|
|
|> put_flash(:error, "That link is invalid.")
|
integrate R module and add url editor ui
Replaces hardcoded paths with R module throughout:
- Shop components: layout nav, cart, product links
- Controllers: cart, checkout, contact, seo, order lookup
- Shop pages: collection, product, search, checkout success, etc.
- Site context: nav item url resolution
Admin URL management:
- Settings page: prefix editor with validation feedback
- Page renderer: url_editor component for page URLs
- CSS for url editor styling
Test updates for cache isolation
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-04-01 00:36:17 +01:00
|
|
|
|> redirect(to: R.contact())
|
2026-02-24 08:40:08 +00:00
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
@doc """
|
|
|
|
|
Generates a signed, time-limited token for the given email address.
|
|
|
|
|
"""
|
|
|
|
|
def generate_token(email) do
|
|
|
|
|
Phoenix.Token.sign(BerrypodWeb.Endpoint, @salt, email)
|
|
|
|
|
end
|
|
|
|
|
end
|