palpo_data/user/
password.rs1use diesel::prelude::*;
2
3use crate::core::identifiers::*;
4use crate::core::{MatrixError, UnixMillis};
5use crate::schema::*;
6use crate::{connect, DataResult};
7
8use super::DbUser;
9
10#[derive(Identifiable, Debug, Clone)]
11#[diesel(table_name = user_passwords)]
12pub struct DbPassword {
13 pub id: i64,
14 pub user_id: OwnedUserId,
15 pub hash: String,
16 pub created_at: UnixMillis,
17}
18#[derive(Insertable, Queryable, Debug, Clone)]
19#[diesel(table_name = user_passwords)]
20pub struct NewDbPassword {
21 pub user_id: OwnedUserId,
22 pub hash: String,
23 pub created_at: UnixMillis,
24}
25
26fn get_password_hash(user_id: &UserId) -> DataResult<String> {
27 user_passwords::table
28 .filter(user_passwords::user_id.eq(user_id))
29 .order_by(user_passwords::id.desc())
30 .select(user_passwords::hash)
31 .first::<String>(&mut *connect()?)
32 .map_err(Into::into)
33}