bazzar/web/src/api/admin.rs

36 lines
992 B
Rust
Raw Normal View History

2022-05-17 08:23:39 +02:00
use seed::fetch::{Header, Method, Request};
use crate::api::{perform, NetRes};
pub async fn sign_in(identity: String, password: model::Password) -> NetRes<model::Account> {
use model::api::admin::SignInInput;
let input = if identity.contains('@') {
SignInInput {
login: None,
email: Some(model::Email::new(identity)),
password,
}
} else {
SignInInput {
login: Some(model::Login::new(identity)),
email: None,
password,
}
};
perform(
Request::new("/api/v1/sign-in")
.method(Method::Post)
.json(&input)
.map_err(NetRes::Http)?,
)
.await
}
/// This request validates if session is still active
/// It should be run from time to time just to check if user should be
/// redirected to sign-in page
pub async fn check_session() -> NetRes<String> {
perform(Request::new("/api/v1/check").method(Method::Get)).await
}