Always set 'secret_key' in session example.

This commit also removes a previously unused 'Flash' message.
This commit is contained in:
David Darrell 2018-06-24 19:29:19 +08:00 committed by Sergio Benitez
parent 648eb1a5eb
commit 76bbcb5de8
2 changed files with 4 additions and 9 deletions

View File

@ -1,7 +1,2 @@
[staging]
secret_key = "itlYmFR2vYKrOmFhupMIn/hyB6lYCCTXz4yaQX89XVg="
address = "localhost"
port = 8000
[production]
[global]
secret_key = "itlYmFR2vYKrOmFhupMIn/hyB6lYCCTXz4yaQX89XVg="

View File

@ -36,12 +36,12 @@ impl<'a, 'r> FromRequest<'a, 'r> for User {
}
#[post("/login", data = "<login>")]
fn login(mut cookies: Cookies, login: Form<Login>) -> Flash<Redirect> {
fn login(mut cookies: Cookies, login: Form<Login>) -> Result<Redirect, Flash<Redirect>> {
if login.get().username == "Sergio" && login.get().password == "password" {
cookies.add_private(Cookie::new("user_id", 1.to_string()));
Flash::success(Redirect::to(uri!(index)), "Successfully logged in.")
Ok(Redirect::to(uri!(index)))
} else {
Flash::error(Redirect::to(uri!(login_page)), "Invalid username/password.")
Err(Flash::error(Redirect::to(uri!(login_page)), "Invalid username/password."))
}
}