fix: CI
This commit is contained in:
parent
32825ba9e1
commit
93e66f1236
1 changed files with 29 additions and 17 deletions
46
src/main.rs
46
src/main.rs
|
|
@ -73,24 +73,36 @@ async fn main() -> anyhow::Result<()> {
|
||||||
.await?
|
.await?
|
||||||
.unwrap_or(0);
|
.unwrap_or(0);
|
||||||
if user_count == 0 {
|
if user_count == 0 {
|
||||||
println!("\nNo users found. Create the first admin account.");
|
let (username, password) = match (
|
||||||
print!("Username: ");
|
std::env::var("MERCURY_ADMIN_USER").ok().filter(|s| !s.is_empty()),
|
||||||
io::stdout().flush()?;
|
std::env::var("MERCURY_ADMIN_PASSWORD").ok().filter(|s| !s.is_empty()),
|
||||||
let mut username = String::new();
|
) {
|
||||||
io::stdin().read_line(&mut username)?;
|
(Some(u), Some(p)) => {
|
||||||
let username = username.trim().to_string();
|
tracing::info!("creating first admin user from environment variables");
|
||||||
if username.is_empty() {
|
(u, p)
|
||||||
anyhow::bail!("username cannot be empty");
|
}
|
||||||
}
|
_ => {
|
||||||
|
println!("\nNo users found. Create the first admin account.");
|
||||||
|
print!("Username: ");
|
||||||
|
io::stdout().flush()?;
|
||||||
|
let mut username = String::new();
|
||||||
|
io::stdin().read_line(&mut username)?;
|
||||||
|
let username = username.trim().to_string();
|
||||||
|
if username.is_empty() {
|
||||||
|
anyhow::bail!("username cannot be empty");
|
||||||
|
}
|
||||||
|
|
||||||
print!("Password: ");
|
print!("Password: ");
|
||||||
io::stdout().flush()?;
|
io::stdout().flush()?;
|
||||||
let mut password = String::new();
|
let mut password = String::new();
|
||||||
io::stdin().read_line(&mut password)?;
|
io::stdin().read_line(&mut password)?;
|
||||||
let password = password.trim().to_string();
|
let password = password.trim().to_string();
|
||||||
if password.is_empty() {
|
if password.is_empty() {
|
||||||
anyhow::bail!("password cannot be empty");
|
anyhow::bail!("password cannot be empty");
|
||||||
}
|
}
|
||||||
|
(username, password)
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
let hash = bcrypt::hash(&password, bcrypt::DEFAULT_COST)?;
|
let hash = bcrypt::hash(&password, bcrypt::DEFAULT_COST)?;
|
||||||
sqlx::query(
|
sqlx::query(
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue