Actix-Demo/src/models/users.rs
Rohan Sircar cb26393fcd Many updates
Split codebase into modules
Added custom all in one error type
Added password to user model
Added password hashing using bcrypt
Added model validation for username using regex
2020-05-09 12:07:08 +05:30

39 lines
931 B
Rust

use serde::{Deserialize, Serialize};
use crate::schema::users;
use crate::utils::regexs;
use chrono;
use validator::Validate;
use validator_derive::*;
use yarte::Template;
#[derive(Debug, Clone, Serialize, Queryable, Identifiable, Deserialize, PartialEq)]
pub struct User {
pub id: i32,
pub name: String,
pub password: String,
pub created_at: chrono::NaiveDateTime,
}
#[derive(Debug, Clone, Serialize, Insertable, Deserialize, Validate)]
#[table_name = "users"]
pub struct NewUser {
#[validate(regex = "regexs::USERNAME_REG", length(min = 4, max = 10))]
pub name: String,
pub password: String,
}
#[derive(Debug, Clone, Serialize, Deserialize, Queryable)]
pub struct UserDTO {
pub name: String,
pub registration_date: chrono::NaiveDateTime,
}
#[derive(Template)]
#[template(path = "hello.hbs")]
pub struct CardTemplate<'a> {
pub title: &'a str,
pub body: String,
pub num: u32,
}