Skip to content

Commit

Permalink
Update controllers and stop using the focus layout
Browse files Browse the repository at this point in the history
  • Loading branch information
aerosol committed Aug 26, 2024
1 parent df99742 commit ebd8660
Show file tree
Hide file tree
Showing 9 changed files with 35 additions and 143 deletions.
64 changes: 15 additions & 49 deletions lib/plausible_web/controllers/auth_controller.ex
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ defmodule PlausibleWeb.AuthController do
render(conn, "activate.html",
has_email_code?: Plausible.Users.has_email_code?(user),
has_any_memberships?: Plausible.Site.Memberships.any?(user),
layout: {PlausibleWeb.LayoutView, "focus.html"},
form_submit_url: "/activate?flow=#{flow}"
)
end
Expand Down Expand Up @@ -98,7 +97,6 @@ defmodule PlausibleWeb.AuthController do
error: "Incorrect activation code",
has_email_code?: true,
has_any_memberships?: has_any_memberships?,
layout: {PlausibleWeb.LayoutView, "focus.html"},
form_submit_url: "/activate?flow=#{flow}"
)

Expand All @@ -107,7 +105,6 @@ defmodule PlausibleWeb.AuthController do
error: "Code is expired, please request another one",
has_email_code?: false,
has_any_memberships?: has_any_memberships?,
layout: {PlausibleWeb.LayoutView, "focus.html"},
form_submit_url: "/activate?flow=#{flow}"
)
end
Expand All @@ -123,16 +120,11 @@ defmodule PlausibleWeb.AuthController do
end

def password_reset_request_form(conn, _) do
render(conn, "password_reset_request_form.html",
layout: {PlausibleWeb.LayoutView, "focus.html"}
)
render(conn, "password_reset_request_form.html")
end

def password_reset_request(conn, %{"email" => ""}) do
render(conn, "password_reset_request_form.html",
error: "Please enter an email address",
layout: {PlausibleWeb.LayoutView, "focus.html"}
)
render(conn, "password_reset_request_form.html", error: "Please enter an email address")
end

def password_reset_request(conn, %{"email" => email} = params) do
Expand All @@ -149,20 +141,13 @@ defmodule PlausibleWeb.AuthController do
"Password reset e-mail sent. In dev environment GET /sent-emails for details."
)

render(conn, "password_reset_request_success.html",
email: email,
layout: {PlausibleWeb.LayoutView, "focus.html"}
)
render(conn, "password_reset_request_success.html", email: email)
else
render(conn, "password_reset_request_success.html",
email: email,
layout: {PlausibleWeb.LayoutView, "focus.html"}
)
render(conn, "password_reset_request_success.html", email: email)
end
else
render(conn, "password_reset_request_form.html",
error: "Please complete the captcha to reset your password",
layout: {PlausibleWeb.LayoutView, "focus.html"}
error: "Please complete the captcha to reset your password"
)
end
end
Expand All @@ -172,8 +157,7 @@ defmodule PlausibleWeb.AuthController do
{:ok, %{email: email}} ->
render(conn, "password_reset_form.html",
connect_live_socket: true,
email: email,
layout: {PlausibleWeb.LayoutView, "focus.html"}
email: email
)

{:error, :expired} ->
Expand Down Expand Up @@ -201,7 +185,7 @@ defmodule PlausibleWeb.AuthController do
end

def login_form(conn, _params) do
render(conn, "login_form.html", layout: {PlausibleWeb.LayoutView, "focus.html"})
render(conn, "login_form.html")
end

def login(conn, %{"user" => params}) do
Expand Down Expand Up @@ -243,19 +227,13 @@ defmodule PlausibleWeb.AuthController do
{:error, :wrong_password} ->
maybe_log_failed_login_attempts("wrong password for #{email}")

render(conn, "login_form.html",
error: "Wrong email or password. Please try again.",
layout: {PlausibleWeb.LayoutView, "focus.html"}
)
render(conn, "login_form.html", error: "Wrong email or password. Please try again.")

