Added http errors for user apis
This commit is contained in:
12
src/users.rs
12
src/users.rs
@@ -156,16 +156,16 @@ pub async fn login(
|
||||
State(pool): State<PgPool>,
|
||||
Query(mut info): Query<OpenId>,
|
||||
session: Session,
|
||||
) -> Result<&'static str, AppError> {
|
||||
) -> Result<(), AppError> {
|
||||
if !info.is_valid().await? {
|
||||
return Ok("nok");
|
||||
return Err(AppError::OpenIdError("Some query parameters are erronous or lacking.".into()));
|
||||
}
|
||||
let steamid = info
|
||||
.identity
|
||||
.replace("https://steamcommunity.com/openid/id/", "");
|
||||
let user = User::from_steamid(&pool, steamid).await?;
|
||||
session.insert("uuid", user.id).await?;
|
||||
Ok("ok")
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub async fn logout(session: Session) -> Result<(), AppError> {
|
||||
@@ -177,11 +177,11 @@ pub async fn logout(session: Session) -> Result<(), AppError> {
|
||||
pub async fn me(
|
||||
State(pool): State<PgPool>,
|
||||
session: Session,
|
||||
) -> Result<Json<Option<User>>, AppError> {
|
||||
) -> Result<Json<User>, AppError> {
|
||||
if let Some(uuid) = session.get("uuid").await? {
|
||||
let user = User::fetch_id(&pool, uuid).await?;
|
||||
Ok(Json(Some(user)))
|
||||
Ok(Json(user))
|
||||
} else {
|
||||
Ok(Json(None))
|
||||
Err(AppError::Unauthorised)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user