blob: 11d3a728dfd475f7068d6ab61d3d79daf3f860ce (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
|
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(
sqlx::query!("select username from users where id = $1", user_id)
.fetch_one(&state.db)
.await?
.username,
)
} else {
username = None
}
return Ok(HttpResponse::Ok().body(render!(templates::home_html, username).unwrap()));
}
|