forked from Txio-labs/txio
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuser.rs
More file actions
69 lines (62 loc) · 1.8 KB
/
Copy pathuser.rs
File metadata and controls
69 lines (62 loc) · 1.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
use chrono::{DateTime, Utc};
use mongodb::bson::oid::ObjectId;
use serde::{Deserialize, Serialize};
use crate::model::network::Network;
#[derive(Debug, Serialize, Deserialize, Clone)]
pub struct User {
#[serde(rename = "_id", skip_serializing_if = "Option::is_none")]
pub id: Option<ObjectId>,
pub email: String,
pub password_hash: String,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub google_sub: Option<String>,
pub tier: PlanTier,
#[serde(default)]
pub network: Network,
pub created_at: DateTime<Utc>,
#[serde(default)]
pub notification_preferences: NotificationPreferences,
}
#[derive(Debug, Serialize, Deserialize, Clone)]
pub struct NotificationPreferences {
pub email_digests: bool,
pub email_security_alerts: bool,
pub in_app_activity_alerts: bool,
pub in_app_product_updates: bool,
}
impl Default for NotificationPreferences {
fn default() -> Self {
Self {
email_digests: true,
email_security_alerts: true,
in_app_activity_alerts: true,
in_app_product_updates: false,
}
}
}
#[derive(Debug, Serialize, Deserialize, Clone)]
pub enum PlanTier {
Free,
Pro,
Team,
}
impl User {
pub fn new(email: String, password_hash: String) -> Self {
Self {
id: None,
email,
password_hash,
google_sub: None,
tier: PlanTier::Free,
network: Network::default(),
created_at: Utc::now(),
notification_preferences: NotificationPreferences::default(),
}
}
pub fn new_oauth(email: String, password_hash: String, google_sub: String) -> Self {
Self {
google_sub: Some(google_sub),
..Self::new(email, password_hash)
}
}
}