summaryrefslogblamecommitdiffstats
path: root/src/routes/home.rs
blob: a43eabcedb4d781ca786bd7f584919837f281269 (plain) (tree)
1
2
3
4
5
6
7
8
9
10









                                                                                   
                                                                       




                                                                                         
use actix_session::Session;
use actix_web::{get, web, HttpResponse};

use crate::templates;
use crate::{Pinussy, Result};

#[get("/")]
async fn get(session: Session, state: web::Data<Pinussy>) -> Result<HttpResponse> {
    let username: Option<String>;
    if let Some(user_id) = session.get::<i32>("user_id")? {
        username = Some(state.db.users().read(user_id).await?.username)
    } else {
        username = None
    }
    return Ok(HttpResponse::Ok().body(render!(templates::home_html, username).unwrap()));
}