|
|
|
@ -1,12 +1,13 @@
|
|
|
|
|
use std::ops::Deref;
|
|
|
|
|
|
|
|
|
|
use rocket::{http::CookieJar, State};
|
|
|
|
|
use reqwest::StatusCode;
|
|
|
|
|
use rocket::{http::{CookieJar, Status}, State, Response};
|
|
|
|
|
use rocket_dyn_templates::{context, Template};
|
|
|
|
|
|
|
|
|
|
use crate::{
|
|
|
|
|
cookies::LANG_COOKIE,
|
|
|
|
|
i18n::DEFAULT as DEFAULT_LANG,
|
|
|
|
|
models::{Settings, SessionUser, Database},
|
|
|
|
|
models::{Settings, SessionUser, Database, DatabaseError},
|
|
|
|
|
utils::AcceptLanguage,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
@ -17,11 +18,19 @@ pub async fn get_user(
|
|
|
|
|
settings: &State<Settings>,
|
|
|
|
|
database: &State<Database>,
|
|
|
|
|
accept_language: AcceptLanguage,
|
|
|
|
|
) -> Template {
|
|
|
|
|
Template::render(
|
|
|
|
|
) -> Result<Template, Status> {
|
|
|
|
|
let profile_user = match database.get_user_by_name(&user) {
|
|
|
|
|
Ok(profile_user) => profile_user,
|
|
|
|
|
Err(DatabaseError::Rusqlite(rusqlite::Error::QueryReturnedNoRows)) => return Err(Status::NotFound),
|
|
|
|
|
Err(error) => {
|
|
|
|
|
eprintln!("{:?}", error);
|
|
|
|
|
return Err(Status::InternalServerError);
|
|
|
|
|
},
|
|
|
|
|
};
|
|
|
|
|
Ok(Template::render(
|
|
|
|
|
"user",
|
|
|
|
|
context! {
|
|
|
|
|
profile_user: database.get_user_by_name(&user).unwrap(),
|
|
|
|
|
profile_user,
|
|
|
|
|
submissions: database.get_submissions_by_user_name(&user).unwrap(),
|
|
|
|
|
settings: settings.deref(),
|
|
|
|
|
lang: cookies
|
|
|
|
@ -31,5 +40,5 @@ pub async fn get_user(
|
|
|
|
|
.unwrap_or_else(|| vec![DEFAULT_LANG.to_owned()]),
|
|
|
|
|
user: SessionUser::get(cookies).await.unwrap(),
|
|
|
|
|
},
|
|
|
|
|
)
|
|
|
|
|
))
|
|
|
|
|
}
|