2019-07-18 12:55:14 +01:00
|
|
|
use super::schema::*;
|
|
|
|
use diesel::{r2d2::ConnectionManager, PgConnection};
|
2018-12-09 15:55:36 +00:00
|
|
|
|
2019-07-18 12:55:14 +01:00
|
|
|
// type alias to use in multiple places
|
|
|
|
pub type Pool = r2d2::Pool<ConnectionManager<PgConnection>>;
|
2018-12-09 15:55:36 +00:00
|
|
|
|
|
|
|
#[derive(Debug, Serialize, Deserialize, Queryable, Insertable)]
|
|
|
|
#[table_name = "users"]
|
|
|
|
pub struct User {
|
|
|
|
pub email: String,
|
2019-07-18 12:55:14 +01:00
|
|
|
pub hash: String,
|
|
|
|
pub created_at: chrono::NaiveDateTime,
|
2018-12-09 15:55:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
impl User {
|
2019-07-18 12:55:14 +01:00
|
|
|
pub fn from_details<S: Into<String>, T: Into<String>>(email: S, pwd: T) -> Self {
|
2018-12-09 15:55:36 +00:00
|
|
|
User {
|
2019-07-18 12:55:14 +01:00
|
|
|
email: email.into(),
|
|
|
|
hash: pwd.into(),
|
|
|
|
created_at: chrono::Local::now().naive_local(),
|
2018-12-09 15:55:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Debug, Serialize, Deserialize, Queryable, Insertable)]
|
|
|
|
#[table_name = "invitations"]
|
|
|
|
pub struct Invitation {
|
2019-07-18 12:55:14 +01:00
|
|
|
pub id: uuid::Uuid,
|
2018-12-09 15:55:36 +00:00
|
|
|
pub email: String,
|
2019-07-18 12:55:14 +01:00
|
|
|
pub expires_at: chrono::NaiveDateTime,
|
|
|
|
}
|
|
|
|
|
|
|
|
// any type that implements Into<String> can be used to create Invitation
|
|
|
|
impl<T> From<T> for Invitation where
|
|
|
|
T: Into<String> {
|
|
|
|
fn from(email: T) -> Self {
|
|
|
|
Invitation {
|
|
|
|
id: uuid::Uuid::new_v4(),
|
|
|
|
email: email.into(),
|
|
|
|
expires_at: chrono::Local::now().naive_local() + chrono::Duration::hours(24),
|
|
|
|
}
|
|
|
|
}
|
2018-12-09 15:55:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Debug, Serialize, Deserialize)]
|
|
|
|
pub struct SlimUser {
|
|
|
|
pub email: String,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl From<User> for SlimUser {
|
|
|
|
fn from(user: User) -> Self {
|
2019-03-09 18:03:09 -08:00
|
|
|
SlimUser { email: user.email }
|
2018-12-09 15:55:36 +00:00
|
|
|
}
|
|
|
|
}
|