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