Hastic standalone https://hastic.io
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

37 lines
953 B

use hastic::services::user_service;
3 years ago
3 years ago
use warp::filters::method::post;
use warp::http::HeaderValue;
3 years ago
use warp::hyper::Body;
3 years ago
use warp::{http::Response, Filter};
3 years ago
use warp::{Rejection, Reply};
3 years ago
use serde::Serialize;
3 years ago
use crate::api;
use parking_lot::RwLock;
use std::sync::Arc;
#[derive(Serialize)]
struct SigninResp {
3 years ago
token: user_service::AccessToken,
}
3 years ago
pub fn get_route(
user_service: Arc<RwLock<user_service::UserService>>,
) -> impl Filter<Extract = impl Reply, Error = Rejection> + Clone {
3 years ago
return warp::path!("api" / "auth" / "signin")
.and(post())
.and(warp::body::json())
.map(move |user: user_service::User| {
let us = user_service.write().login(&user);
match us {
Some(token) => api::API::json(&SigninResp { token }),
None => api::API::json(&SigninResp {
token: "no token".to_string(),
}),
}
3 years ago
});
3 years ago
}