use renox::Environment;
use renox::prelude::*;
use serde::Serialize;
use super::seed::{PASSWORD, PEOPLE};
#[derive(Debug, Clone, Serialize)]
pub struct Account {
pub name: &'static str,
pub email: &'static str,
}
#[derive(Debug, Clone, Serialize)]
pub struct Demo {
pub password: &'static str,
pub accounts: Vec<Account>,
}
pub async fn for_view(ctx: renox::view::ViewContext) -> Result<Option<Demo>> {
if ctx.path != "/login" || ctx.state.config.env != Environment::Local {
return Ok(None);
}
let mut accounts = Vec::new();
for &(name, email, _) in PEOPLE {
if User::find_by_email(&ctx.state.db, email).await?.is_some() {
accounts.push(Account { name, email });
}
}
Ok((!accounts.is_empty()).then_some(Demo {
password: PASSWORD,
accounts,
}))
}