Move users to api

This commit is contained in:
Ethan Girouard 2025-02-06 11:03:47 -05:00
parent 362b8161e3
commit afd8f014b2
Signed by: eta357
GPG Key ID: 7BCDC36DFD11C146
7 changed files with 9 additions and 9 deletions

View File

@ -12,7 +12,7 @@ cfg_if! {
}
use crate::models::backend::User;
use crate::users::UserCredentials;
use crate::api::users::UserCredentials;
/// Create a new user and log them in
/// Takes in a NewUser struct, with the password in plaintext
@ -24,7 +24,7 @@ pub async fn signup(new_user: User) -> Result<(), ServerFnError> {
return Err(ServerFnError::<NoCustomError>::ServerError("Signup is disabled".to_string()));
}
use crate::users::create_user;
use crate::api::users::create_user;
// Ensure the user has no id, and is not a self-proclaimed admin
let new_user = User {
@ -63,7 +63,7 @@ pub async fn signup(new_user: User) -> Result<(), ServerFnError> {
/// Returns a Result with a boolean indicating if the login was successful
#[server(endpoint = "login")]
pub async fn login(credentials: UserCredentials) -> Result<Option<User>, ServerFnError> {
use crate::users::validate_user;
use crate::api::users::validate_user;
let mut auth_session = extract::<AuthSession<AuthBackend>>().await
.map_err(|e| ServerFnError::<NoCustomError>::ServerError(format!("Error getting auth session: {}", e)))?;

View File

@ -7,3 +7,4 @@ pub mod album;
pub mod search;
pub mod upload;
pub mod auth;
pub mod users;

View File

@ -1,5 +1,5 @@
use axum_login::{AuthnBackend, AuthUser, UserId};
use crate::users::UserCredentials;
use crate::api::users::UserCredentials;
use leptos::server_fn::error::ServerFnErrorErr;
use crate::models::backend::User;
@ -37,12 +37,12 @@ impl AuthnBackend for AuthBackend {
type Error = ServerFnErrorErr;
async fn authenticate(&self, creds: Self::Credentials) -> Result<Option<Self::User>, Self::Error> {
crate::users::validate_user(creds).await
crate::api::users::validate_user(creds).await
.map_err(|e| ServerFnErrorErr::ServerError(format!("Error validating user: {}", e)))
}
async fn get_user(&self, user_id: &UserId<Self>) -> Result<Option<Self::User>, Self::Error> {
crate::users::find_user_by_id(*user_id).await
crate::api::users::find_user_by_id(*user_id).await
.map_err(|e| ServerFnErrorErr::ServerError(format!("Error getting user: {}", e)))
}
}

View File

@ -35,7 +35,6 @@ pub mod app;
pub mod models;
pub mod pages;
pub mod components;
pub mod users;
pub mod error_template;
pub mod api;
pub mod util;

View File

@ -4,7 +4,7 @@ use leptos::leptos_dom::*;
use leptos::prelude::*;
use leptos_icons::*;
use leptos::task::spawn_local;
use crate::users::UserCredentials;
use crate::api::users::UserCredentials;
use crate::components::loading::Loading;
#[component]

View File

@ -12,7 +12,7 @@ use crate::components::error::*;
use crate::api::profile::*;
use crate::models::backend::User;
use crate::users::get_user_by_id;
use crate::api::users::get_user_by_id;
use crate::util::state::GlobalState;
/// Duration in seconds backwards from now to aggregate history data for