diff --git a/core/plugin.cpp b/core/plugin.cpp index 781d33a..b981178 100755 --- a/core/plugin.cpp +++ b/core/plugin.cpp @@ -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; diff --git a/core/pluginmsg.h b/core/pluginmsg.h index 997fae5..bd9b4fd 100755 --- a/core/pluginmsg.h +++ b/core/pluginmsg.h @@ -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 diff --git a/core/users.cpp b/core/users.cpp index 8d26f18..e9b42a2 100755 --- a/core/users.cpp +++ b/core/users.cpp @@ -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; } diff --git a/core/users.h b/core/users.h index 96d18fc..0c8ac5a 100755 --- a/core/users.h +++ b/core/users.h @@ -22,12 +22,7 @@ class SessionManager; class Users { -typedef UGContainer Table; -Table table; - - Cur * cur; - SessionManager * session_manager; - long how_many_logged; + typedef UGContainer 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); + }; diff --git a/functions/Makefile.dep b/functions/Makefile.dep index 42406dd..033043e 100755 --- a/functions/Makefile.dep +++ b/functions/Makefile.dep @@ -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 diff --git a/functions/login.cpp b/functions/login.cpp index 33a93a9..28dba08 100755 --- a/functions/login.cpp +++ b/functions/login.cpp @@ -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 {