{:error, :user_not_found} ->
maybe_log_failed_login_attempts("user not found for #{email}")
Plausible.Auth.Password.dummy_calculation()

render(conn, "login_form.html",
error: "Wrong email or password. Please try again.",
layout: {PlausibleWeb.LayoutView, "focus.html"}
)
render(conn, "login_form.html", error: "Wrong email or password. Please try again.")

{:error, {:rate_limit, _}} ->
maybe_log_failed_login_attempts("too many login attempts for #{email}")
Expand Down Expand Up @@ -370,8 +348,7 @@ defmodule PlausibleWeb.AuthController do
{:ok, user} ->
if Auth.TOTP.enabled?(user) do
render(conn, "verify_2fa.html",
remember_2fa_days: TwoFactor.Session.remember_2fa_days(),
layout: {PlausibleWeb.LayoutView, "focus.html"}
remember_2fa_days: TwoFactor.Session.remember_2fa_days()
)
else
redirect_to_login(conn)
Expand All @@ -398,8 +375,7 @@ defmodule PlausibleWeb.AuthController do
conn
|> put_flash(:error, "The provided code is invalid. Please try again")
|> render("verify_2fa.html",
remember_2fa_days: TwoFactor.Session.remember_2fa_days(),
layout: {PlausibleWeb.LayoutView, "focus.html"}
remember_2fa_days: TwoFactor.Session.remember_2fa_days()
)

{:error, :not_enabled} ->
Expand All @@ -412,9 +388,7 @@ defmodule PlausibleWeb.AuthController do
case TwoFactor.Session.get_2fa_user(conn) do
{:ok, user} ->
if Auth.TOTP.enabled?(user) do
render(conn, "verify_2fa_recovery_code.html",
layout: {PlausibleWeb.LayoutView, "focus.html"}
)
render(conn, "verify_2fa_recovery_code.html")
else
redirect_to_login(conn)
end
Expand All @@ -435,9 +409,7 @@ defmodule PlausibleWeb.AuthController do

conn
|> put_flash(:error, "The provided recovery code is invalid. Please try another one")
|> render("verify_2fa_recovery_code.html",
layout: {PlausibleWeb.LayoutView, "focus.html"}
)
|> render("verify_2fa_recovery_code.html")

{:error, :not_enabled} ->
UserAuth.log_in_user(conn, user)
Expand Down Expand Up @@ -577,10 +549,7 @@ defmodule PlausibleWeb.AuthController do
def new_api_key(conn, _params) do
changeset = Auth.ApiKey.changeset(%Auth.ApiKey{})

render(conn, "new_api_key.html",
changeset: changeset,
layout: {PlausibleWeb.LayoutView, "focus.html"}
)
render(conn, "new_api_key.html", changeset: changeset)
end

def create_api_key(conn, %{"api_key" => %{"name" => name, "key" => key}}) do
Expand All @@ -591,10 +560,7 @@ defmodule PlausibleWeb.AuthController do
|> redirect(to: "/settings#api-keys")

{:error, changeset} ->
render(conn, "new_api_key.html",
changeset: changeset,
layout: {PlausibleWeb.LayoutView, "focus.html"}
)
render(conn, "new_api_key.html", changeset: changeset)
end
end

Expand Down
14 changes: 4 additions & 10 deletions lib/plausible_web/controllers/billing_controller.ex
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ defmodule PlausibleWeb.BillingController do
else
render(conn, "choose_plan.html",
skip_plausible_tracking: true,
layout: {PlausibleWeb.LayoutView, "focus.html"},
connect_live_socket: true
)
end
Expand All @@ -48,25 +47,21 @@ defmodule PlausibleWeb.BillingController do
redirect(conn, to: Routes.auth_path(conn, :user_settings))

subscribed_to_latest? ->
render(conn, "change_enterprise_plan_contact_us.html",
skip_plausible_tracking: true,
layout: {PlausibleWeb.LayoutView, "focus.html"}
)
render(conn, "change_enterprise_plan_contact_us.html", skip_plausible_tracking: true)

