|
|
@@ -6,10 +6,11 @@ use crate::http_error::HttpError;
|
|
|
|
|
|
pub struct User {
|
|
|
id: Uuid,
|
|
|
- token: Uuid,
|
|
|
+ session_token: Uuid,
|
|
|
name: String,
|
|
|
email: String,
|
|
|
pass_hash: String,
|
|
|
+ tokens: i64,
|
|
|
created_at: DateTime<Utc>
|
|
|
}
|
|
|
|
|
|
@@ -24,24 +25,26 @@ impl User {
|
|
|
pub fn new(name: String, email: String, pass_hash: String) -> Self {
|
|
|
Self {
|
|
|
id: Uuid::now_v7(),
|
|
|
- token: Uuid::new_v4(),
|
|
|
+ session_token: Uuid::new_v4(),
|
|
|
name: name,
|
|
|
email: email.to_lowercase(),
|
|
|
pass_hash: pass_hash,
|
|
|
+ tokens: 0,
|
|
|
created_at: Utc::now()
|
|
|
}
|
|
|
}
|
|
|
|
|
|
pub async fn insert_one(&self, db: &PgPool) -> Result<(), HttpError> {
|
|
|
let result = sqlx::query(
|
|
|
- "INSERT into users(id, token, name, email, pass_hash, created_at)
|
|
|
- VALUES($1, $2, $3, $4, $5, $6)"
|
|
|
+ "INSERT into users(id, session_token, name, email, pass_hash, tokens, created_at)
|
|
|
+ VALUES($1, $2, $3, $4, $5, $6, $7)"
|
|
|
)
|
|
|
.bind(&self.id)
|
|
|
- .bind(&self.token)
|
|
|
+ .bind(&self.session_token)
|
|
|
.bind(&self.name)
|
|
|
.bind(&self.email)
|
|
|
.bind(&self.pass_hash)
|
|
|
+ .bind(&self.tokens)
|
|
|
.bind(&self.created_at)
|
|
|
.execute(db)
|
|
|
.await;
|