This commit is contained in:
@@ -4,8 +4,6 @@ use serde::{Deserialize, Serialize};
|
||||
use sycamore::prelude::*;
|
||||
use web_sys::Event;
|
||||
|
||||
use crate::models::generic::GenericResponse;
|
||||
|
||||
cfg_if::cfg_if! {
|
||||
if #[cfg(client)] {
|
||||
use crate::{
|
||||
@@ -14,7 +12,10 @@ cfg_if::cfg_if! {
|
||||
state_enums::{LoginState, OpenState},
|
||||
templates::{get_api_path},
|
||||
global_state::{self, AppStateRx},
|
||||
models::auth::WebAuthInfo,
|
||||
models::{
|
||||
auth::WebAuthInfo,
|
||||
generic::GenericResponse
|
||||
},
|
||||
};
|
||||
use reqwest::StatusCode;
|
||||
}
|
||||
|
||||
@@ -1,20 +1,20 @@
|
||||
use std::sync::Arc;
|
||||
|
||||
use perseus::prelude::*;
|
||||
use sycamore::prelude::*;
|
||||
use web_sys::Event;
|
||||
|
||||
use crate::{
|
||||
capsules::{
|
||||
forgot_password_form::{ForgotPasswordFormProps, FORGOT_PASSWORD_FORM},
|
||||
login_form::{LoginFormProps, LOGIN_FORM},
|
||||
},
|
||||
endpoints::LOGIN,
|
||||
global_state::AppStateRx,
|
||||
models::auth::LoginInfo,
|
||||
state_enums::{GameState, LoginState, OpenState},
|
||||
state_enums::{GameState, LoginState},
|
||||
};
|
||||
|
||||
cfg_if::cfg_if! {
|
||||
if #[cfg(client)] {
|
||||
use crate::{
|
||||
state_enums::OpenState,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Prop)]
|
||||
pub struct HeaderProps<'a> {
|
||||
pub game: GameState,
|
||||
|
||||
@@ -4,13 +4,12 @@ use crate::{
|
||||
login_form::{LoginFormProps, LOGIN_FORM},
|
||||
register_form::{RegisterFormProps, REGISTER_FORM},
|
||||
},
|
||||
components::header::{Header, HeaderProps},
|
||||
components::header::Header,
|
||||
global_state::AppStateRx,
|
||||
state_enums::{GameState, LoginState, OpenState},
|
||||
state_enums::{GameState, OpenState},
|
||||
};
|
||||
use perseus::prelude::*;
|
||||
use sycamore::prelude::*;
|
||||
use web_sys::Event;
|
||||
|
||||
#[derive(Prop)]
|
||||
pub struct LayoutProps<'a, G: Html> {
|
||||
|
||||
@@ -4,16 +4,10 @@ use perseus::{prelude::*, state::GlobalStateCreator};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::{
|
||||
models::auth::{Claims, WebAuthInfo},
|
||||
models::auth::WebAuthInfo,
|
||||
state_enums::{LoginState, OpenState},
|
||||
};
|
||||
|
||||
cfg_if::cfg_if! {
|
||||
if #[cfg(engine)] {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, ReactiveState, Clone)]
|
||||
#[rx(alias = "AppStateRx")]
|
||||
pub struct AppState {
|
||||
@@ -33,6 +27,7 @@ pub struct AuthData {
|
||||
}
|
||||
|
||||
impl AuthDataRx {
|
||||
#[cfg(client)]
|
||||
pub fn handle_log_in(&self, auth_info: WebAuthInfo) {
|
||||
// Save new token to persistent storage
|
||||
if auth_info.remember_me {
|
||||
@@ -56,7 +51,7 @@ impl AuthDataRx {
|
||||
self.auth_info.set(Some(auth_info));
|
||||
self.state.set(LoginState::Authenticated);
|
||||
}
|
||||
|
||||
#[cfg(client)]
|
||||
pub fn handle_log_out(&self) {
|
||||
// Delete persistent storage
|
||||
// TODO -> handle error if local storage is not readable in browser
|
||||
|
||||
@@ -6,11 +6,13 @@ pub struct GenericResponse {
|
||||
}
|
||||
|
||||
impl GenericResponse {
|
||||
#[cfg(engine)]
|
||||
pub fn ok() -> Self {
|
||||
GenericResponse {
|
||||
status: String::new(),
|
||||
}
|
||||
}
|
||||
#[cfg(engine)]
|
||||
pub fn err(msg: &str) -> Self {
|
||||
GenericResponse {
|
||||
status: msg.to_string(),
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
use crate::{models::auth::ForgotPasswordRequest, server::server_state::ServerState};
|
||||
use axum::{
|
||||
extract::{Json, State},
|
||||
http::{HeaderMap, StatusCode},
|
||||
http::StatusCode,
|
||||
};
|
||||
use sea_orm::DatabaseConnection;
|
||||
|
||||
pub async fn post_forgot_password(
|
||||
State(state): State<ServerState>,
|
||||
|
||||
@@ -1,28 +1,18 @@
|
||||
use crate::entity::prelude::*;
|
||||
use crate::models::auth::{Claims, LoginInfo, LoginResponse};
|
||||
use crate::{
|
||||
entity::user::{self, Entity},
|
||||
models::auth::RegisterRequest,
|
||||
entity::{
|
||||
prelude::*,
|
||||
user::{self},
|
||||
},
|
||||
models::auth::{Claims, LoginInfo, LoginResponse},
|
||||
server::server_state::ServerState,
|
||||
};
|
||||
use argon2::password_hash::rand_core::OsRng;
|
||||
use argon2::password_hash::SaltString;
|
||||
use argon2::Argon2;
|
||||
use argon2::PasswordHash;
|
||||
use argon2::PasswordHasher;
|
||||
use argon2::PasswordVerifier;
|
||||
use argon2::{Argon2, PasswordHash, PasswordVerifier};
|
||||
use axum::{
|
||||
extract::{Json, State},
|
||||
http::{HeaderMap, StatusCode},
|
||||
};
|
||||
use futures::sink::Fanout;
|
||||
use sea_orm::ColumnTrait;
|
||||
use sea_orm::EntityTrait;
|
||||
use sea_orm::InsertResult;
|
||||
use sea_orm::QueryFilter;
|
||||
use sea_orm::Set;
|
||||
|
||||
use jsonwebtoken::{decode, encode, DecodingKey, EncodingKey, Header, Validation};
|
||||
use sea_orm::{ColumnTrait, EntityTrait, QueryFilter};
|
||||
|
||||
pub async fn credentials_are_correct(username: &str, password: &str, state: &ServerState) -> bool {
|
||||
// Get user
|
||||
|
||||
@@ -1,23 +1,15 @@
|
||||
use crate::entity::prelude::*;
|
||||
use crate::models::generic::GenericResponse;
|
||||
use argon2::password_hash::rand_core::OsRng;
|
||||
use argon2::password_hash::SaltString;
|
||||
use argon2::Argon2;
|
||||
use argon2::PasswordHash;
|
||||
use argon2::PasswordHasher;
|
||||
use axum::{extract::State, http::StatusCode, Json};
|
||||
use chrono::Utc;
|
||||
use sea_orm::ColumnTrait;
|
||||
use sea_orm::EntityTrait;
|
||||
use sea_orm::InsertResult;
|
||||
use sea_orm::QueryFilter;
|
||||
use sea_orm::Set;
|
||||
|
||||
use crate::{
|
||||
entity::user::{self, Entity},
|
||||
models::auth::RegisterRequest,
|
||||
entity::{prelude::*, user},
|
||||
models::{auth::RegisterRequest, generic::GenericResponse},
|
||||
server::server_state::ServerState,
|
||||
};
|
||||
use argon2::{
|
||||
password_hash::{rand_core::OsRng, SaltString},
|
||||
Argon2, PasswordHash, PasswordHasher,
|
||||
};
|
||||
use axum::{extract::State, http::StatusCode, Json};
|
||||
use chrono::Utc;
|
||||
use sea_orm::{ColumnTrait, EntityTrait, QueryFilter, Set};
|
||||
|
||||
pub async fn post_register_user(
|
||||
State(state): State<ServerState>,
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
// (Server only) Routes
|
||||
use crate::endpoints::{FORGOT_PASSWORD, LOGIN, LOGIN_TEST, REGISTER};
|
||||
use axum::routing::{post, Router};
|
||||
use futures::executor::block_on;
|
||||
use sea_orm::Database;
|
||||
|
||||
use super::{
|
||||
auth::{
|
||||
|
||||
@@ -6,15 +6,9 @@ pub mod overall_board;
|
||||
#[cfg(client)]
|
||||
use perseus::utils::get_path_prefix_client;
|
||||
|
||||
#[cfg(client)]
|
||||
pub fn get_api_path(path: &str) -> String {
|
||||
#[cfg(engine)]
|
||||
{
|
||||
path.to_string()
|
||||
}
|
||||
#[cfg(client)]
|
||||
{
|
||||
let origin = web_sys::window().unwrap().origin();
|
||||
let base_path = get_path_prefix_client();
|
||||
format!("{}{}{}", origin, base_path, path)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user