rocket: User sign up guard forwards over failures When no user can be found, the User implementation of FromRequest was failing, which is a mistake. This meant that no other routes were tried and thus assigning policies to routes failed. This changes fixes that by forwarding instead. To be frank, this is over forwarding, and can still be improved on.
Dependencies
- [2]
E4OBIIUBtemplates: Fix navigation mocks Cleans up the directory structure for templates and fixes the navigation bugs in the applications too. Includes a context! macro which is lifted from upstream, but is currently unreleased. When rocket_dyn_templates is updates, it could be DRY'ed out. - [3]
RJ75MX6Yroutes: Move user routes to controllers module The last routes to move, the src directory now only has a main.rs file and directories. - [4]
KFVJ3KMWfrontend: Introduce navigation bar Minor changes to the front-end mostly, to allow users to register, sign in, and sign out. The sign out route is changed to a GET endpoint, as links in HTML cannot DELETE.
Change contents
- replacement in templates/landing.html.tera at line 11
<a class="btn btn-primary btn-lg ps-4 gap-3" href="/users/sign_up" role="button">Sign up</a><a class="btn btn-primary btn-lg ps-4 gap-3" href="/users/new" role="button">Sign up</a> - edit in src/controllers/users.rs at line 13
use rocket::outcome::try_outcome; - replacement in src/controllers/users.rs at line 20
async fn from_request(request: &'r Request<'_>) -> request::Outcome<Self, Self::Error> {let db = try_outcome!(request.guard::<&State<Database>>().await);// &State<Database>>().await);async fn from_request(request: &'r Request<'_>) -> request::Outcome<User, ()> {let db: &State<Database> = match request.guard().await {Outcome::Success(db) => db,_ => return Outcome::Failure((Status::Unauthorized, ())),}; - replacement in src/controllers/users.rs at line 29
None => return Outcome::Failure((Status::Unauthorized, ())),None => return Outcome::Forward(()), - replacement in src/controllers/users.rs at line 34
Err(_e) => Outcome::Failure((Status::Unauthorized, ())),Err(_e) => Outcome::Forward(()), // TODO this is a failure - edit in src/controllers/users.rs at line 39
#[get("/users/new", rank = 1)]fn new_already_user(_user: User) -> Redirect {Redirect::to("/")} - edit in src/controllers/users.rs at line 47
}#[get("/users/new", rank = 1)]fn new_already_user(_user: User) -> Redirect {Redirect::to("/")