Added favicons and shit like this.
This commit is contained in:
1 parent
76e1e8cb53
commit
1b94784c7f
18 files changed
+163
-22
No files matched your search
@@ -11,16 +11,27 @@ pub struct LoginPayload {
|
||||
password: String,
|
||||
}
|
||||
|
||||
fn logout_req(){
|
||||
|
||||
}
|
||||
|
||||
#[actix_web::post("/login")]
|
||||
pub async fn login(
|
||||
tmpl_env: MiniJinjaRenderer,
|
||||
web::Json(form): web::Json<LoginPayload>,
|
||||
service_factory: web::Data<ServicesFactory>,
|
||||
) -> actix_web::Result<impl Responder> {
|
||||
let conn = service_factory.get_connection()?;
|
||||
let user_service = service_factory.get_user_service(&conn)?;
|
||||
let maybeUser = user_service.get_user_for_authentication(&form.username, &form.password).unwrap();
|
||||
if maybeUser.is_none() {
|
||||
return Ok(tmpl_env.render("partials/index/failure.html", context!{})?.customize());
|
||||
}
|
||||
let user = maybeUser.unwrap();
|
||||
let authentication_service = service_factory.get_authentication_service()?;
|
||||
let cookie = authentication_service.create_login_cookie(&form.username);
|
||||
let cookie = authentication_service.create_login_cookie(&user.id);
|
||||
let ctx = context! {
|
||||
name => form.username,
|
||||
user => & user,
|
||||
};
|
||||
let ret = tmpl_env
|
||||
.render("partials/index/success.html", ctx)?
|
||||
@@ -46,12 +57,16 @@ pub async fn index(
|
||||
service_factory: web::Data<ServicesFactory>,
|
||||
tmpl_env: MiniJinjaRenderer,
|
||||
) -> actix_web::Result<impl Responder> {
|
||||
let conn = service_factory.get_connection()?;
|
||||
let authentication_service = service_factory.get_authentication_service()?;
|
||||
let user_service = service_factory.get_user_service(&conn)?;
|
||||
|
||||
let userid = authentication_service.get_login(&req);
|
||||
|
||||
let username = userid.clone().unwrap_or("".to_string());
|
||||
let ctx = context! {
|
||||
is_logged_in => userid.is_some(),
|
||||
name => username,
|
||||
// user => user_service.get_user_for_authentication(userid.unwrap(),
|
||||
};
|
||||
tmpl_env.render("index.html", ctx)
|
||||
}
|
||||
@@ -5,6 +5,7 @@ use r2d2::PooledConnection;
|
||||
use r2d2_sqlite::SqliteConnectionManager;
|
||||
|
||||
use std::path::PathBuf;
|
||||
use cookie::Key;
|
||||
|
||||
pub type DbPool = r2d2::Pool<SqliteConnectionManager>;
|
||||
|
||||
@@ -15,7 +16,7 @@ pub fn creat_db_pool(path: &PathBuf) -> DbPool {
|
||||
|
||||
#[derive(Clone)]
|
||||
struct ServicesCache {
|
||||
session_service: SessionService,
|
||||
session_service_key: Key,
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
@@ -27,8 +28,8 @@ pub struct ServicesFactory {
|
||||
impl ServicesFactory {
|
||||
pub fn new(pool: DbPool) -> ServicesFactory {
|
||||
let mut conn = pool.get().unwrap();
|
||||
let session_service = SessionService::from_conn(&mut conn).unwrap();
|
||||
let cache = ServicesCache { session_service };
|
||||
let session_service_key = SessionService::get_key(&mut conn).unwrap();
|
||||
let cache = ServicesCache { session_service_key };
|
||||
ServicesFactory { pool, cache }
|
||||
}
|
||||
|
||||
@@ -39,7 +40,7 @@ impl ServicesFactory {
|
||||
}
|
||||
|
||||
pub fn get_authentication_service(&self) -> Result<SessionService> {
|
||||
Ok(self.cache.session_service.clone())
|
||||
Ok(SessionService::from_key(self.cache.session_service_key.clone()))
|
||||
}
|
||||
|
||||
pub fn get_user_service<'a>(
|
||||
|
||||
Reference in new issue
Block a user