/ src / views / auth.rs
auth.rs
 1  use serde::{Deserialize, Serialize};
 2  
 3  use crate::models::_entities::users;
 4  
 5  #[derive(Debug, Deserialize, Serialize)]
 6  pub struct LoginResponse {
 7      pub token: String,
 8      pub pid: String,
 9      pub name: String,
10      pub is_verified: bool,
11  }
12  
13  impl LoginResponse {
14      #[must_use]
15      pub fn new(user: &users::Model, token: &String) -> Self {
16          Self {
17              token: token.to_string(),
18              pid: user.pid.to_string(),
19              name: user.name.clone(),
20              is_verified: user.email_verified_at.is_some(),
21          }
22      }
23  }
24  
25  #[derive(Debug, Deserialize, Serialize)]
26  pub struct CurrentResponse {
27      pub pid: String,
28      pub name: String,
29      pub email: String,
30  }
31  
32  impl CurrentResponse {
33      #[must_use]
34      pub fn new(user: &users::Model) -> Self {
35          Self {
36              pid: user.pid.to_string(),
37              name: user.name.clone(),
38              email: user.email.clone(),
39          }
40      }
41  }