1use std::fmt;
5
6#[derive(Debug, Clone, PartialEq, Eq)]
9#[non_exhaustive]
10pub enum SignUpFault {
11 AuthDisabled,
15 ReservedField(String),
19 FileField(String),
23 RelationshipField(String),
27}
28
29#[derive(Debug, Clone, PartialEq, Eq)]
32#[non_exhaustive]
33pub enum ProfileFault {
34 AuthDisabled,
38 ReservedField(String),
42 FileField(String),
46 RelationshipField(String),
50}
51
52#[derive(Debug, Clone, PartialEq, Eq)]
55#[non_exhaustive]
56pub enum ResetFault {
57 AuthDisabled,
61}
62
63impl fmt::Display for ResetFault {
64 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
65 match self {
66 Self::AuthDisabled => f.write_str(
67 "a password reset needs auth: `Auth::disabled()` serves no sign-in to reset",
68 ),
69 }
70 }
71}
72
73impl fmt::Display for ProfileFault {
74 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
75 match self {
76 Self::AuthDisabled => {
77 f.write_str("a profile page needs auth: `Auth::disabled()` signs nobody in to edit")
78 }
79 Self::ReservedField(field) => write!(
80 f,
81 "the profile form declares a field named '{field}', which its POST carries \
82 itself: rename the field"
83 ),
84 Self::FileField(field) => write!(
85 f,
86 "the profile form declares a file field '{field}', which its POST does not \
87 upload: edit the file on a resource's form"
88 ),
89 Self::RelationshipField(field) => write!(
90 f,
91 "the profile form declares a relationship choice '{field}', whose options no \
92 route serves the profile page: offer static options"
93 ),
94 }
95 }
96}
97
98impl fmt::Display for SignUpFault {
99 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
100 match self {
101 Self::AuthDisabled => f.write_str(
102 "registration needs auth: `Auth::disabled()` serves no sign-in for a new \
103 account to land on",
104 ),
105 Self::ReservedField(field) => write!(
106 f,
107 "the sign-up form declares a field named '{field}', which its POST carries \
108 itself: rename the field"
109 ),
110 Self::FileField(field) => write!(
111 f,
112 "the sign-up form declares a file field '{field}', which its POST does not \
113 upload: ask for the file once the account signs in"
114 ),
115 Self::RelationshipField(field) => write!(
116 f,
117 "the sign-up form declares a relationship choice '{field}', which would list \
118 records to a visitor nobody signed in: offer static options"
119 ),
120 }
121 }
122}
123
124#[derive(Debug, Clone, PartialEq, Eq)]
127#[non_exhaustive]
128pub enum AuthMailFault {
129 Unset {
134 feature: &'static str,
136 },
137 BaseUrl(String),
141 MissingMail,
146}
147
148impl fmt::Display for AuthMailFault {
149 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
150 match self {
151 Self::Unset { feature } => write!(
152 f,
153 "`Auth::{feature}` sends mail, but the auth sets no sender: install one with \
154 `Auth::mail(AuthMail::new(..))`"
155 ),
156 Self::BaseUrl(url) => write!(
157 f,
158 "the auth mail's base URL '{url}' is not an absolute http or https URL: pass the \
159 scheme and host the app answers on, such as `https://admin.example.com`"
160 ),
161 Self::MissingMail => f.write_str(
162 "the panel's auth mails links, but the router registers no `Mailer`: add \
163 one with `.with(Mailer::new(..))` before mounting the panel",
164 ),
165 }
166 }
167}
168
169#[derive(Debug, Clone, PartialEq, Eq)]
172#[non_exhaustive]
173pub enum VerificationFault {
174 AuthDisabled,
178}
179
180impl fmt::Display for VerificationFault {
181 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
182 match self {
183 Self::AuthDisabled => f.write_str(
184 "email verification needs auth: `Auth::disabled()` signs nobody in to verify",
185 ),
186 }
187 }
188}
189
190#[derive(Debug, Clone, PartialEq, Eq)]
193#[non_exhaustive]
194pub enum TenantRegistrationFault {
195 AuthDisabled,
199 ReservedField(String),
203 FileField(String),
207 RelationshipField(String),
211}
212
213impl fmt::Display for TenantRegistrationFault {
214 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
215 match self {
216 Self::AuthDisabled => f.write_str(
217 "tenant registration needs auth: `Auth::disabled()` signs nobody in to register \
218 a tenant",
219 ),
220 Self::ReservedField(field) => write!(
221 f,
222 "the tenant registration form declares a field named '{field}', which its POST \
223 carries itself: rename the field"
224 ),
225 Self::FileField(field) => write!(
226 f,
227 "the tenant registration form declares a file field '{field}', which its POST \
228 does not upload: ask for the file on a resource's form"
229 ),
230 Self::RelationshipField(field) => write!(
231 f,
232 "the tenant registration form declares a relationship choice '{field}', whose \
233 options no route serves the registration page: offer static options"
234 ),
235 }
236 }
237}
238
239#[derive(Debug, Clone, PartialEq, Eq)]
242#[non_exhaustive]
243pub enum TenantProfileFault {
244 AuthDisabled,
248 ReservedField(String),
252 FileField(String),
256 RelationshipField(String),
260}
261
262impl fmt::Display for TenantProfileFault {
263 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
264 match self {
265 Self::AuthDisabled => f.write_str(
266 "a tenant settings page needs auth: `Auth::disabled()` signs nobody in to edit a \
267 tenant",
268 ),
269 Self::ReservedField(field) => write!(
270 f,
271 "the tenant settings form declares a field named '{field}', which its POST \
272 carries itself: rename the field"
273 ),
274 Self::FileField(field) => write!(
275 f,
276 "the tenant settings form declares a file field '{field}', which its POST does \
277 not upload: edit the file on a resource's form"
278 ),
279 Self::RelationshipField(field) => write!(
280 f,
281 "the tenant settings form declares a relationship choice '{field}', whose \
282 options no route serves the settings page: offer static options"
283 ),
284 }
285 }
286}
287
288#[derive(Debug, Clone, PartialEq, Eq)]
291#[non_exhaustive]
292pub enum TwoFactorFault {
293 AuthDisabled,
297 MissingKey,
302}
303
304impl fmt::Display for TwoFactorFault {
305 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
306 match self {
307 Self::AuthDisabled => f.write_str(
308 "two-factor sign-in needs auth: `Auth::disabled()` signs nobody in to ask a \
309 second factor of",
310 ),
311 Self::MissingKey => f.write_str(
312 "two-factor sign-in seals each authenticator secret under the router's cookie \
313 key, and the router has none: register a `topcoat::cookie::Key` with `.with(..)`",
314 ),
315 }
316 }
317}
318
319#[derive(Debug, Clone, PartialEq, Eq)]
322#[non_exhaustive]
323pub enum OidcFault {
324 AuthDisabled,
328 ExternalAuth,
332 MissingKey,
337 BaseUrl(String),
341 NoProvider,
345 ProviderKey(String),
349 DuplicateProvider(String),
353 Issuer(String),
357 ReservedParam(String, String),
362}
363
364impl fmt::Display for OidcFault {
365 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
366 match self {
367 Self::AuthDisabled => f.write_str(
368 "provider sign-in needs auth: `Auth::disabled()` signs nobody in to link an \
369 identity to",
370 ),
371 Self::ExternalAuth => f.write_str(
372 "provider sign-in cannot sit beside `Auth::external`: the app signs every user in \
373 itself, so sign in through the provider there",
374 ),
375 Self::MissingKey => f.write_str(
376 "provider sign-in seals each pending sign-in under the router's cookie key, and \
377 the router has none: register a `topcoat::cookie::Key` with `.with(..)`",
378 ),
379 Self::BaseUrl(url) => write!(
380 f,
381 "provider sign-in's base URL '{url}' is not an absolute `https` origin: pass the \
382 app's public origin, such as `https://app.example.com`"
383 ),
384 Self::NoProvider => {
385 f.write_str("provider sign-in has no provider: add one with `Oidc::provider`")
386 }
387 Self::ProviderKey(key) => write!(
388 f,
389 "provider key '{key}' cannot name a route: use lowercase ASCII letters, digits \
390 and `-`"
391 ),
392 Self::DuplicateProvider(key) => write!(
393 f,
394 "two providers have the key '{key}': give each a distinct key"
395 ),
396 Self::Issuer(key) => write!(
397 f,
398 "provider '{key}' has an issuer that is not an `https` URL, nor an `http` one on \
399 a loopback host"
400 ),
401 Self::ReservedParam(key, name) => write!(
402 f,
403 "provider '{key}' sets the authorization parameter '{name}', which the panel \
404 sets itself: drop it"
405 ),
406 }
407 }
408}