|
|
@ -1,12 +1,13 @@
|
|
|
|
use std::ops::Deref;
|
|
|
|
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 rocket_dyn_templates::{context, Template};
|
|
|
|
|
|
|
|
|
|
|
|
use crate::{
|
|
|
|
use crate::{
|
|
|
|
cookies::LANG_COOKIE,
|
|
|
|
cookies::LANG_COOKIE,
|
|
|
|
i18n::DEFAULT as DEFAULT_LANG,
|
|
|
|
i18n::DEFAULT as DEFAULT_LANG,
|
|
|
|
models::{Settings, SessionUser, Database},
|
|
|
|
models::{Settings, SessionUser, Database, DatabaseError},
|
|
|
|
utils::AcceptLanguage,
|
|
|
|
utils::AcceptLanguage,
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
@ -17,11 +18,19 @@ pub async fn get_user(
|
|
|
|
settings: &State<Settings>,
|
|
|
|
settings: &State<Settings>,
|
|
|
|
database: &State<Database>,
|
|
|
|
database: &State<Database>,
|
|
|
|
accept_language: AcceptLanguage,
|
|
|
|
accept_language: AcceptLanguage,
|
|
|
|
) -> Template {
|
|
|
|
) -> Result<Template, Status> {
|
|
|
|
Template::render(
|
|
|
|
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",
|
|
|
|
"user",
|
|
|
|
context! {
|
|
|
|
context! {
|
|
|
|
profile_user: database.get_user_by_name(&user).unwrap(),
|
|
|
|
profile_user,
|
|
|
|
submissions: database.get_submissions_by_user_name(&user).unwrap(),
|
|
|
|
submissions: database.get_submissions_by_user_name(&user).unwrap(),
|
|
|
|
settings: settings.deref(),
|
|
|
|
settings: settings.deref(),
|
|
|
|
lang: cookies
|
|
|
|
lang: cookies
|
|
|
@ -31,5 +40,5 @@ pub async fn get_user(
|
|
|
|
.unwrap_or_else(|| vec![DEFAULT_LANG.to_owned()]),
|
|
|
|
.unwrap_or_else(|| vec![DEFAULT_LANG.to_owned()]),
|
|
|
|
user: SessionUser::get(cookies).await.unwrap(),
|
|
|
|
user: SessionUser::get(cookies).await.unwrap(),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
)
|
|
|
|
))
|
|
|
|
}
|
|
|
|
}
|