Adding (dummy) FromRequest impl for User
Need a way to access the db without a guard..
This commit is contained in:
parent
6548aa0b7e
commit
9a6bd240ad
31
src/main.rs
31
src/main.rs
|
@ -31,6 +31,9 @@ use ldap3::{ LdapConn, Scope, SearchEntry };
|
||||||
use rocket::request::{
|
use rocket::request::{
|
||||||
FlashMessage,
|
FlashMessage,
|
||||||
Form,
|
Form,
|
||||||
|
FromRequest,
|
||||||
|
Outcome,
|
||||||
|
Request,
|
||||||
};
|
};
|
||||||
use rocket::response::{
|
use rocket::response::{
|
||||||
Flash,
|
Flash,
|
||||||
|
@ -220,12 +223,32 @@ fn oidc_config() -> Json<OidcConfig> {
|
||||||
Json(config)
|
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("/")]
|
#[get("/")]
|
||||||
fn hello() -> Template {
|
fn hello(user: User) -> Template {
|
||||||
let config = OidcConfig {
|
println!("User: {:?}", &user);
|
||||||
jwks_uri: "https://auth.xeen.dev/oauth2/keys".to_string(),
|
let context = HelloContext {
|
||||||
|
username: user.username,
|
||||||
};
|
};
|
||||||
Template::render("hello", &config)
|
Template::render("hello", &context)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn routes() -> Vec<rocket::Route> {
|
fn routes() -> Vec<rocket::Route> {
|
||||||
|
|
Loading…
Reference in New Issue