setup: show flash

This commit is contained in:
Philippe Loctaux 2023-03-07 19:00:14 +01:00
parent c670201b86
commit cf9fb61f80
2 changed files with 18 additions and 8 deletions

View file

@ -15,7 +15,6 @@ async fn setup_completed(_setup: CompletedSetup) -> Redirect {
#[get("/", rank = 2)] #[get("/", rank = 2)]
async fn setup(flash: Option<FlashMessage<'_>>) -> Template { async fn setup(flash: Option<FlashMessage<'_>>) -> Template {
// TODO: show flash on html page
flash flash
.map(|flash| Page::with_flash(Page::Setup, flash)) .map(|flash| Page::with_flash(Page::Setup, flash))
.unwrap_or_else(|| Page::Setup.into()) .unwrap_or_else(|| Page::Setup.into())
@ -37,13 +36,16 @@ async fn create_first_account(
let form = form.into_inner(); let form = form.into_inner();
// Parse url // Parse url
return Ok(Either::Right(Flash::new( let url = match Url::parse(form.url) {
Redirect::to(uri!(self::setup)), Ok(url) => url,
FlashKind::Danger, Err(e) => {
"Failed to parse url".to_string(), return Ok(Either::Right(Flash::new(
))); Redirect::to(uri!(self::setup)),
FlashKind::Danger,
let url = Url::parse(form.url).unwrap(); e.to_string(),
)));
}
};
// Generate UserID // Generate UserID
let user_id = task::spawn_blocking(UserID::default).await?; let user_id = task::spawn_blocking(UserID::default).await?;

View file

@ -10,6 +10,14 @@
<img src="http://localhost:8000/logo" height="96" alt=""> <img src="http://localhost:8000/logo" height="96" alt="">
</a> </a>
</div> </div>
{% if flash %}
<div class="alert alert-{{flash.0}}" role="alert">
<h4 class="alert-title">Could not finish setup</h4>
<div class="text-muted">{{ flash.1 }}</div>
</div>
{% endif %}
<form action="/setup" method="post"> <form action="/setup" method="post">
<div class="card card-md"> <div class="card card-md">
<div class="card-body text-center py-4 p-sm-5"> <div class="card-body text-center py-4 p-sm-5">