Fix unused NoCustomError import
This commit is contained in:
parent
013fb6391d
commit
bc94c60240
@ -1,5 +1,5 @@
|
|||||||
use leptos::*;
|
use leptos::*;
|
||||||
use leptos::server_fn::error::NoCustomError;
|
|
||||||
use crate::models::User;
|
use crate::models::User;
|
||||||
|
|
||||||
/// Create a new user and log them in
|
/// Create a new user and log them in
|
||||||
@ -12,6 +12,7 @@ pub async fn signup(new_user: User) -> Result<(), ServerFnError> {
|
|||||||
use leptos_actix::extract;
|
use leptos_actix::extract;
|
||||||
use actix_web::{HttpMessage, HttpRequest};
|
use actix_web::{HttpMessage, HttpRequest};
|
||||||
use actix_identity::Identity;
|
use actix_identity::Identity;
|
||||||
|
use leptos::server_fn::error::NoCustomError;
|
||||||
|
|
||||||
// Ensure the user has no id
|
// Ensure the user has no id
|
||||||
let new_user = User {
|
let new_user = User {
|
||||||
@ -42,6 +43,7 @@ pub async fn login(username_or_email: String, password: String) -> Result<bool,
|
|||||||
use actix_web::{HttpMessage, HttpRequest};
|
use actix_web::{HttpMessage, HttpRequest};
|
||||||
use actix_identity::Identity;
|
use actix_identity::Identity;
|
||||||
use leptos_actix::extract;
|
use leptos_actix::extract;
|
||||||
|
use leptos::server_fn::error::NoCustomError;
|
||||||
|
|
||||||
let possible_user = validate_user(username_or_email, password).await
|
let possible_user = validate_user(username_or_email, password).await
|
||||||
.map_err(|e| ServerFnError::<NoCustomError>::ServerError(format!("Error validating user: {}", e)))?;
|
.map_err(|e| ServerFnError::<NoCustomError>::ServerError(format!("Error validating user: {}", e)))?;
|
||||||
@ -68,6 +70,7 @@ pub async fn login(username_or_email: String, password: String) -> Result<bool,
|
|||||||
pub async fn logout() -> Result<(), ServerFnError> {
|
pub async fn logout() -> Result<(), ServerFnError> {
|
||||||
use leptos_actix::extract;
|
use leptos_actix::extract;
|
||||||
use actix_identity::Identity;
|
use actix_identity::Identity;
|
||||||
|
use leptos::server_fn::error::NoCustomError;
|
||||||
|
|
||||||
match extract::<Option<Identity>>().await {
|
match extract::<Option<Identity>>().await {
|
||||||
Ok(Some(user)) => user.logout(),
|
Ok(Some(user)) => user.logout(),
|
||||||
|
@ -14,7 +14,6 @@ cfg_if::cfg_if! {
|
|||||||
}
|
}
|
||||||
|
|
||||||
use leptos::*;
|
use leptos::*;
|
||||||
use leptos::server_fn::error::NoCustomError;
|
|
||||||
use crate::models::User;
|
use crate::models::User;
|
||||||
|
|
||||||
/// Get a user from the database by username or email
|
/// Get a user from the database by username or email
|
||||||
@ -22,6 +21,7 @@ use crate::models::User;
|
|||||||
#[cfg(feature = "ssr")]
|
#[cfg(feature = "ssr")]
|
||||||
pub async fn find_user(username_or_email: String) -> Result<Option<User>, ServerFnError> {
|
pub async fn find_user(username_or_email: String) -> Result<Option<User>, ServerFnError> {
|
||||||
use crate::schema::users::dsl::*;
|
use crate::schema::users::dsl::*;
|
||||||
|
use leptos::server_fn::error::NoCustomError;
|
||||||
|
|
||||||
// Look for either a username or email that matches the input, and return an option with None if no user is found
|
// Look for either a username or email that matches the input, and return an option with None if no user is found
|
||||||
let db_con = &mut get_db_conn();
|
let db_con = &mut get_db_conn();
|
||||||
@ -37,6 +37,7 @@ pub async fn find_user(username_or_email: String) -> Result<Option<User>, Server
|
|||||||
#[cfg(feature = "ssr")]
|
#[cfg(feature = "ssr")]
|
||||||
pub async fn create_user(new_user: &User) -> Result<(), ServerFnError> {
|
pub async fn create_user(new_user: &User) -> Result<(), ServerFnError> {
|
||||||
use crate::schema::users::dsl::*;
|
use crate::schema::users::dsl::*;
|
||||||
|
use leptos::server_fn::error::NoCustomError;
|
||||||
|
|
||||||
let new_password = new_user.password.clone()
|
let new_password = new_user.password.clone()
|
||||||
.ok_or(ServerFnError::<NoCustomError>::ServerError(format!("No password provided for user {}", new_user.username)))?;
|
.ok_or(ServerFnError::<NoCustomError>::ServerError(format!("No password provided for user {}", new_user.username)))?;
|
||||||
@ -62,6 +63,8 @@ pub async fn create_user(new_user: &User) -> Result<(), ServerFnError> {
|
|||||||
/// Returns a Result with the user if the credentials are valid, None if not valid, or an error if there was a problem
|
/// Returns a Result with the user if the credentials are valid, None if not valid, or an error if there was a problem
|
||||||
#[cfg(feature = "ssr")]
|
#[cfg(feature = "ssr")]
|
||||||
pub async fn validate_user(username_or_email: String, password: String) -> Result<Option<User>, ServerFnError> {
|
pub async fn validate_user(username_or_email: String, password: String) -> Result<Option<User>, ServerFnError> {
|
||||||
|
use leptos::server_fn::error::NoCustomError;
|
||||||
|
|
||||||
let db_user = find_user(username_or_email.clone()).await
|
let db_user = find_user(username_or_email.clone()).await
|
||||||
.map_err(|e| ServerFnError::<NoCustomError>::ServerError(format!("Error getting user from database: {}", e)))?;
|
.map_err(|e| ServerFnError::<NoCustomError>::ServerError(format!("Error getting user from database: {}", e)))?;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user