cargo fmt
This commit is contained in:
parent
c33b54383d
commit
202a7e5224
@ -10,7 +10,7 @@ mod user;
|
||||
|
||||
use rocket::fs::FileServer;
|
||||
use rocket::response::Redirect;
|
||||
use rocket_db_pools::{sqlx, Database, Connection};
|
||||
use rocket_db_pools::{sqlx, Connection, Database};
|
||||
use rocket_dyn_templates::{context, Template};
|
||||
use user::AuthenticatedUser;
|
||||
|
||||
|
@ -1,9 +1,9 @@
|
||||
use crate::user::AuthenticatedUser;
|
||||
use crate::{feed_utils::fetch_feed, Db};
|
||||
use rocket::http::Status;
|
||||
use rocket::serde::uuid::Uuid;
|
||||
use rocket::serde::{json::Json, Serialize};
|
||||
use rocket_db_pools::Connection;
|
||||
use crate::user::AuthenticatedUser;
|
||||
|
||||
#[derive(Debug, Serialize)]
|
||||
#[serde(crate = "rocket::serde")]
|
||||
@ -15,7 +15,7 @@ pub struct FeedPollResponse {
|
||||
pub async fn poll_feed(
|
||||
mut db: Connection<Db>,
|
||||
feed_id: Uuid,
|
||||
user: AuthenticatedUser
|
||||
user: AuthenticatedUser,
|
||||
) -> Result<Json<FeedPollResponse>, Status> {
|
||||
let feed_id = feed_id.to_string();
|
||||
let user_id = user.user_id.to_string();
|
||||
@ -32,8 +32,7 @@ pub async fn poll_feed(
|
||||
.url;
|
||||
|
||||
// Parse the URL
|
||||
let url = url::Url::parse(&feed_url)
|
||||
.map_err(|_| Status::InternalServerError)?;
|
||||
let url = url::Url::parse(&feed_url).map_err(|_| Status::InternalServerError)?;
|
||||
|
||||
let feed_data = fetch_feed(&url).await.map_err(|_| Status::BadGateway)?;
|
||||
|
||||
|
26
src/user.rs
26
src/user.rs
@ -279,7 +279,10 @@ pub async fn setup_page(mut db: Connection<Db>) -> Result<Template, Status> {
|
||||
}
|
||||
|
||||
#[post("/setup", data = "<new_user>")]
|
||||
pub async fn setup(mut db: Connection<Db>, new_user: Json<NewUser>) -> Result<Status, Json<SetupError>> {
|
||||
pub async fn setup(
|
||||
mut db: Connection<Db>,
|
||||
new_user: Json<NewUser>,
|
||||
) -> Result<Status, Json<SetupError>> {
|
||||
// Check if any users exist
|
||||
let count = sqlx::query!("SELECT COUNT(*) as count FROM users")
|
||||
.fetch_one(&mut **db)
|
||||
@ -299,12 +302,13 @@ pub async fn setup(mut db: Connection<Db>, new_user: Json<NewUser>) -> Result<St
|
||||
}
|
||||
|
||||
// Hash the password
|
||||
let password_hash = bcrypt::hash(new_user.password.as_bytes(), bcrypt::DEFAULT_COST).map_err(|e| {
|
||||
eprintln!("Password hashing error: {}", e);
|
||||
Json(SetupError {
|
||||
error: "Failed to process password".to_string(),
|
||||
})
|
||||
})?;
|
||||
let password_hash =
|
||||
bcrypt::hash(new_user.password.as_bytes(), bcrypt::DEFAULT_COST).map_err(|e| {
|
||||
eprintln!("Password hashing error: {}", e);
|
||||
Json(SetupError {
|
||||
error: "Failed to process password".to_string(),
|
||||
})
|
||||
})?;
|
||||
|
||||
// Create admin user
|
||||
let user_id = Uuid::new_v4().to_string();
|
||||
@ -329,9 +333,11 @@ pub async fn setup(mut db: Connection<Db>, new_user: Json<NewUser>) -> Result<St
|
||||
Err(e) => {
|
||||
eprintln!("Database error: {}", e);
|
||||
match e {
|
||||
sqlx::Error::Database(db_err) if db_err.is_unique_violation() => Err(Json(SetupError {
|
||||
error: "Username already exists".to_string(),
|
||||
})),
|
||||
sqlx::Error::Database(db_err) if db_err.is_unique_violation() => {
|
||||
Err(Json(SetupError {
|
||||
error: "Username already exists".to_string(),
|
||||
}))
|
||||
}
|
||||
_ => Err(Json(SetupError {
|
||||
error: "Failed to create user".to_string(),
|
||||
})),
|
||||
|
Loading…
Reference in New Issue
Block a user