fixed: base_url_redirect config option was not read from the config file

and was not used when checking for base url redirect
fixed: return values from plugins should be given in a special structure
       they were remembered in plugin object (ret_false, ret_true)
       and consequently were not thread safe
       now all plugin.Call() methods return PluginRes structure 
       in which there are ret_false and ret_true variables       
changed: small refactoring in AddUser winix function



git-svn-id: svn://ttmath.org/publicrep/winix/trunk@827 e52654a7-88a9-db11-a3e9-0013d4bc506e
pull/3/head
Tomasz Sowa 11 years ago
parent 920290e9dc
commit bcea4f9464

@ -187,6 +187,14 @@ void App::BaseUrlRedirect(int code)
bool App::BaseUrlRedirect()
{
plugin.Call((Session*)0, WINIX_BASE_URL_REDIRECT);
if( !cur.request->redirect_to.empty() )
return true;
if( !config.base_url_redirect )
return false;
if( config.base_url.empty() )
return false;

@ -167,6 +167,8 @@ void Config::AssignValues(bool stdout_is_closed)
base_url_static = Text(L"base_url_static");
base_url_common = Text(L"base_url_common");
base_url_redirect = Bool(L"base_url_redirect");
NoLastSlash(base_url);
NoLastSlash(base_url_static);
NoLastSlash(base_url_common);

@ -2,7 +2,7 @@
* This file is a part of Winix
* and is not publicly distributed
*
* Copyright (c) 2008-2011, Tomasz Sowa
* Copyright (c) 2008-2012, Tomasz Sowa
* All rights reserved.
*
*/
@ -41,9 +41,6 @@ Plugin::Plugin()
templates = 0;
synchro = 0;
session_manager = 0;
ret_false = 0;
ret_true = 0;
}
@ -296,13 +293,9 @@ void Plugin::Call(Session * ses, int message, Slots::iterator & slot, PluginInfo
void Plugin::Call(Session * ses, int message, void * p1_, void * p2_, long l1_, long l2_)
PluginRes Plugin::Call(Session * ses, int message, void * p1_, void * p2_, long l1_, long l2_)
{
// how many plugins return 'false' and 'true'
// we are using local variables because Call() method can be called
// from a plugin too (one Call() can execute another Call())
int ret_false_loc = 0;
int ret_true_loc = 0;
PluginRes res;
int old_current_plugin = current_plugin;
PluginInfo info;
@ -319,111 +312,111 @@ PluginInfo info;
Call(ses, message, i, info);
if( info.res )
++ret_true_loc;
++res.res_true;
else
++ret_false_loc;
++res.res_false;
}
current_plugin = old_current_plugin;
ret_false = ret_false_loc;
ret_true = ret_true_loc;
return res;
}
void Plugin::Call(int message)
PluginRes Plugin::Call(int message)
{
Call(cur->session, message, 0, 0, 0, 0);
return Call(cur->session, message, 0, 0, 0, 0);
}
void Plugin::Call(int message, void * p1_)
PluginRes Plugin::Call(int message, void * p1_)
{
Call(cur->session, message, p1_, 0, 0, 0);
return Call(cur->session, message, p1_, 0, 0, 0);
}
void Plugin::Call(int message, void * p1_, void * p2_)
PluginRes Plugin::Call(int message, void * p1_, void * p2_)
{
Call(cur->session, message, p1_, p2_, 0, 0);
return Call(cur->session, message, p1_, p2_, 0, 0);
}
void Plugin::Call(int message, long l1_)
PluginRes Plugin::Call(int message, long l1_)
{
Call(cur->session, message, 0, 0, l1_, 0);
return Call(cur->session, message, 0, 0, l1_, 0);
}
void Plugin::Call(int message, long l1_, long l2_)
PluginRes Plugin::Call(int message, long l1_, long l2_)
{
Call(cur->session, message, 0, 0, l1_, l2_);
return Call(cur->session, message, 0, 0, l1_, l2_);
}
void Plugin::Call(int message, void * p1_, long l1_)
PluginRes Plugin::Call(int message, void * p1_, long l1_)
{
Call(cur->session, message, p1_, 0, l1_, 0);
return Call(cur->session, message, p1_, 0, l1_, 0);
}
void Plugin::Call(int message, void * p1_, long l1_, long l2_)
PluginRes Plugin::Call(int message, void * p1_, long l1_, long l2_)
{
Call(cur->session, message, p1_, 0, l1_, l2_);
return Call(cur->session, message, p1_, 0, l1_, l2_);
}
void Plugin::Call(int message, void * p1_, void * p2_, long l1_)
PluginRes Plugin::Call(int message, void * p1_, void * p2_, long l1_)
{
Call(cur->session, message, p1_, p2_, l1_, 0);
return Call(cur->session, message, p1_, p2_, l1_, 0);
}
void Plugin::Call(Session * ses, int message)
PluginRes Plugin::Call(Session * ses, int message)
{
Call(ses, message, 0, 0, 0, 0);
return Call(ses, message, 0, 0, 0, 0);
}
void Plugin::Call(Session * ses, int message, void * p1_)
PluginRes Plugin::Call(Session * ses, int message, void * p1_)
{
Call(ses, message, p1_, 0, 0, 0);
return Call(ses, message, p1_, 0, 0, 0);
}
void Plugin::Call(Session * ses, int message, void * p1_, void * p2_)
PluginRes Plugin::Call(Session * ses, int message, void * p1_, void * p2_)
{
Call(ses, message, p1_, p2_, 0, 0);
return Call(ses, message, p1_, p2_, 0, 0);
}
void Plugin::Call(Session * ses, int message, long l1_)
PluginRes Plugin::Call(Session * ses, int message, long l1_)
{
Call(ses, message, 0, 0, l1_, 0);
return Call(ses, message, 0, 0, l1_, 0);
}
void Plugin::Call(Session * ses, int message, long l1_, long l2_)
PluginRes Plugin::Call(Session * ses, int message, long l1_, long l2_)
{
Call(ses, message, 0, 0, l1_, l2_);
return Call(ses, message, 0, 0, l1_, l2_);
}
void Plugin::Call(Session * ses, int message, void * p1_, long l1_)
PluginRes Plugin::Call(Session * ses, int message, void * p1_, long l1_)
{
Call(ses, message, p1_, 0, l1_, 0);
return Call(ses, message, p1_, 0, l1_, 0);
}
void Plugin::Call(Session * ses, int message, void * p1_, long l1_, long l2_)
PluginRes Plugin::Call(Session * ses, int message, void * p1_, long l1_, long l2_)
{
Call(ses, message, p1_, 0, l1_, l2_);
return Call(ses, message, p1_, 0, l1_, l2_);
}
void Plugin::Call(Session * ses, int message, void * p1_, void * p2_, long l1_)
PluginRes Plugin::Call(Session * ses, int message, void * p1_, void * p2_, long l1_)
{
Call(ses, message, p1_, p2_, l1_, 0);
return Call(ses, message, p1_, p2_, l1_, 0);
}
@ -436,19 +429,12 @@ size_t Plugin::Size()
}
int Plugin::True()
{
return ret_true;
}
int Plugin::False()
{
return ret_false;
}
/*
!! IMPROVE ME
Assign() can work only if other threads are not started
we can add some barrier/flag so when other threads starts
then we cannot use Assign() method
*/
void Plugin::Assign(int message, Fun1 fun1)
{
Slot s;

@ -2,7 +2,7 @@
* This file is a part of Winix
* and is not publicly distributed
*
* Copyright (c) 2008-2011, Tomasz Sowa
* Copyright (c) 2008-2012, Tomasz Sowa
* All rights reserved.
*
*/
@ -104,6 +104,22 @@ struct PluginInfo
};
/*
this structure tells how many plugins returned true and false
*/
struct PluginRes
{
int res_false;
int res_true;
PluginRes()
{
res_false = 0;
res_true = 0;
}
};
class Plugin
{
@ -168,36 +184,28 @@ public:
bool HasMessage(int message);
void Call(int message);
void Call(int message, void * p1_);
void Call(int message, void * p1_, void * p2_);
void Call(int message, long l1_);
void Call(int message, long l1_, long l2_);
void Call(int message, void * p1_, long l1_);
void Call(int message, void * p1_, long l1_, long l2_);
void Call(int message, void * p1_, void * p2_, long l1_);
void Call(Session * ses, int message, void * p1_, void * p2_, long l1_, long l2_);
PluginRes Call(int message);
PluginRes Call(int message, void * p1_);
PluginRes Call(int message, void * p1_, void * p2_);
PluginRes Call(int message, long l1_);
PluginRes Call(int message, long l1_, long l2_);
PluginRes Call(int message, void * p1_, long l1_);
PluginRes Call(int message, void * p1_, long l1_, long l2_);
PluginRes Call(int message, void * p1_, void * p2_, long l1_);
PluginRes Call(Session * ses, int message, void * p1_, void * p2_, long l1_, long l2_);
void Call(Session * ses, int message);
void Call(Session * ses, int message, void * p1_);
void Call(Session * ses, int message, void * p1_, void * p2_);
void Call(Session * ses, int message, long l1_);
void Call(Session * ses, int message, long l1_, long l2_);
void Call(Session * ses, int message, void * p1_, long l1_);
void Call(Session * ses, int message, void * p1_, long l1_, long l2_);
void Call(Session * ses, int message, void * p1_, void * p2_, long l1_);
PluginRes Call(Session * ses, int message);
PluginRes Call(Session * ses, int message, void * p1_);
PluginRes Call(Session * ses, int message, void * p1_, void * p2_);
PluginRes Call(Session * ses, int message, long l1_);
PluginRes Call(Session * ses, int message, long l1_, long l2_);
PluginRes Call(Session * ses, int message, void * p1_, long l1_);
PluginRes Call(Session * ses, int message, void * p1_, long l1_, long l2_);
PluginRes Call(Session * ses, int message, void * p1_, void * p2_, long l1_);
// how many plugins there are
size_t Size();
// how many plugins returned 'true'
// from last Call()
int True();
// how many plugins returned 'false'
// from last Call()
int False();
// assign a function to a message
// you can assign more than one function to a specific message
void Assign(int message, Fun1);
@ -217,9 +225,6 @@ private:
Synchro * synchro;
SessionManager * session_manager;
int ret_false;
int ret_true;
std::wstring temp_path;
Plugins plugins;

@ -221,7 +221,11 @@
// in l1 you have the old user_id
#define WINIX_USER_REMOVED 31020
// here you can check if the domain part of the URL address is correct
// if no then set cur-request->redirect_to
// and winix will do a 'base url redirect' without making any winix functions
// the session pointer in info is null
#define WINIX_BASE_URL_REDIRECT 31030
// values from 4000 - 4099 reserved for 'thread' plugin

@ -134,6 +134,7 @@ struct Request
tm start_tm;
Request();
void SetConfig(Config * pconfig);
void RequestStarts();

@ -216,9 +216,9 @@ bool Users::LoginUser(long user_id, bool remember_me, bool use_ses_log)
if( !puser )
return false;
plugin.Call(WINIX_PREPARE_USER_TO_LOGIN, puser);
PluginRes res = plugin.Call(WINIX_PREPARE_USER_TO_LOGIN, puser);
if( plugin.False() > 0 )
if( res.res_false > 0 )
{
log << log3 << "Users: login prevented by a plugin" << logend;
return false;

@ -158,33 +158,40 @@ return false;
void AddUser::MakePost()
/*
adding a new account
this method doesn't check whether the login or password is correct
(consist of allowed characters)
input:
login - account login name
pass - password
email - email address
autoactivate - if true then the account will be created with WINIX_ACCOUNT_READY flag
(an email will not be sent)
if false then the flag depends on config->account_need_email_verification
try_login - if true then if there is no a user logged (in this session)
and if the account is ready (has WINIX_ACCOUNT_READY flag)
the the new user will be logged in
use_ses_log - when true the session logger will be used (info about sending an email)
*/
bool AddUser::AddNewUser(const std::wstring & login,
const std::wstring & pass,
const std::wstring & email,
bool autoactivate,
bool try_login,
bool use_ses_log)
{
user.Clear();
const std::wstring & login = cur->request->PostVar(L"login");
const std::wstring & pass = cur->request->PostVar(L"password");
const std::wstring & conf_pass = cur->request->PostVar(L"passwordconfirm");
const std::wstring & email = cur->request->PostVar(L"email");
long code = 0;
if( !IsLoginCorrect(login, true) || !IsEmailCorrect(email, true) ||
!functions->fun_passwd.IsPasswordCorrect(pass, conf_pass, true) )
return;
user.name = login;
user.email = email;
user.super_user = false;
user.notify = 0;
user.status = (config->account_need_email_verification)? WINIX_ACCOUNT_NOT_ACTIVATED : WINIX_ACCOUNT_READY;
long code = 0;
if( cur->session->puser && cur->session->puser->super_user )
{
if( cur->request->IsPostVar(L"autoactivate") )
{
user.status = WINIX_ACCOUNT_READY;
log << log2 << "AddUser: account activated by an admin" << logend;
}
}
if( autoactivate )
user.status = WINIX_ACCOUNT_READY;
if( user.status == WINIX_ACCOUNT_NOT_ACTIVATED )
{
@ -194,7 +201,7 @@ void AddUser::MakePost()
if( AddNewUser(user, pass) )
{
if( !cur->session->puser && user.status == WINIX_ACCOUNT_READY )
if( try_login && !cur->session->puser && user.status == WINIX_ACCOUNT_READY )
{
system->users.LoginUser(user.id, false);
log << log2 << "AddUser: now logged as: " << user.name << logend;
@ -204,11 +211,41 @@ void AddUser::MakePost()
if( user.status == WINIX_ACCOUNT_NOT_ACTIVATED )
{
system->notify.ActivateAccount(user.name, user.email, code);
slog << loginfo << T(L"account_email_sent") << logend;
if( use_ses_log )
slog << loginfo << T(L"account_email_sent") << logend;
}
system->RedirectToLastItem();
return true;
}
return false;
}
void AddUser::MakePost()
{
const std::wstring & login = cur->request->PostVar(L"login");
const std::wstring & pass = cur->request->PostVar(L"password");
const std::wstring & conf_pass = cur->request->PostVar(L"passwordconfirm");
const std::wstring & email = cur->request->PostVar(L"email");
bool autoactivate = false;
if( !IsLoginCorrect(login, true) ||
!IsEmailCorrect(email, true) ||
!functions->fun_passwd.IsPasswordCorrect(pass, conf_pass, true) )
return;
if( cur->session->puser && cur->session->puser->super_user )
{
autoactivate = cur->request->IsPostVar(L"autoactivate");
if( autoactivate )
log << log2 << "AddUser: account activated by an admin" << logend;
}
if( AddNewUser(login, pass, email, autoactivate, true, true) )
system->RedirectToLastItem();
}

@ -32,6 +32,13 @@ public:
bool HasLoginCorrectChars(const std::wstring & login);
bool AddNewUser(User & user, const std::wstring & pass);
bool AddNewUser(const std::wstring & login,
const std::wstring & pass,
const std::wstring & email,
bool autoactivate,
bool try_login,
bool use_ses_log = false);
private:
UserPass up;

@ -106,9 +106,9 @@ void ShowTickets::CreatePointers()
void ShowTickets::SortPointers()
{
plugin.Call(WINIX_PL_TICKET_SORT_POINTERS, &ticket_info->item_sort_tab);
PluginRes res = plugin.Call(WINIX_PL_TICKET_SORT_POINTERS, &ticket_info->item_sort_tab);
if( plugin.True() > 0 )
if( res.res_true > 0 )
return;
int sort_type = 1;

@ -21,5 +21,3 @@ Content-Type: {notify_content_type}
-- \n
{notify_footer1}\n
{notify_footer2}\n
{notify_footer3}\n
{notify_footer4}\n

@ -21,5 +21,3 @@ Content-Type: {notify_content_type}
-- \n
{notify_footer1}\n
{notify_footer2}\n
{notify_footer3}\n
{notify_footer4}\n

Loading…
Cancel
Save