added: 'remember me' flag when logging

added: the session file
       sessions can still be available between starting and stopping the cmslu system


git-svn-id: svn://ttmath.org/publicrep/cmslu/trunk@529 e52654a7-88a9-db11-a3e9-0013d4bc506e
This commit is contained in:
2009-11-20 23:09:52 +00:00
parent 848afac803
commit 4827c116f0
21 changed files with 443 additions and 36 deletions

View File

@@ -6,7 +6,8 @@
* All rights reserved.
*
*/
#include <ctime>
#include "request.h"
#include "getparser.h"
#include "postparser.h"
@@ -14,7 +15,7 @@
#include "log.h"
#include "data.h"
#include "plugin.h"
#include "misc.h"
@@ -84,29 +85,35 @@ void Request::Clear()
// value can be null
void Request::SetCookie(const char * name, const char * value)
void Request::SetCookie(const char * name, const char * value, tm * expires)
{
request.headers << "Set-Cookie: " << name << "=";
headers << "Set-Cookie: " << name << "=";
if( value && value[0]!=0 )
request.headers << value;
headers << value;
else
request.headers << "\"\"";
headers << "\"\"";
request.headers << "; path=/\r\n";
if( expires )
headers << "; expires=" << DateToStrCookie(expires) << " GMT";
headers << "; path=/\r\n";
}
void Request::SetCookie(const char * name, long value)
void Request::SetCookie(const char * name, long value, tm * expires)
{
request.headers << "Set-Cookie: " << name << "=" << value << "; path=/\r\n";
headers << "Set-Cookie: " << name << "=" << value;
if( expires )
headers << "; expires=" << DateToStrCookie(expires) << " GMT";
headers << "; path=/\r\n";
}
bool Request::IsPostVar(const char * var)
{
PostTable::iterator p;
@@ -298,8 +305,36 @@ void Request::Read()
void Request::SendSessionCookie()
{
if( !session || session->id==0 )
return;
if( !session->puser || !session->remember_me )
{
SetCookie(data.http_session_id_name.c_str(), session->id);
return;
}
time_t t = time(0) + data.session_remember_max_iddle;
tm * expires = localtime(&t);
if( !expires )
{
// oops, something wrong
SetCookie(data.http_session_id_name.c_str(), session->id);
return;
}
SetCookie(data.http_session_id_name.c_str(), session->id, expires);
}
void Request::SendAll()
{
SendSessionCookie();
if( !redirect_to.empty() )
{
FCGX_PutS("Status: 301 Moved Permanently\r\n", out);