feat: implemented verify endpoint change
This commit is contained in:
parent
2d12303bbc
commit
bc610ef22a
|
@ -29,7 +29,7 @@ async fn register(
|
||||||
async fn verify(data: web::Data<ApiState>, body: web::Json<data::VerifyRequest>) -> impl Responder {
|
async fn verify(data: web::Data<ApiState>, body: web::Json<data::VerifyRequest>) -> impl Responder {
|
||||||
match handlers::verify(&data.pool, body.into_inner()).await {
|
match handlers::verify(&data.pool, body.into_inner()).await {
|
||||||
Ok(resp) => match resp {
|
Ok(resp) => match resp {
|
||||||
data::VerifyResponse::Success => HttpResponse::Ok().finish(),
|
data::VerifyResponse::Success(b) => HttpResponse::Ok().json(web::Json(b)),
|
||||||
data::VerifyResponse::TokenUnknown => HttpResponse::NotFound().finish(),
|
data::VerifyResponse::TokenUnknown => HttpResponse::NotFound().finish(),
|
||||||
data::VerifyResponse::Blocked => HttpResponse::Forbidden().finish(),
|
data::VerifyResponse::Blocked => HttpResponse::Forbidden().finish(),
|
||||||
},
|
},
|
||||||
|
|
|
@ -34,9 +34,14 @@ pub struct VerifyRequest {
|
||||||
pub token: String,
|
pub token: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Serialize)]
|
||||||
|
pub struct VerifySuccess {
|
||||||
|
pub token: String,
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub enum VerifyResponse {
|
pub enum VerifyResponse {
|
||||||
Success,
|
Success(VerifySuccess),
|
||||||
Blocked,
|
Blocked,
|
||||||
TokenUnknown,
|
TokenUnknown,
|
||||||
}
|
}
|
||||||
|
|
|
@ -103,7 +103,11 @@ pub async fn verify(pool: &PgPool, request: data::VerifyRequest) -> Result<data:
|
||||||
|
|
||||||
token.apply(pool).await?;
|
token.apply(pool).await?;
|
||||||
|
|
||||||
Ok(data::VerifyResponse::Success)
|
let auth_token = AuthToken::new(pool, &token.account, chrono::Duration::days(7)).await?;
|
||||||
|
|
||||||
|
Ok(data::VerifyResponse::Success(data::VerifySuccess {
|
||||||
|
token: auth_token.token
|
||||||
|
}))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn authenticate(
|
pub async fn authenticate(
|
||||||
|
|
Loading…
Reference in New Issue