true ->
render(conn, "upgrade_to_enterprise_plan.html",
latest_enterprise_plan: latest_enterprise_plan,
price: price,
subscription_resumable: subscription_resumable?,
contact_link: "https://plausible.io/contact",
skip_plausible_tracking: true,
layout: {PlausibleWeb.LayoutView, "focus.html"}
skip_plausible_tracking: true
)
end
end

def upgrade_success(conn, _params) do
render(conn, "upgrade_success.html", layout: {PlausibleWeb.LayoutView, "focus.html"})
render(conn, "upgrade_success.html")
end

def change_plan_preview(conn, %{"plan_id" => new_plan_id}) do
Expand All @@ -78,8 +73,7 @@ defmodule PlausibleWeb.BillingController do
back_link: Routes.billing_path(conn, :choose_plan),
skip_plausible_tracking: true,
subscription: subscription,
preview_info: preview_info,
layout: {PlausibleWeb.LayoutView, "focus.html"}
preview_info: preview_info
)

_ ->
Expand Down
3 changes: 1 addition & 2 deletions lib/plausible_web/controllers/debug_controller.ex
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,7 @@ defmodule PlausibleWeb.DebugController do

conn
|> render("clickhouse.html",
queries: queries,
layout: {PlausibleWeb.LayoutView, "focus.html"}
queries: queries
)
end

Expand Down
6 changes: 2 additions & 4 deletions lib/plausible_web/controllers/google_analytics_controller.ex
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,7 @@ defmodule PlausibleWeb.GoogleAnalyticsController do
expires_at: expires_at,
site: conn.assigns.site,
properties: properties,
selected_property_error: error,
layout: {PlausibleWeb.LayoutView, "focus.html"}
selected_property_error: error
)

{:error, :rate_limit_exceeded} ->
Expand Down Expand Up @@ -182,8 +181,7 @@ defmodule PlausibleWeb.GoogleAnalyticsController do
selected_property: property,
selected_property_name: property_name,
start_date: start_date,
end_date: end_date,
layout: {PlausibleWeb.LayoutView, "focus.html"}
end_date: end_date
)

{:error, :rate_limit_exceeded} ->
Expand Down
2 changes: 1 addition & 1 deletion lib/plausible_web/controllers/page_controller.ex
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ defmodule PlausibleWeb.PageController do
This controller action is only ever triggered in self-hosted Plausible.
"""
def index(conn, _params) do
render(conn, "index.html", layout: {PlausibleWeb.LayoutView, "focus.html"})
render(conn, "index.html")
end
end
4 changes: 0 additions & 4 deletions lib/plausible_web/controllers/site/membership_controller.ex
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ defmodule PlausibleWeb.Site.MembershipController do
conn,
"invite_member_form.html",
site: site,
layout: {PlausibleWeb.LayoutView, "focus.html"},
team_member_limit: limit,
is_at_limit: not below_limit?,
skip_plausible_tracking: true
Expand All @@ -64,7 +63,6 @@ defmodule PlausibleWeb.Site.MembershipController do
render(conn, "invite_member_form.html",
error: "Cannot send invite because #{email} is already a member of #{site.domain}",
site: site,
layout: {PlausibleWeb.LayoutView, "focus.html"},
skip_plausible_tracking: true
)

Expand All @@ -73,7 +71,6 @@ defmodule PlausibleWeb.Site.MembershipController do
error:
"Your account is limited to #{limit} team members. You can upgrade your plan to increase this limit.",
site: site,
layout: {PlausibleWeb.LayoutView, "focus.html"},
skip_plausible_tracking: true,
is_at_limit: true,
team_member_limit: limit
Expand Down Expand Up @@ -103,7 +100,6 @@ defmodule PlausibleWeb.Site.MembershipController do
conn,
"transfer_ownership_form.html",
site: site,
layout: {PlausibleWeb.LayoutView, "focus.html"},
skip_plausible_tracking: true
)
end
Expand Down
Loading

0 comments on commit ebd8660

Please sign in to comment.