added: winix function: rmuser

changed: UGContainer<> now uses std::list as a storage
         (previously it was using std::vector with pointers)
removed: now we don't have the operator[] for UGContainer<>



git-svn-id: svn://ttmath.org/publicrep/winix/trunk@816 e52654a7-88a9-db11-a3e9-0013d4bc506e
This commit is contained in:
2012-03-09 02:36:25 +00:00
parent 6c2c12fe5e
commit 489310ba1c
51 changed files with 1146 additions and 602 deletions

View File

@@ -2,13 +2,15 @@
* This file is a part of Winix
* and is not publicly distributed
*
* Copyright (c) 2008-2010, Tomasz Sowa
* Copyright (c) 2008-2012, Tomasz Sowa
* All rights reserved.
*
*/
#include <arpa/inet.h>
#include "users.h"
#include "sessionmanager.h"
#include "plugin.h"
@@ -25,6 +27,12 @@ void Users::SetCur(Cur * pcur)
}
void Users::SetSessionManager(SessionManager * sm)
{
session_manager = sm;
}
void Users::Clear()
{
table.Clear();
@@ -45,7 +53,7 @@ void Users::SetTimeZoneOffset(int offset)
for(i=table.Begin() ; i!=table.End() ; ++i)
{
(*i)->time_zone_offset = offset;
i->time_zone_offset = offset;
}
}
@@ -71,7 +79,7 @@ User * Users::GetUser(long user_id)
if( i == table.End() )
return 0;
return &(**i);
return &(*i);
}
@@ -82,7 +90,7 @@ User * Users::GetUser(const std::wstring & name)
if( i == table.End() )
return 0;
return &(**i);
return &(*i);
}
@@ -119,13 +127,28 @@ Users::SizeType Users::Size()
}
User & Users::operator[](Users::SizeType pos)
bool Users::Remove(long user_id)
{
return table[pos];
bool result = false;
User * puser = GetUser(user_id);
if( puser )
{
LogoutUser(user_id);
plugin.Call(WINIX_PREPARE_TO_REMOVE_USER, puser);
result = table.Remove(user_id);
if( result )
plugin.Call(WINIX_USER_REMOVED, user_id);
}
return result;
}
// !! IMPROVE ME
// this method is too long
bool Users::LoginUser(long user_id, bool remember_me, bool use_ses_log)
{
if( !cur->session )
@@ -191,6 +214,27 @@ return true;
}
size_t Users::LogoutUser(long user_id)
{
size_t how_many = 0;
User * puser = GetUser(user_id);
if( puser )
{
log << log2 << "Users: logging out user " << puser->name << ", id: "
<< puser->id << " from all sessions" << logend;
// WINIX_PREPARE_USER_TO_LOGOUT will be sent by MarkAllSessionsToRemove()
how_many = session_manager->MarkAllSessionsToRemove(user_id);
how_many_logged -= how_many;
if( how_many )
log << log3 << "Users: " << how_many << " user(s) were logged out" << logend;
}
return how_many;
}
void Users::LogoutCurrentUser()
@@ -201,13 +245,14 @@ void Users::LogoutCurrentUser()
log << log2 << "Users: user " << cur->session->puser->name << ", id: "
<< cur->session->puser->id << " logged out" << logend;
plugin.Call(WINIX_PREPARE_USER_TO_LOGOUT, cur->session->puser);
last.UserLogout(cur->session->puser->id, cur->session->id);
if( how_many_logged > 0 ) // for safety
how_many_logged -= 1;
cur->session->puser = 0;
cur->session->remember_me = 0;
cur->session->remember_me = false;
}