Add database to server endpoints, move modals, add forget pw to db
All checks were successful
Build Crate / build (push) Successful in 1m45s
All checks were successful
Build Crate / build (push) Successful in 1m45s
This commit is contained in:
13
src/server/auth/forgot_password.rs
Normal file
13
src/server/auth/forgot_password.rs
Normal file
@@ -0,0 +1,13 @@
|
||||
use crate::{models::auth::ForgotPasswordRequest, server::server_state::ServerState};
|
||||
use axum::{
|
||||
extract::{Json, State},
|
||||
http::{HeaderMap, StatusCode},
|
||||
};
|
||||
use sea_orm::DatabaseConnection;
|
||||
|
||||
pub async fn post_forgot_password(
|
||||
State(state): State<ServerState>,
|
||||
Json(password_request): Json<ForgotPasswordRequest>,
|
||||
) -> StatusCode {
|
||||
StatusCode::OK
|
||||
}
|
||||
@@ -1,6 +1,9 @@
|
||||
use crate::models::auth::{Claims, LoginInfo, LoginResponse};
|
||||
use crate::{
|
||||
models::auth::{Claims, LoginInfo, LoginResponse},
|
||||
server::server_state::ServerState,
|
||||
};
|
||||
use axum::{
|
||||
extract::Json,
|
||||
extract::{Json, State},
|
||||
http::{HeaderMap, StatusCode},
|
||||
};
|
||||
use jsonwebtoken::{decode, encode, DecodingKey, EncodingKey, Header, Validation};
|
||||
@@ -10,6 +13,7 @@ pub fn is_valid_user(username: &str, password: &str) -> bool {
|
||||
}
|
||||
|
||||
pub async fn post_login_user(
|
||||
State(state): State<ServerState>,
|
||||
Json(login_info): Json<LoginInfo>,
|
||||
) -> Result<Json<LoginResponse>, StatusCode> {
|
||||
let user_authenticated = is_valid_user(&login_info.username, &login_info.password);
|
||||
@@ -42,7 +46,10 @@ pub async fn post_login_user(
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn post_test_login(header_map: HeaderMap) -> Result<Json<String>, StatusCode> {
|
||||
pub async fn post_test_login(
|
||||
State(state): State<ServerState>,
|
||||
header_map: HeaderMap,
|
||||
) -> Result<Json<String>, StatusCode> {
|
||||
if let Some(auth_header) = header_map.get("Authorization") {
|
||||
if let Ok(auth_header_str) = auth_header.to_str() {
|
||||
if auth_header_str.starts_with("Bearer ") {
|
||||
|
||||
@@ -1 +1,2 @@
|
||||
pub mod forgot_password;
|
||||
pub mod login;
|
||||
|
||||
@@ -1,2 +1,3 @@
|
||||
pub mod auth;
|
||||
pub mod routes;
|
||||
pub mod server_state;
|
||||
|
||||
@@ -1,11 +1,21 @@
|
||||
// (Server only) Routes
|
||||
use crate::endpoints::{LOGIN, LOGIN_TEST};
|
||||
use crate::endpoints::{FORGOT_PASSWORD, LOGIN, LOGIN_TEST};
|
||||
use axum::routing::{post, Router};
|
||||
use futures::executor::block_on;
|
||||
use sea_orm::Database;
|
||||
|
||||
use super::auth::login::{post_login_user, post_test_login};
|
||||
use super::{
|
||||
auth::{
|
||||
forgot_password::post_forgot_password,
|
||||
login::{post_login_user, post_test_login},
|
||||
},
|
||||
server_state::ServerState,
|
||||
};
|
||||
|
||||
pub fn register_routes(app: Router) -> Router {
|
||||
let app = app.route(LOGIN, post(post_login_user));
|
||||
let app = app.route(LOGIN_TEST, post(post_test_login));
|
||||
app
|
||||
pub fn get_api_router(state: ServerState) -> Router {
|
||||
Router::new()
|
||||
.route(LOGIN, post(post_login_user))
|
||||
.route(LOGIN_TEST, post(post_test_login))
|
||||
.route(FORGOT_PASSWORD, post(post_forgot_password))
|
||||
.with_state(state)
|
||||
}
|
||||
|
||||
6
src/server/server_state.rs
Normal file
6
src/server/server_state.rs
Normal file
@@ -0,0 +1,6 @@
|
||||
use sea_orm::DatabaseConnection;
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct ServerState {
|
||||
pub db_conn: DatabaseConnection,
|
||||
}
|
||||
Reference in New Issue
Block a user