Formatting code

This commit is contained in:
Benjamin Sherriff
2024-05-12 09:05:59 -04:00
parent c971c55aa3
commit 1de68f86ae
46 changed files with 1109 additions and 609 deletions

View File

@@ -86,7 +86,10 @@ impl InsertUser {
Ok(user)
}
pub fn update_profile(email: &str, profile_picture: Option<&str>) -> Result<QueryUser, ServiceError> {
pub fn update_profile(
email: &str,
profile_picture: Option<&str>,
) -> Result<QueryUser, ServiceError> {
let mut conn = connection()?;
let user = diesel::update(users::table)
.filter(users::email.eq(&email))
@@ -120,7 +123,7 @@ impl From<QueryUser> for ResponseUser {
#[derive(Debug, Serialize, Deserialize)]
pub struct Auth {
pub id: String,
pub user: ResponseUser
pub user: ResponseUser,
}
impl FromRequest for Auth {
@@ -131,21 +134,30 @@ impl FromRequest for Auth {
.cookie(SESSION_COOKIE_NAME)
.map(|c| c.value().to_string())
.or_else(|| {
req.headers().get(http::header::AUTHORIZATION)
.map(|h| h.to_str().unwrap().split_at(7).1.to_string())
req
.headers()
.get(http::header::AUTHORIZATION)
.map(|h| h.to_str().unwrap().split_at(7).1.to_string())
}) {
Some(token) => token,
None => return ready(Err(ActixError::from(ServiceError {
Some(token) => token,
None => {
return ready(Err(ActixError::from(ServiceError {
status: 401,
message: "Unauthorized".to_string()
message: "Unauthorized".to_string(),
})))
};
}
};
let ip_address = req.peer_addr().unwrap().ip().to_string();
match Session::verify(&session_id, &ip_address) {
Ok(v) => return ready(Ok(Auth { id: v.0.id, user: v.1.into() })),
Err(err) => return ready(Err(ActixError::from(err)))
Ok(v) => {
return ready(Ok(Auth {
id: v.0.id,
user: v.1.into(),
}))
}
Err(err) => return ready(Err(ActixError::from(err))),
}
}
}
@@ -156,7 +168,7 @@ pub fn verify_role(auth: &Auth, role: &str) -> Result<(), ServiceError> {
} else {
Err(ServiceError {
status: 403,
message: "Forbidden".to_string()
message: "Forbidden".to_string(),
})
}
}