1
0
mirror of https://github.com/actix/actix-website synced 2025-01-22 16:15:56 +01:00

update user_session sample (#292)

This commit is contained in:
Takahiro, NAKAMURA 2022-10-26 19:14:06 +09:00 committed by GitHub
parent 2bc48c18c8
commit f6d103da57
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 5 deletions

View File

@ -5,6 +5,6 @@ edition = "2018"
[dependencies] [dependencies]
actix-web = "4" actix-web = "4"
actix-session = "0.5.0-beta.8" actix-session = { version = "0.7.2", features = ["cookie-session"] }
futures-util = { version = "0.3.7", default-features = false, features = ["std"] } futures-util = { version = "0.3.7", default-features = false, features = ["std"] }
env_logger = "0.7" env_logger = "0.7"

View File

@ -1,8 +1,8 @@
#![allow(dead_code)] #![allow(dead_code)]
// <user-session> // <user-session>
use actix_session::{CookieSession, Session}; use actix_session::{Session, SessionMiddleware, storage::CookieSessionStore};
use actix_web::{web, App, Error, HttpResponse, HttpServer}; use actix_web::{web, App, Error, HttpResponse, HttpServer, cookie::Key};
async fn index(session: Session) -> Result<HttpResponse, Error> { async fn index(session: Session) -> Result<HttpResponse, Error> {
// access session data // access session data
@ -23,8 +23,10 @@ async fn main() -> std::io::Result<()> {
HttpServer::new(|| { HttpServer::new(|| {
App::new() App::new()
.wrap( .wrap(
CookieSession::signed(&[0; 32]) // <- create cookie based session middleware // create cookie based session middleware
.secure(false), SessionMiddleware::builder(CookieSessionStore::default(), Key::from(&[0; 64]))
.cookie_secure(false)
.build()
) )
.service(web::resource("/").to(index)) .service(web::resource("/").to(index))
}) })