1use doido_core::Result;
4use doido_model::password::HasSecurePassword;
5use doido_model::sea_orm::DatabaseConnection;
6use serde::de::DeserializeOwned;
7use serde::Serialize;
8use std::future::Future;
9
10pub trait AuthUser: Clone + Send + Sync + 'static {
12 type Id: Clone
14 + Send
15 + Sync
16 + std::fmt::Debug
17 + Serialize
18 + DeserializeOwned
19 + Into<serde_json::Value>
20 + 'static;
21
22 fn id(&self) -> Self::Id;
23 fn email(&self) -> &str;
24 fn password_digest(&self) -> Option<&str>;
25
26 fn find_by_email(
27 db: &DatabaseConnection,
28 email: &str,
29 ) -> impl Future<Output = Result<Option<Self>>> + Send;
30
31 fn find_by_id(
32 db: &DatabaseConnection,
33 id: Self::Id,
34 ) -> impl Future<Output = Result<Option<Self>>> + Send;
35}
36
37pub fn authenticate_password<U: AuthUser + HasSecurePassword>(user: &U, password: &str) -> bool {
39 user.authenticate(password)
40}