aboutsummaryrefslogtreecommitdiff
path: root/backend/src/handlers
diff options
context:
space:
mode:
authorAkshay <[email protected]>2020-12-28 07:50:35 +0000
committerAkshay <[email protected]>2020-12-28 07:50:35 +0000
commit3baea0e943ef89c7c73a5de51cbd41f78f8f0f14 (patch)
treeb1c7fe119b90f77daf170e10af000e0c1ed1270e /backend/src/handlers
parentd5aabbac71fcd12f31c82159fe0d7a58d0ad925d (diff)
add redis integration
Diffstat (limited to 'backend/src/handlers')
-rw-r--r--backend/src/handlers/users.rs12
1 files changed, 12 insertions, 0 deletions
diff --git a/backend/src/handlers/users.rs b/backend/src/handlers/users.rs
index 8423384..775635e 100644
--- a/backend/src/handlers/users.rs
+++ b/backend/src/handlers/users.rs
@@ -9,6 +9,7 @@ use actix_web::{web, HttpResponse, Responder};
9use bcrypt::{hash, verify, DEFAULT_COST}; 9use bcrypt::{hash, verify, DEFAULT_COST};
10use diesel::prelude::*; 10use diesel::prelude::*;
11use log::{error, info}; 11use log::{error, info};
12use redis::Commands;
12use serde::{Deserialize, Serialize}; 13use serde::{Deserialize, Serialize};
13 14
14pub async fn new_user( 15pub async fn new_user(
@@ -74,6 +75,14 @@ pub async fn login(
74 let hashed_pass = selected_user.password; 75 let hashed_pass = selected_user.password;
75 if verify(entered_pass, &hashed_pass).unwrap() { 76 if verify(entered_pass, &hashed_pass).unwrap() {
76 cookie.remember(login_details.username.clone()); 77 cookie.remember(login_details.username.clone());
78 let redis_client = redis::Client::open("redis://127.0.0.1/").unwrap();
79 let mut redis_conn = redis_client.get_connection().unwrap();
80 redis_conn
81 .set::<String, String, String>(
82 login_details.username.clone(),
83 cookie.identity().unwrap(),
84 )
85 .unwrap();
77 info!( 86 info!(
78 "Successful login: {} {}", 87 "Successful login: {} {}",
79 selected_user.username, selected_user.email_id 88 selected_user.username, selected_user.email_id
@@ -85,6 +94,9 @@ pub async fn login(
85} 94}
86 95
87pub async fn logout(cookie: Identity) -> impl Responder { 96pub async fn logout(cookie: Identity) -> impl Responder {
97 let redis_client = redis::Client::open("redis://127.0.0.1/").unwrap();
98 let mut redis_conn = redis_client.get_connection().unwrap();
99 redis_conn.del::<String, String>(cookie.identity().unwrap());
88 cookie.forget(); 100 cookie.forget();
89 HttpResponse::Ok().body("Successful logout.") 101 HttpResponse::Ok().body("Successful logout.")
90} 102}