clean code; if logged out: save url where user tried to go to, go there once logged in, Fixes #179
This commit is contained in:
@ -3,10 +3,14 @@ use rocket::{
|
||||
fairing::AdHoc,
|
||||
form::Form,
|
||||
fs::FileServer,
|
||||
get, post,
|
||||
get,
|
||||
http::Cookie,
|
||||
post,
|
||||
request::FlashMessage,
|
||||
response::{Flash, Redirect},
|
||||
routes, Build, FromForm, Rocket, State,
|
||||
routes,
|
||||
time::{Duration, OffsetDateTime},
|
||||
Build, FromForm, Request, Rocket, State,
|
||||
};
|
||||
use rocket_dyn_templates::Template;
|
||||
use serde::Deserialize;
|
||||
@ -51,7 +55,13 @@ async fn wikiauth(db: &State<SqlitePool>, login: Form<LoginForm<'_>>) -> String
|
||||
}
|
||||
|
||||
#[catch(401)] //Unauthorized
|
||||
fn unauthorized_error() -> Redirect {
|
||||
fn unauthorized_error(req: &Request) -> Redirect {
|
||||
// Save the URL the user tried to access, to be able to go there once logged in
|
||||
let mut redirect_cookie = Cookie::new("redirect_url", format!("{}", req.uri()));
|
||||
println!("{}", req.uri());
|
||||
redirect_cookie.set_expires(OffsetDateTime::now_utc() + Duration::hours(1));
|
||||
req.cookies().add_private(redirect_cookie);
|
||||
|
||||
Redirect::to("/auth")
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user