added: TextStream<> DbTextStream<> and HtmlTextStream<> have operator<<(Space&) now
added: to db: bool DbBase::AssertValueSpace(PGresult * r, int row, int col, Space & space, bool split_single) added: environment variables for users User::env (of type Space) and User::aenv (of type Space) for admin variables (can be changed only by a super user) added: winix function 'env' for changing User::env and User::aenv ('env' winix function with a 'a' parameter) git-svn-id: svn://ttmath.org/publicrep/winix/trunk@790 e52654a7-88a9-db11-a3e9-0013d4bc506e
This commit is contained in:
60
db/db.cpp
60
db/db.cpp
@@ -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.
|
||||
*
|
||||
*/
|
||||
@@ -68,8 +68,7 @@ return user_ok;
|
||||
|
||||
|
||||
|
||||
Error Db::AddUser(User & user, const std::wstring & password, const std::string & password_encrypted,
|
||||
int pass_type, bool pass_hash_salted)
|
||||
Error Db::AddUser(User & user, const UserPass & up)
|
||||
{
|
||||
PGresult * r = 0;
|
||||
Error status = WINIX_ERR_OK;
|
||||
@@ -78,22 +77,25 @@ Error Db::AddUser(User & user, const std::wstring & password, const std::string
|
||||
{
|
||||
query.Clear();
|
||||
query << R("insert into core.user (login, password, pass_encrypted, super_user, email,"
|
||||
"notify, pass_type, pass_hash_salted) values (")
|
||||
"notify, pass_type, pass_hash_salted, env, aenv) values (")
|
||||
<< user.name;
|
||||
|
||||
// for safety
|
||||
if( password_encrypted.empty() )
|
||||
query << password;
|
||||
// for safety we put up.pass only if there is not an encrypted version
|
||||
// someone could have forgotten to clear up.pass
|
||||
if( up.pass_encrypted.empty() )
|
||||
query << up.pass;
|
||||
else
|
||||
query << "";
|
||||
|
||||
query.EPutBin(password_encrypted);
|
||||
query.EPutBin(up.pass_encrypted);
|
||||
|
||||
query << user.super_user
|
||||
<< user.email
|
||||
<< user.notify
|
||||
<< pass_type
|
||||
<< pass_hash_salted
|
||||
<< up.pass_type
|
||||
<< up.pass_hash_salted
|
||||
<< user.env
|
||||
<< user.aenv
|
||||
<< R(");");
|
||||
|
||||
r = AssertQuery(query);
|
||||
@@ -140,8 +142,31 @@ return DoCommand(query);
|
||||
}
|
||||
|
||||
|
||||
Error Db::ChangeUserEnv(long user_id, const Space & space)
|
||||
{
|
||||
query.Clear();
|
||||
query << R("update core.user set(env) = (")
|
||||
<< space
|
||||
<< R(") where id = ")
|
||||
<< user_id
|
||||
<< R(";");
|
||||
|
||||
return DoCommand(query);
|
||||
}
|
||||
|
||||
|
||||
Error Db::ChangeUserAdminEnv(long user_id, const Space & space)
|
||||
{
|
||||
query.Clear();
|
||||
query << R("update core.user set(aenv) = (")
|
||||
<< space
|
||||
<< R(") where id = ")
|
||||
<< user_id
|
||||
<< R(";");
|
||||
|
||||
return DoCommand(query);
|
||||
}
|
||||
|
||||
|
||||
//!! wywalic z nazwy 'Subject' nic nie jest robione z tytulem
|
||||
// ta metoda uzywana tez jest w EditParentUrlById()
|
||||
@@ -1239,18 +1264,13 @@ return EndTrans(result);
|
||||
|
||||
Error Db::EditMetaById(const Space & meta, long id)
|
||||
{
|
||||
meta_stream.Clear();
|
||||
meta.Serialize(meta_stream);
|
||||
|
||||
query.Clear();
|
||||
query << R("update core.item set (meta) = (")
|
||||
<< meta_stream.Str()
|
||||
<< meta
|
||||
<< R(") where id=")
|
||||
<< id
|
||||
<< R(";");
|
||||
|
||||
meta_stream.Clear();
|
||||
|
||||
return DoCommand(query);
|
||||
}
|
||||
|
||||
@@ -1506,7 +1526,7 @@ void Db::GetUsers(UGContainer<User> & user_tab)
|
||||
try
|
||||
{
|
||||
query.Clear();
|
||||
query << R("select id, login, super_user, group_id, email, notify"
|
||||
query << R("select id, login, super_user, group_id, email, notify, env, aenv"
|
||||
" from core.user left outer join core.group_mem on"
|
||||
" core.user.id = core.group_mem.user_id order by id asc;");
|
||||
|
||||
@@ -1521,12 +1541,14 @@ void Db::GetUsers(UGContainer<User> & user_tab)
|
||||
int cgroup_id = AssertColumn(r, "group_id");
|
||||
int cemail = AssertColumn(r, "email");
|
||||
int cnotify = AssertColumn(r, "notify");
|
||||
int cenv = AssertColumn(r, "env");
|
||||
int caenv = AssertColumn(r, "aenv");
|
||||
|
||||
User u;
|
||||
long last_id = -1;
|
||||
UGContainer<User>::Iterator iter = user_tab.End();
|
||||
|
||||
for(int i = 0 ; i<rows ; ++i)
|
||||
for(int i=0 ; i<rows ; ++i)
|
||||
{
|
||||
u.id = AssertValueLong(r, i, cid);
|
||||
|
||||
@@ -1536,6 +1558,8 @@ void Db::GetUsers(UGContainer<User> & user_tab)
|
||||
u.super_user = AssertValueBool(r, i, csuper_user);
|
||||
u.email = AssertValueWide(r, i, cemail);
|
||||
u.notify = AssertValueInt(r, i, cnotify);
|
||||
AssertValueSpace(r, i, cenv, u.env);
|
||||
AssertValueSpace(r, i, caenv, u.aenv);
|
||||
|
||||
log << log2 << "Db: user: id: " << u.id << ", name: " << u.name << ", super_user: " << u.super_user << logend;
|
||||
|
||||
|
Reference in New Issue
Block a user