about summary refs log tree commit diff
path: root/src/handlers.rs
diff options
context:
space:
mode:
authorVincent Ambo <tazjin@gmail.com>2018-04-08T20·56+0200
committerVincent Ambo <tazjin@gmail.com>2018-04-08T20·56+0200
commit9eb8501fae4b4024e1b2d052b213351deeae8b81 (patch)
tree574497a9391304d1c5c4785210bfbf711a92826a /src/handlers.rs
parente761b2d295c920da153ac673892cfd9616e6a2b7 (diff)
feat(handlers): Use cookie session backend to store author info
Diffstat (limited to 'src/handlers.rs')
-rw-r--r--src/handlers.rs24
1 files changed, 16 insertions, 8 deletions
diff --git a/src/handlers.rs b/src/handlers.rs
index ebae7f390e..0531bb1742 100644
--- a/src/handlers.rs
+++ b/src/handlers.rs
@@ -5,14 +5,15 @@
 //! the tera templates stored in the `/templates` directory in the
 //! project root.
 
-use tera;
+use actix::prelude::{Addr, Syn};
 use actix_web::*;
-use models::*;
+use actix_web::middleware::RequestSession;
 use db::*;
-use actix::prelude::{Addr, Syn};
-use futures::Future;
 use errors::{Result, ConverseError};
+use futures::Future;
+use models::*;
 use oidc::*;
+use tera;
 
 type ConverseResponse = Box<Future<Item=HttpResponse, Error=ConverseError>>;
 
@@ -119,11 +120,18 @@ pub fn login(state: State<AppState>) -> ConverseResponse {
         .responder()
 }
 
-pub fn callback(state: State<AppState>, data: Form<CodeResponse>) -> ConverseResponse {
+pub fn callback(state: State<AppState>,
+                data: Form<CodeResponse>,
+                mut req: HttpRequest<AppState>) -> ConverseResponse {
     state.oidc.send(RetrieveToken(data.0))
         .from_err()
-        .and_then(|author| {
-            Ok(HttpResponse::from(format!("{:?}", author)))
-        })
+        .and_then(move |result| {
+            let author = result?;
+            info!("Setting cookie for {} after callback", author.name);
+            req.session().set("author_name", author.name)?;
+            req.session().set("author_email", author.email)?;
+            Ok(HttpResponse::SeeOther()
+               .header("Location", "/")
+               .finish())})
         .responder()
 }