Add cookie based auth, file serving and uploading

This commit is contained in:
2024-11-03 01:25:28 +01:00
parent c83c0e7ec4
commit 5c69317660
19 changed files with 418 additions and 45 deletions

39
src/tasks/create_user.rs Normal file
View File

@@ -0,0 +1,39 @@
use loco_rs::prelude::*;
use crate::models::users::{self};
pub struct CreateUserData;
#[async_trait]
impl Task for CreateUserData {
fn task(&self) -> TaskInfo {
TaskInfo {
name: "create_user".to_string(),
detail: "Task for creating a new user".to_string(),
}
}
async fn run(&self, app_context: &AppContext, vars: &task::Vars) -> Result<()> {
let username = vars.cli_arg("username")?;
let email = vars.cli_arg("email")?;
let password = vars.cli_arg("password")?;
let user = users::Model::create_with_password(
&app_context.db,
&users::RegisterParams {
name: username.to_string(),
email: email.to_string(),
password: password.to_string(),
},
)
.await?;
tracing::info!(
user_id = user.id,
user_email = &user.email,
"User created successfully",
);
Ok(())
}
}