Enabled :error_handling, :unknown, :unmatched_returns, :extra_return, :missing_return in an earlier commit and landed a 129-warning baseline. Four parallel agents each fixed a directory slice: - Core contexts (29): Radio, Release, Weather, Beacons, Cache, Backtest.Features, Terrain.Srtm, Ionosphere.GiroClient, Propagation.RunTiming, Accounts.Scope, RepoListener. Fixes were (a) prefix side-effect calls (Task.start, Phoenix.PubSub, Logger, :ets.new) with _ = ; (b) tighten/widen specs that didn't match actual returns; (c) add missing @type t declarations; (d) drop dead parse_int(nil) clause. - Propagation + weather subdirs (15): FreshnessMonitor, NotifyListener, ScoreCache, ScoreCacheReconciler, Weather.FrontalAnalysis, Weather.Grib2.Extractor, Weather.Grib2.Wgrib2, GridCache, HrrrPointEnqueuer, NexradCache. Same patterns — mostly _ = on PubSub / :ets / Repo.insert_all; widened two specs (float -> number) where integer returns were reachable. - Workers (35): BackfillEnqueue, CanadianSoundingFetch, ContactImport, ContactWeatherEnqueue, GefsFetch, IemreFetch, NarrFetch, SolarIndex, TerrainProfile, WeatherFetch. Prefixed Repo.update_all / Radio.set_enrichment_status! / Weather.upsert_* side-effect calls. Fixed one :pattern_match in CanadianSoundingFetch.most_recent_sounding_time/1 where a tautological cond guard generated unreachable code. - Web + Mix tasks + lib_ml (46 of 50): controllers, LiveViews, UserAuth, and 11 mix tasks. Same prefix strategy. 4 remaining warnings originate in LiveTable.LiveResource dep macro expansion and can't be fixed without forking the dep — added .dialyzer_ignore.exs to suppress just those specific file:line pairs. Also wired ignore_warnings in mix.exs dialyzer config. mix dialyzer --format short | grep ^lib/ | wc -l -> 0 mix test: 2163 tests, 3 pre-existing flakes, 0 regressions.
88 lines
2.6 KiB
Elixir
88 lines
2.6 KiB
Elixir
defmodule MicrowavepropWeb.UserSettingsController do
|
|
use MicrowavepropWeb, :controller
|
|
|
|
import MicrowavepropWeb.UserAuth, only: [require_sudo_mode: 2]
|
|
|
|
alias Microwaveprop.Accounts
|
|
alias Microwaveprop.BeaconMonitors
|
|
alias MicrowavepropWeb.UserAuth
|
|
|
|
plug :require_sudo_mode
|
|
plug :assign_email_and_password_changesets
|
|
plug :assign_beacon_monitors
|
|
|
|
def edit(conn, _params) do
|
|
render(conn, :edit)
|
|
end
|
|
|
|
def update(conn, %{"action" => "update_email"} = params) do
|
|
%{"user" => user_params} = params
|
|
user = conn.assigns.current_scope.user
|
|
|
|
case Accounts.change_user_email(user, user_params) do
|
|
%{valid?: true} = changeset ->
|
|
_ =
|
|
Accounts.deliver_user_update_email_instructions(
|
|
Ecto.Changeset.apply_action!(changeset, :insert),
|
|
user.email,
|
|
&url(~p"/users/settings/confirm-email/#{&1}")
|
|
)
|
|
|
|
conn
|
|
|> put_flash(
|
|
:info,
|
|
"A link to confirm your email change has been sent to the new address."
|
|
)
|
|
|> redirect(to: ~p"/users/settings")
|
|
|
|
changeset ->
|
|
render(conn, :edit, email_changeset: %{changeset | action: :insert})
|
|
end
|
|
end
|
|
|
|
def update(conn, %{"action" => "update_password"} = params) do
|
|
%{"user" => user_params} = params
|
|
user = conn.assigns.current_scope.user
|
|
|
|
case Accounts.update_user_password(user, user_params) do
|
|
{:ok, {user, _}} ->
|
|
conn
|
|
|> put_flash(:info, "Password updated successfully.")
|
|
|> put_session(:user_return_to, ~p"/users/settings")
|
|
|> UserAuth.log_in_user(user)
|
|
|
|
{:error, changeset} ->
|
|
render(conn, :edit, password_changeset: changeset)
|
|
end
|
|
end
|
|
|
|
def confirm_email(conn, %{"token" => token}) do
|
|
case Accounts.update_user_email(conn.assigns.current_scope.user, token) do
|
|
{:ok, _user} ->
|
|
conn
|
|
|> put_flash(:info, "Email changed successfully.")
|
|
|> redirect(to: ~p"/users/settings")
|
|
|
|
{:error, _} ->
|
|
conn
|
|
|> put_flash(:error, "Email change link is invalid or it has expired.")
|
|
|> redirect(to: ~p"/users/settings")
|
|
end
|
|
end
|
|
|
|
defp assign_email_and_password_changesets(conn, _opts) do
|
|
user = conn.assigns.current_scope.user
|
|
|
|
conn
|
|
|> assign(:email_changeset, Accounts.change_user_email(user))
|
|
|> assign(:password_changeset, Accounts.change_user_password(user))
|
|
end
|
|
|
|
defp assign_beacon_monitors(conn, _opts) do
|
|
user = conn.assigns.current_scope.user
|
|
|
|
conn
|
|
|> assign(:beacon_monitors, BeaconMonitors.list_monitors_for_user(user))
|
|
|> assign(:beacon_monitor_changeset, BeaconMonitors.change_monitor())
|
|
end
|
|
end
|