added: new plugin message: WINIX_PREPARE_USER_TO_LOGIN

a user will be logged in
        set PluginInfo::res to false (it is by default) to prevent logging the user
        directly after this message (if you do not return false)
        a WINIX_USER_LOGGED is sent
        in p1 you have a pointer to User struct
        (if at least one plugin returns false then the user will not be logged)



git-svn-id: svn://ttmath.org/publicrep/winix/trunk@820 e52654a7-88a9-db11-a3e9-0013d4bc506e
This commit is contained in:
Tomasz Sowa 2012-03-14 20:25:30 +00:00
parent 2712c57f15
commit b1b3cea64e
6 changed files with 61 additions and 31 deletions

View File

@ -280,7 +280,8 @@ void Plugin::Call(int message, Slots::iterator & slot, PluginInfo & info)
slot->second.is_running = false;
if( config->log_plugin_call )
log << log1 << "Plugin: returning from plugin id: " << slot->second.index << ", message: " << message << logend;
log << log1 << "Plugin: returning from plugin id: " << slot->second.index << ", message: " << message
<< ", result: " << (info.res? "true" : "false") << logend;
}
else
@ -382,10 +383,6 @@ size_t Plugin::Size()
}
// !! to nie jest dobre rozwiazanie
// obsluga jednego komunikatu moze wywolac inny komunikat
// i zmienne sie nadpisza
// potrzebujemy cos ala stos wywolan
int Plugin::True()
{
return ret_true;

View File

@ -159,6 +159,14 @@
// this is from system->dirs so you should not change the item
#define WINIX_DIR_CONTENT_SORTED 30500
// a user will be logged in
// set PluginInfo::res to false (it is by default) to prevent logging the user
// directly after this message (if you do not return false)
// a WINIX_USER_LOGGED is sent
// in p1 you have a pointer to User struct
// (if at least one plugin returns false then the user will not be logged)
#define WINIX_PREPARE_USER_TO_LOGIN 30550
// a user has been logged
// send from 'login' winix function
// this message is also called when winix starts and reads sessions

View File

@ -16,7 +16,7 @@
Users::Users()
{
how_many_logged = 0;
how_many_logged = 0; // !! CHECK ME may it should be moved to Clear() method?
Clear();
}
@ -146,17 +146,15 @@ return result;
}
// !! IMPROVE ME
// this method is too long
bool Users::LoginUser(long user_id, bool remember_me, bool use_ses_log)
// private
bool Users::LoginUserCheckSession(bool use_ses_log)
{
if( !cur->session )
return false;
if( cur->session->id == 0 )
{
log << log1 << "Users: cannot login a user on a temporary session" << logend;
log << log1 << "Users: I cannot login a user on a temporary session" << logend;
if( use_ses_log )
slog << logerror << T(L"service_unavailable") << logend;
@ -164,6 +162,13 @@ bool Users::LoginUser(long user_id, bool remember_me, bool use_ses_log)
return false;
}
return true;
}
// private
User * Users::LoginUserCheckStatus(long user_id, bool use_ses_log)
{
User * puser = GetUser(user_id);
if( !puser )
@ -173,7 +178,7 @@ bool Users::LoginUser(long user_id, bool remember_me, bool use_ses_log)
if( use_ses_log )
slog << logerror << T(L"service_unavailable") << logend;
return false;
return 0;
}
if( puser->status != WINIX_ACCOUNT_READY )
@ -193,6 +198,29 @@ bool Users::LoginUser(long user_id, bool remember_me, bool use_ses_log)
slog << logerror << T(L"account_banned") << logend;
}
return 0;
}
return puser;
}
bool Users::LoginUser(long user_id, bool remember_me, bool use_ses_log)
{
if( !LoginUserCheckSession(use_ses_log) )
return false;
User * puser = LoginUserCheckStatus(user_id, use_ses_log);
if( !puser )
return false;
plugin.Call(WINIX_PREPARE_USER_TO_LOGIN, puser);
if( plugin.False() > 0 )
{
log << log3 << "Users: login prevented by a plugin" << logend;
return false;
}
@ -204,11 +232,10 @@ bool Users::LoginUser(long user_id, bool remember_me, bool use_ses_log)
cur->session->remember_me = remember_me;
last.UserLogin(user_id, cur->session->puser->name, inet_addr(cur->request->env_remote_addr), cur->session->id);
// !! jesli uzytkownik ponownie sie loguje ten sam na ta sama sesje to mozna nie zwiekszac licznika
how_many_logged += 1;
log << log2 << "User " << cur->session->puser->name << " (id: " << user_id << ") logged" << logend;
log << log2 << "Users: user " << cur->session->puser->name << " (id: " << user_id << ") logged" << logend;
plugin.Call(WINIX_USER_LOGGED);
return true;
}

View File

@ -22,12 +22,7 @@ class SessionManager;
class Users
{
typedef UGContainer<User> Table;
Table table;
Cur * cur;
SessionManager * session_manager;
long how_many_logged;
typedef UGContainer<User> Table;
public:
@ -60,6 +55,18 @@ public:
void IncrementLoggedUsers();
long HowManyLogged();
private:
Table table;
Cur * cur;
SessionManager * session_manager;
long how_many_logged;
bool LoginUserCheckSession(bool use_ses_log);
User * LoginUserCheckStatus(long user_id, bool use_ses_log);
};

View File

@ -521,12 +521,7 @@ login.o: ../core/users.h ../core/ugcontainer.h ../core/lastcontainer.h
login.o: ../core/mounts.h ../core/mountparser.h ../core/crypt.h
login.o: ../core/users.h ../core/groups.h ../core/group.h ../core/loadavg.h
login.o: ../core/image.h ../core/basethread.h ../core/threadmanager.h
login.o: ../core/synchro.h ../core/plugin.h ../core/pluginmsg.h
login.o: ../core/system.h ../core/sessionmanager.h ../core/sessioncontainer.h
login.o: ../functions/functions.h ../templates/templates.h
login.o: ../templates/patterncacher.h ../templates/indexpatterns.h
login.o: ../templates/patterns.h ../templates/changepatterns.h
login.o: ../templates/htmltextstream.h ../core/sessionmanager.h
login.o: ../core/synchro.h
logout.o: logout.h functionbase.h ../core/item.h
logout.o: ../../pikotools/confparser/space.h ../db/db.h ../db/dbbase.h
logout.o: ../db/dbconn.h ../db/dbtextstream.h ../core/textstream.h

View File

@ -9,7 +9,6 @@
#include "login.h"
#include "utf8/utf8.h"
#include "core/plugin.h"
@ -108,10 +107,7 @@ long user_id;
if( CheckUserPass(login, password, user_id) )
{
if( system->users.LoginUser(user_id, remember_me, use_ses_log) )
{
plugin.Call(WINIX_USER_LOGGED);
return true;
}
}
else
{