Added auth to endpoints
This commit is contained in:
@@ -79,9 +79,30 @@ impl InsertUser {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
pub struct ResponseUser {
|
||||
pub email: String,
|
||||
pub role: String,
|
||||
pub first_name: String,
|
||||
pub last_name: String,
|
||||
}
|
||||
|
||||
impl From<QueryUser> for ResponseUser {
|
||||
fn from(user: QueryUser) -> Self {
|
||||
ResponseUser {
|
||||
email: user.email,
|
||||
role: user.role,
|
||||
first_name: user.first_name,
|
||||
last_name: user.last_name,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
pub struct JwtAuth {
|
||||
pub access_token_uuid: uuid::Uuid
|
||||
pub access_token_uuid: uuid::Uuid,
|
||||
pub email: String,
|
||||
pub role: String,
|
||||
}
|
||||
|
||||
impl FromRequest for JwtAuth {
|
||||
@@ -140,8 +161,8 @@ impl FromRequest for JwtAuth {
|
||||
};
|
||||
|
||||
match QueryUser::get_by_email(&user_email) {
|
||||
Ok(_) => {
|
||||
ready(Ok(JwtAuth { access_token_uuid }))
|
||||
Ok(user) => {
|
||||
ready(Ok(JwtAuth { access_token_uuid, email: user.email, role: user.role }))
|
||||
}
|
||||
Err(err) => return ready(Err(ActixError::from(ServiceError {
|
||||
status: 500,
|
||||
|
||||
Reference in New Issue
Block a user