mirror of
https://github.com/actix/examples
synced 2025-06-28 18:00:37 +02:00
upgrade to 2.0 alpha.3
This commit is contained in:
@ -2,24 +2,25 @@ use actix_identity::Identity;
|
||||
use actix_identity::{CookieIdentityPolicy, IdentityService};
|
||||
use actix_web::{middleware, web, App, HttpResponse, HttpServer};
|
||||
|
||||
fn index(id: Identity) -> String {
|
||||
async fn index(id: Identity) -> String {
|
||||
format!(
|
||||
"Hello {}",
|
||||
id.identity().unwrap_or_else(|| "Anonymous".to_owned())
|
||||
)
|
||||
}
|
||||
|
||||
fn login(id: Identity) -> HttpResponse {
|
||||
async fn login(id: Identity) -> HttpResponse {
|
||||
id.remember("user1".to_owned());
|
||||
HttpResponse::Found().header("location", "/").finish()
|
||||
}
|
||||
|
||||
fn logout(id: Identity) -> HttpResponse {
|
||||
async fn logout(id: Identity) -> HttpResponse {
|
||||
id.forget();
|
||||
HttpResponse::Found().header("location", "/").finish()
|
||||
}
|
||||
|
||||
fn main() -> std::io::Result<()> {
|
||||
#[actix_rt::main]
|
||||
async fn main() -> std::io::Result<()> {
|
||||
std::env::set_var("RUST_LOG", "actix_web=info");
|
||||
env_logger::init();
|
||||
|
||||
@ -37,5 +38,6 @@ fn main() -> std::io::Result<()> {
|
||||
.service(web::resource("/").route(web::get().to(index)))
|
||||
})
|
||||
.bind("127.0.0.1:8080")?
|
||||
.run()
|
||||
.start()
|
||||
.await
|
||||
}
|
||||
|
Reference in New Issue
Block a user