upgrades packages.
This commit is contained in:
parent
9e84a62c41
commit
02913c7b52
1398
backend-actix/Cargo.lock
generated
1398
backend-actix/Cargo.lock
generated
File diff suppressed because it is too large
Load Diff
@ -7,7 +7,7 @@ edition = "2021"
|
|||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
actix-web = "4"
|
actix-web = "4"
|
||||||
actix-cors = "0.6"
|
actix-cors = "0.7"
|
||||||
serde = { version = "1.0", features = ["derive"] }
|
serde = { version = "1.0", features = ["derive"] }
|
||||||
serde_json = "1.0"
|
serde_json = "1.0"
|
||||||
uuid = { version = "1.3.0", features = ["serde", "v4"] }
|
uuid = { version = "1.3.0", features = ["serde", "v4"] }
|
||||||
@ -16,5 +16,6 @@ diesel-derive-enum = { version = "2.0", features = ["postgres"] }
|
|||||||
diesel_migrations = "2.0"
|
diesel_migrations = "2.0"
|
||||||
argon2 = "0.5"
|
argon2 = "0.5"
|
||||||
chrono = { version = "0.4", features = ["serde"] }
|
chrono = { version = "0.4", features = ["serde"] }
|
||||||
jsonwebtoken = "8.1"
|
jsonwebtoken = "9.3"
|
||||||
validator = { version = "0.16", features = ["derive"] }
|
validator = { version = "0.20", features = ["derive"] }
|
||||||
|
rand_core = { version = "0.9" }
|
@ -1,5 +1,5 @@
|
|||||||
|
|
||||||
mod requests;
|
pub mod requests;
|
||||||
mod responses;
|
mod responses;
|
||||||
mod user_handlers;
|
mod user_handlers;
|
||||||
mod gamenight_handlers;
|
mod gamenight_handlers;
|
||||||
|
@ -12,20 +12,24 @@ pub struct Login {
|
|||||||
pub password: String
|
pub password: String
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub struct RegisterContext<'v_a> {
|
||||||
|
pub pool: &'v_a Pool<ConnectionManager<PgConnection>>
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Clone, Validate)]
|
#[derive(Serialize, Deserialize, Clone, Validate)]
|
||||||
|
#[validate(context = RegisterContext::<'v_a>)]
|
||||||
pub struct Register {
|
pub struct Register {
|
||||||
#[validate(
|
#[validate(
|
||||||
length(min = 1),
|
length(min = 1),
|
||||||
custom(function = "unique_username", arg = "&'v_a Pool<ConnectionManager<PgConnection>>")
|
custom(function = "unique_username", use_context)
|
||||||
)]
|
)]
|
||||||
pub username: String,
|
pub username: String,
|
||||||
#[validate(
|
#[validate(
|
||||||
email,
|
email,
|
||||||
custom(function = "unique_email", arg = "&'v_a Pool<ConnectionManager<PgConnection>>")
|
custom(function = "unique_email", use_context)
|
||||||
)]
|
)]
|
||||||
#[validate(email)]
|
|
||||||
pub email: String,
|
pub email: String,
|
||||||
#[validate(length(min = 10), must_match = "password_repeat")]
|
#[validate(length(min = 10), must_match(other = "password_repeat", ))]
|
||||||
pub password: String,
|
pub password: String,
|
||||||
pub password_repeat: String,
|
pub password_repeat: String,
|
||||||
}
|
}
|
||||||
|
@ -3,7 +3,7 @@ use actix_web::http::header::ContentType;
|
|||||||
use actix_web::{web, post, HttpResponse, Responder};
|
use actix_web::{web, post, HttpResponse, Responder};
|
||||||
use validator::ValidateArgs;
|
use validator::ValidateArgs;
|
||||||
use crate::DbPool;
|
use crate::DbPool;
|
||||||
use crate::request::requests::{Login, Register};
|
use crate::request::requests::{Login, Register, RegisterContext};
|
||||||
use crate::request::error::ApiError;
|
use crate::request::error::ApiError;
|
||||||
use crate::request::responses::LoginResponse;
|
use crate::request::responses::LoginResponse;
|
||||||
use crate::request::authorization::get_token;
|
use crate::request::authorization::get_token;
|
||||||
@ -55,7 +55,7 @@ pub async fn login(pool: web::Data<DbPool>, login_data: web::Json<Login>) -> Res
|
|||||||
#[post("/user")]
|
#[post("/user")]
|
||||||
pub async fn register(pool: web::Data<DbPool>, register_data: web::Json<Register>) -> Result<impl Responder, ApiError> {
|
pub async fn register(pool: web::Data<DbPool>, register_data: web::Json<Register>) -> Result<impl Responder, ApiError> {
|
||||||
web::block(move || -> Result<(), ApiError> {
|
web::block(move || -> Result<(), ApiError> {
|
||||||
register_data.validate_args((&pool, &pool))?;
|
register_data.validate_with_args(&RegisterContext{pool: &pool})?;
|
||||||
let register_request = register_data.into_inner().into();
|
let register_request = register_data.into_inner().into();
|
||||||
let mut conn = pool.get_conn();
|
let mut conn = pool.get_conn();
|
||||||
schema::register(&mut conn, register_request)?;
|
schema::register(&mut conn, register_request)?;
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
use argon2::password_hash::Salt;
|
||||||
use diesel::Connection;
|
use diesel::Connection;
|
||||||
use serde::{Serialize, Deserialize};
|
use serde::{Serialize, Deserialize};
|
||||||
use uuid::Uuid;
|
use uuid::Uuid;
|
||||||
@ -6,17 +7,14 @@ use diesel_derive_enum::DbEnum;
|
|||||||
use argon2::password_hash::SaltString;
|
use argon2::password_hash::SaltString;
|
||||||
use argon2::PasswordHash;
|
use argon2::PasswordHash;
|
||||||
use argon2::PasswordVerifier;
|
use argon2::PasswordVerifier;
|
||||||
use argon2::{
|
use argon2::Argon2;
|
||||||
password_hash::{rand_core::OsRng, PasswordHasher},
|
use argon2::password_hash::PasswordHasher;
|
||||||
Argon2,
|
|
||||||
};
|
|
||||||
use validator::ValidationError;
|
use validator::ValidationError;
|
||||||
use crate::DbPool;
|
|
||||||
use crate::util::GetConnection;
|
use crate::util::GetConnection;
|
||||||
|
|
||||||
use super::schema::{pwd, users};
|
use super::schema::{pwd, users};
|
||||||
|
|
||||||
pub use super::error::DatabaseError;
|
pub use super::error::DatabaseError;
|
||||||
|
use ::rand_core::{OsRng,TryRngCore};
|
||||||
|
use crate::request::requests::RegisterContext;
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Debug, Insertable, Queryable)]
|
#[derive(Serialize, Deserialize, Debug, Insertable, Queryable)]
|
||||||
#[diesel(table_name = pwd)]
|
#[diesel(table_name = pwd)]
|
||||||
@ -92,8 +90,8 @@ pub fn get_user(conn: &mut PgConnection, id: Uuid) -> Result<User, DatabaseError
|
|||||||
Ok(users::table.find(id).first(conn)?)
|
Ok(users::table.find(id).first(conn)?)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn unique_username(username: &String, pool: &DbPool) -> Result<(), ValidationError> {
|
pub fn unique_username(username: &String, context: &RegisterContext) -> Result<(), ValidationError> {
|
||||||
let mut conn = pool.get().expect("Couldn't get db connection from pool");
|
let mut conn = context.pool.get().expect("Couldn't get db connection from pool");
|
||||||
|
|
||||||
match users::table
|
match users::table
|
||||||
.count()
|
.count()
|
||||||
@ -106,8 +104,8 @@ pub fn unique_username(username: &String, pool: &DbPool) -> Result<(), Validatio
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn unique_email(email: &String, pool: &DbPool) -> Result<(), ValidationError> {
|
pub fn unique_email(email: &String, context: &RegisterContext) -> Result<(), ValidationError> {
|
||||||
let mut conn = pool.get_conn();
|
let mut conn = context.pool.get_conn();
|
||||||
|
|
||||||
match users::table
|
match users::table
|
||||||
.count()
|
.count()
|
||||||
@ -123,8 +121,9 @@ pub fn unique_email(email: &String, pool: &DbPool) -> Result<(), ValidationError
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn register(conn: &mut PgConnection, register: Register) -> Result<(), DatabaseError> {
|
pub fn register(conn: &mut PgConnection, register: Register) -> Result<(), DatabaseError> {
|
||||||
let salt = SaltString::generate(&mut OsRng);
|
let mut bytes = [0u8; Salt::RECOMMENDED_LENGTH];
|
||||||
|
OsRng.try_fill_bytes(&mut bytes).unwrap();
|
||||||
|
let salt = SaltString::encode_b64(&bytes).unwrap();
|
||||||
let argon2 = Argon2::default();
|
let argon2 = Argon2::default();
|
||||||
|
|
||||||
let password_hash = argon2
|
let password_hash = argon2
|
||||||
|
Loading…
x
Reference in New Issue
Block a user