mirror of https://github.com/rwf2/Rocket.git
Always set 'secret_key' in session example.
This commit also removes a previously unused 'Flash' message.
This commit is contained in:
parent
648eb1a5eb
commit
76bbcb5de8
|
@ -1,7 +1,2 @@
|
|||
[staging]
|
||||
secret_key = "itlYmFR2vYKrOmFhupMIn/hyB6lYCCTXz4yaQX89XVg="
|
||||
address = "localhost"
|
||||
port = 8000
|
||||
|
||||
[production]
|
||||
[global]
|
||||
secret_key = "itlYmFR2vYKrOmFhupMIn/hyB6lYCCTXz4yaQX89XVg="
|
||||
|
|
|
@ -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."))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue