Adding (dummy) FromRequest impl for User

Need a way to access the db without a guard..
This commit is contained in:
Alex Wright 2020-03-01 23:06:01 +01:00
parent 6548aa0b7e
commit 9a6bd240ad
1 changed files with 27 additions and 4 deletions

View File

@ -31,6 +31,9 @@ use ldap3::{ LdapConn, Scope, SearchEntry };
use rocket::request::{
FlashMessage,
Form,
FromRequest,
Outcome,
Request,
};
use rocket::response::{
Flash,
@ -220,12 +223,32 @@ fn oidc_config() -> Json<OidcConfig> {
Json(config)
}
impl<'a, 'r> FromRequest<'a, 'r> for User {
type Error = ();
fn from_request(_request: &'a Request<'r>) -> Outcome<User, Self::Error> {
Outcome::Success(User {
id: 1,
username: "Alex".to_string(),
is_active: true,
created_at: None,
updated_at: None,
})
}
}
#[derive(Serialize)]
struct HelloContext {
username: String,
}
#[get("/")]
fn hello() -> Template {
let config = OidcConfig {
jwks_uri: "https://auth.xeen.dev/oauth2/keys".to_string(),
fn hello(user: User) -> Template {
println!("User: {:?}", &user);
let context = HelloContext {
username: user.username,
};
Template::render("hello", &config)
Template::render("hello", &context)
}
fn routes() -> Vec<rocket::Route> {