diff --git a/server/src/jwt.rs b/server/src/jwt.rs index 8111ac1..2e4bc44 100755 --- a/server/src/jwt.rs +++ b/server/src/jwt.rs @@ -40,6 +40,7 @@ pub fn token_factory(user: &str) -> JwtResult { Ok(token) } +#[allow(dead_code)] pub fn validate_token(token: &str) -> JwtResult { let token_data = decode::( token, diff --git a/server/src/main.rs b/server/src/main.rs index 5512cbb..6eeb981 100755 --- a/server/src/main.rs +++ b/server/src/main.rs @@ -1,8 +1,7 @@ -#![allow(dead_code, unused_imports)] -use actix_web::web::{Data, Query}; +// #![allow(dead_code, unused_imports)] +use actix_web::web::Data; use actix_web::{web::scope, App, HttpServer}; use log::info; -// use uuid::Uuid; mod jwt; mod routes; @@ -10,16 +9,8 @@ mod state; mod types; use routes::{get_posts, login, new_post, register, test}; -use sqlx::ConnectOptions; use state::AppState; -use sqlx::{migrate::MigrateDatabase, query, sqlite}; - -struct User { - name: String, - pass: String, -} - #[actix_web::main] async fn main() -> std::io::Result<()> { env_logger::Builder::from_env(env_logger::Env::default().default_filter_or("debug")).init(); diff --git a/server/src/routes.rs b/server/src/routes.rs index 87b9c5b..95f212e 100755 --- a/server/src/routes.rs +++ b/server/src/routes.rs @@ -1,9 +1,15 @@ +use crate::jwt::token_factory; use crate::types::{NewPost, Post}; use crate::AppState; -use actix_web::web::{to, Data, Path}; +use actix_web::web::{Data, Path}; use actix_web::{get, post, web::Json, HttpResponse, Responder, Result}; +use argon2::password_hash::rand_core::OsRng; use argon2::password_hash::SaltString; +use argon2::password_hash::*; +use argon2::Argon2; +use argon2::PasswordHasher; +use argon2::PasswordVerifier; use log::*; use serde::{Deserialize, Serialize}; use uuid::Uuid; @@ -104,14 +110,6 @@ pub struct RegisterData { captcha: String, } -use argon2::password_hash::rand_core::OsRng; -use argon2::password_hash::*; -use argon2::Algorithm; -use argon2::Argon2; -use argon2::PasswordHasher; -use argon2::PasswordVerifier; -use argon2::Version; - #[post("/register")] pub async fn register(data: Json, state: Data) -> Result { let q = "SELECT password FROM users WHERE username = ?"; @@ -152,8 +150,6 @@ struct LoginResponse { token: String, } -use crate::jwt::token_factory; - #[post("/login")] pub async fn login(data: Json, state: Data) -> Result { let q = "SELECT password FROM users WHERE username = ?"; @@ -170,7 +166,7 @@ pub async fn login(data: Json, state: Data) -> Result { + Ok(_) => { info!("User {} logged in", data.username); let token = token_factory(&data.username).unwrap(); println!("{:?}", token); @@ -178,9 +174,8 @@ pub async fn login(data: Json, state: Data) -> Result { + Err(_) => { info!("User \"{}\" failed to log in", data.username); return Ok(HttpResponse::BadRequest().json("Error")); } diff --git a/server/src/state.rs b/server/src/state.rs index 7b5ca1f..f59c98f 100644 --- a/server/src/state.rs +++ b/server/src/state.rs @@ -1,7 +1,7 @@ use crate::types::Post; +use sqlx::Pool; use sqlx::Sqlite; use sqlx::{self, sqlite}; -use sqlx::{AnyPool, Pool}; use std::collections::BTreeMap; use std::sync::Arc; use std::sync::Mutex; diff --git a/server/src/types.rs b/server/src/types.rs index a26e76c..267be22 100755 --- a/server/src/types.rs +++ b/server/src/types.rs @@ -1,7 +1,4 @@ use serde::{Deserialize, Serialize}; -use std::collections::BTreeMap; -use std::sync::Arc; -use std::sync::Mutex; use uuid::Uuid; // The post as it is received from the client