forked from StellarSend/backend
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuser.rs
More file actions
77 lines (70 loc) · 1.93 KB
/
Copy pathuser.rs
File metadata and controls
77 lines (70 loc) · 1.93 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
70
71
72
73
74
75
76
77
use chrono::{DateTime, Utc};
use serde::{Deserialize, Serialize};
use uuid::Uuid;
/// Row as stored in the `users` table.
#[derive(Debug, Clone, sqlx::FromRow)]
pub struct UserRow {
pub id: Uuid,
pub email: String,
pub password_hash: String,
pub full_name: String,
pub stellar_address: Option<String>,
pub is_active: bool,
pub created_at: DateTime<Utc>,
pub updated_at: DateTime<Utc>,
}
/// Public-facing user representation (no password hash).
#[derive(Debug, Clone, Serialize)]
pub struct User {
pub id: Uuid,
pub email: String,
pub full_name: String,
pub stellar_address: Option<String>,
pub is_active: bool,
pub created_at: DateTime<Utc>,
}
impl From<UserRow> for User {
fn from(row: UserRow) -> Self {
Self {
id: row.id,
email: row.email,
full_name: row.full_name,
stellar_address: row.stellar_address,
is_active: row.is_active,
created_at: row.created_at,
}
}
}
/// Request body for POST /api/auth/register.
#[derive(Debug, Deserialize)]
pub struct CreateUserRequest {
pub email: String,
pub password: String,
pub full_name: String,
/// Optional Stellar public key the user already owns.
pub stellar_address: Option<String>,
}
/// Request body for POST /api/auth/login.
#[derive(Debug, Deserialize)]
pub struct LoginRequest {
pub email: String,
pub password: String,
}
/// Response body for successful authentication.
#[derive(Debug, Serialize)]
pub struct AuthResponse {
pub token: String,
pub user: User,
}
/// Claims stored inside the JWT.
#[derive(Debug, Serialize, Deserialize, Clone)]
pub struct JwtClaims {
/// Subject (user id).
pub sub: String,
/// Email address (convenient claim so we don't need a DB round-trip often).
pub email: String,
/// Issued-at (Unix timestamp).
pub iat: i64,
/// Expiry (Unix timestamp).
pub exp: i64,
}