Do not display 'Error:' on a successful logout in the 'session' example.

This commit is contained in:
Pieter Frenssen 2019-08-10 22:44:41 +03:00 committed by Jeb Rosen
parent 2dd09f90be
commit 1383671090
3 changed files with 15 additions and 1 deletions

View File

@ -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)

View File

@ -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"));
} }

View File

@ -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">