mirror of https://github.com/rwf2/Rocket.git
Do not display 'Error:' on a successful logout in the 'session' example.
This commit is contained in:
parent
2dd09f90be
commit
1383671090
|
@ -59,6 +59,9 @@ fn login_page(flash: Option<FlashMessage<'_, '_>>) -> Template {
|
||||||
let mut context = HashMap::new();
|
let mut context = HashMap::new();
|
||||||
if let Some(ref msg) = flash {
|
if let Some(ref msg) = flash {
|
||||||
context.insert("flash", msg.msg());
|
context.insert("flash", msg.msg());
|
||||||
|
if msg.name() == "error" {
|
||||||
|
context.insert("flash_type", "Error");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Template::render("login", &context)
|
Template::render("login", &context)
|
||||||
|
|
|
@ -67,4 +67,15 @@ fn login_logout_succeeds() {
|
||||||
let response = client.post("/logout").cookie(login_cookie).dispatch();
|
let response = client.post("/logout").cookie(login_cookie).dispatch();
|
||||||
let cookie = user_id_cookie(&response).expect("logout cookie");
|
let cookie = user_id_cookie(&response).expect("logout cookie");
|
||||||
assert!(cookie.value().is_empty());
|
assert!(cookie.value().is_empty());
|
||||||
|
|
||||||
|
// The user should be redirected back to the login page.
|
||||||
|
assert_eq!(response.status(), Status::SeeOther);
|
||||||
|
assert_eq!(response.headers().get_one("Location"), Some("/login"));
|
||||||
|
|
||||||
|
// The page should show the success message, and no errors.
|
||||||
|
let mut response = client.get("/login").dispatch();
|
||||||
|
let body = response.body_string().unwrap();
|
||||||
|
assert_eq!(response.status(), Status::Ok);
|
||||||
|
assert!(body.contains("Successfully logged out."));
|
||||||
|
assert!(!body.contains("Error"));
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,7 +11,7 @@
|
||||||
<p>Please login to continue.</p>
|
<p>Please login to continue.</p>
|
||||||
|
|
||||||
{{#if flash}}
|
{{#if flash}}
|
||||||
<p>Error: {{ flash }}</p>
|
<p>{{#if flash_type}}{{flash_type}}: {{/if}}{{ flash }}</p>
|
||||||
{{/if}}
|
{{/if}}
|
||||||
|
|
||||||
<form action="/login" method="post" accept-charset="utf-8">
|
<form action="/login" method="post" accept-charset="utf-8">
|
||||||
|
|
Loading…
Reference in New Issue