diff --git a/ffplayout/src/api/routes.rs b/ffplayout/src/api/routes.rs index a0938c88..3c184fc2 100644 --- a/ffplayout/src/api/routes.rs +++ b/ffplayout/src/api/routes.rs @@ -160,26 +160,27 @@ struct ProgramItem { /// } /// ``` #[post("/auth/login/")] -pub async fn login(pool: web::Data>, credentials: web::Json) -> impl Responder { +pub async fn login( + pool: web::Data>, + credentials: web::Json, +) -> Result { let username = credentials.username.clone(); let password = credentials.password.clone(); match handles::select_login(&pool, &username).await { Ok(mut user) => { - let role = handles::select_role(&pool, &user.role_id.unwrap_or_default()) - .await - .unwrap_or(Role::Guest); + let role = handles::select_role(&pool, &user.role_id.unwrap_or_default()).await?; - let pass = user.password.clone(); - let password_clone = password.clone(); + let pass_hash = user.password.clone(); + let cred_password = password.clone(); user.password = "".into(); let verified_password = web::block(move || { - let hash = PasswordHash::new(&pass).unwrap(); - Argon2::default().verify_password(password_clone.as_bytes(), &hash) + let hash = PasswordHash::new(&pass_hash)?; + Argon2::default().verify_password(cred_password.as_bytes(), &hash) }) - .await; + .await?; if verified_password.is_ok() { let claims = Claims::new( @@ -195,31 +196,31 @@ pub async fn login(pool: web::Data>, credentials: web::Json) info!("user {} login, with role: {role}", username); - web::Json(UserObj { + Ok(web::Json(UserObj { message: "login correct!".into(), user: Some(user), }) .customize() - .with_status(StatusCode::OK) + .with_status(StatusCode::OK)) } else { error!("Wrong password for {username}!"); - web::Json(UserObj { + Ok(web::Json(UserObj { message: "Wrong password!".into(), user: None, }) .customize() - .with_status(StatusCode::FORBIDDEN) + .with_status(StatusCode::FORBIDDEN)) } } Err(e) => { error!("Login {username} failed! {e}"); - web::Json(UserObj { + Ok(web::Json(UserObj { message: format!("Login {username} failed!"), user: None, }) .customize() - .with_status(StatusCode::BAD_REQUEST) + .with_status(StatusCode::BAD_REQUEST)) } } } diff --git a/ffplayout/src/utils/channels.rs b/ffplayout/src/utils/channels.rs index 5c7f35c7..696e047f 100644 --- a/ffplayout/src/utils/channels.rs +++ b/ffplayout/src/utils/channels.rs @@ -67,15 +67,15 @@ pub async fn create_channel( channel.preview_url = preview_url(&channel.preview_url, channel.id); if global.shared_storage { - channel.hls_path = Path::new(&channel.hls_path) + channel.hls_path = Path::new(&global.public_root) .join(channel.id.to_string()) .to_string_lossy() .to_string(); - channel.playlist_path = Path::new(&channel.playlist_path) + channel.playlist_path = Path::new(&global.playlist_root) .join(channel.id.to_string()) .to_string_lossy() .to_string(); - channel.storage_path = Path::new(&channel.storage_path) + channel.storage_path = Path::new(&global.storage_root) .join(channel.id.to_string()) .to_string_lossy() .to_string(); diff --git a/frontend b/frontend index fd85411c..0b1e083c 160000 --- a/frontend +++ b/frontend @@ -1 +1 @@ -Subproject commit fd85411c773f86cd3cef02fdd8c3fd041d9af1a8 +Subproject commit 0b1e083ce5b1818589b899d2fe0cc04f4100df32