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::{
|
||||
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> {
|
||||
|
|
Loading…
Reference in New Issue