Cleaning unused imports
This commit is contained in:
parent
8b58f97aa2
commit
118ee088b4
5 changed files with 13 additions and 29 deletions
|
@ -40,6 +40,7 @@ pub fn token_factory(user: &str) -> JwtResult<String> {
|
|||
Ok(token)
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
pub fn validate_token(token: &str) -> JwtResult<Claims> {
|
||||
let token_data = decode::<Claims>(
|
||||
token,
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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<RegisterData>, state: Data<AppState>) -> Result<impl Responder> {
|
||||
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<LoginData>, state: Data<AppState>) -> Result<impl Responder> {
|
||||
let q = "SELECT password FROM users WHERE username = ?";
|
||||
|
@ -170,7 +166,7 @@ pub async fn login(data: Json<LoginData>, state: Data<AppState>) -> Result<impl
|
|||
});
|
||||
|
||||
match Argon2::default().verify_password(data.password.as_bytes(), &pwhash) {
|
||||
Ok(some) => {
|
||||
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<LoginData>, state: Data<AppState>) -> Result<impl
|
|||
username: data.username.clone(),
|
||||
token: token,
|
||||
}));
|
||||
// Sign jwt with user claims
|
||||
}
|
||||
Err(e) => {
|
||||
Err(_) => {
|
||||
info!("User \"{}\" failed to log in", data.username);
|
||||
return Ok(HttpResponse::BadRequest().json("Error"));
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue