mirror of
https://github.com/Relintai/rcpp_framework.git
synced 2025-05-02 13:47:56 +02:00
Added a middleware func to SessionManager that can set up request's session property.
This commit is contained in:
parent
03276bdc26
commit
e62d012ec1
@ -6,6 +6,8 @@
|
|||||||
|
|
||||||
#include "core/hash/sha256.h"
|
#include "core/hash/sha256.h"
|
||||||
|
|
||||||
|
#include "request.h"
|
||||||
|
|
||||||
void SessionManager::add_session(HTTPSession *session) {
|
void SessionManager::add_session(HTTPSession *session) {
|
||||||
if (!session) {
|
if (!session) {
|
||||||
printf("SessionManager::add_session: ERROR, session is null!\n");
|
printf("SessionManager::add_session: ERROR, session is null!\n");
|
||||||
@ -94,7 +96,7 @@ void SessionManager::clear() {
|
|||||||
_sessions_vec.clear();
|
_sessions_vec.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string generate_session_id(const std::string &base) {
|
std::string SessionManager::generate_session_id(const std::string &base) {
|
||||||
//todo make something simpler / better
|
//todo make something simpler / better
|
||||||
|
|
||||||
SHA256 *h = SHA256::get();
|
SHA256 *h = SHA256::get();
|
||||||
@ -111,6 +113,16 @@ std::string generate_session_id(const std::string &base) {
|
|||||||
return sid;
|
return sid;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void SessionManager::session_setup_middleware(Object *instance, Request *request) {
|
||||||
|
const std::string &sid = request->get_cookie("session");
|
||||||
|
|
||||||
|
if (sid == "") {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
request->session = SessionManager::get_singleton()->get_session(sid);
|
||||||
|
}
|
||||||
|
|
||||||
SessionManager *SessionManager::get_singleton() {
|
SessionManager *SessionManager::get_singleton() {
|
||||||
return _self;
|
return _self;
|
||||||
}
|
}
|
||||||
|
@ -9,6 +9,7 @@
|
|||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
class HTTPSession;
|
class HTTPSession;
|
||||||
|
class Request;
|
||||||
|
|
||||||
class SessionManager : public Object {
|
class SessionManager : public Object {
|
||||||
public:
|
public:
|
||||||
@ -22,6 +23,8 @@ public:
|
|||||||
|
|
||||||
virtual std::string generate_session_id(const std::string &base = "");
|
virtual std::string generate_session_id(const std::string &base = "");
|
||||||
|
|
||||||
|
static void session_setup_middleware(Object *instance, Request *request);
|
||||||
|
|
||||||
static SessionManager *get_singleton();
|
static SessionManager *get_singleton();
|
||||||
|
|
||||||
SessionManager();
|
SessionManager();
|
||||||
|
Loading…
Reference in New Issue
Block a user