39 lines
1006 B
Rust
39 lines
1006 B
Rust
use seed::fetch::{Method, Request};
|
|
|
|
use crate::api::{perform, NetRes};
|
|
|
|
pub async fn sign_in(
|
|
identity: String,
|
|
password: model::Password,
|
|
) -> NetRes<model::api::SessionOutput> {
|
|
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
|
|
}
|