start working on User and Group classes
- User and Group has been moved to 'models' directory - removed UserPass struct (passwords fields were put to User struct) not working yet, we need support for binary blobs in morm
This commit is contained in:
@@ -297,6 +297,29 @@ bool App::Init()
|
||||
}
|
||||
/////////////
|
||||
|
||||
morm::Finder<User> finder(model_connector);
|
||||
|
||||
User user = finder.
|
||||
select().
|
||||
where().
|
||||
eq(L"id", 1).
|
||||
get();
|
||||
|
||||
|
||||
log << log1 << user << logend;
|
||||
|
||||
|
||||
|
||||
std::exit(0);
|
||||
|
||||
|
||||
|
||||
|
||||
//////////////////////////////////
|
||||
|
||||
|
||||
|
||||
|
||||
db_conn.SetConnParam(config.db_database, config.db_user, config.db_pass);
|
||||
db_conn.WaitForConnection();
|
||||
db.PostgreSQLsmallerThan10(config.db_postgresql_smaller_than_10);
|
||||
|
@@ -5,7 +5,7 @@
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2011-2018, Tomasz Sowa
|
||||
* Copyright (c) 2011-2021, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
@@ -267,28 +267,28 @@ bool Crypt::RSA(bool encrypt, const std::wstring & keypath, const std::string &
|
||||
|
||||
|
||||
|
||||
bool Crypt::PassHash(const std::wstring & salt, UserPass & up)
|
||||
bool Crypt::PassHash(const std::wstring & salt, User & user)
|
||||
{
|
||||
bool result = true;
|
||||
up.pass_hash_salted = false;
|
||||
user.pass_hash_salted = false;
|
||||
|
||||
if( up.pass_type != WINIX_CRYPT_HASH_NONE )
|
||||
if( user.pass_type != WINIX_CRYPT_HASH_NONE )
|
||||
{
|
||||
pass_org = up.pass;
|
||||
pass_salted = up.pass;
|
||||
pass_org = user.password;
|
||||
pass_salted = user.password;
|
||||
pass_salted += salt;
|
||||
|
||||
if( HashHex(up.pass_type, pass_salted, up.pass) )
|
||||
if( HashHex(user.pass_type, pass_salted, user.password) )
|
||||
{
|
||||
if( !salt.empty() )
|
||||
up.pass_hash_salted = true;
|
||||
user.pass_hash_salted = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
log << log1 << "Crypt: problem with generating a hash, the password will not be hashed" << logend;
|
||||
|
||||
up.pass = pass_org;
|
||||
up.pass_type = WINIX_CRYPT_HASH_NONE;
|
||||
user.password = pass_org;
|
||||
user.pass_type = WINIX_CRYPT_HASH_NONE;
|
||||
result = false;
|
||||
}
|
||||
|
||||
@@ -301,22 +301,22 @@ return result;
|
||||
|
||||
|
||||
|
||||
bool Crypt::PassCrypt(const std::wstring & path_to_rsa_private_key, UserPass & up)
|
||||
bool Crypt::PassCrypt(const std::wstring & path_to_rsa_private_key, User & user)
|
||||
{
|
||||
bool result = false;
|
||||
ClearString(up.pass_encrypted);
|
||||
ClearString(user.pass_encrypted);
|
||||
|
||||
if( !path_to_rsa_private_key.empty() )
|
||||
{
|
||||
PT::WideToUTF8(up.pass, passa);
|
||||
PT::WideToUTF8(user.password, passa);
|
||||
|
||||
if( RSA(true, path_to_rsa_private_key, passa, up.pass_encrypted) )
|
||||
if( RSA(true, path_to_rsa_private_key, passa, user.pass_encrypted) )
|
||||
{
|
||||
result = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
ClearString(up.pass_encrypted);
|
||||
ClearString(user.pass_encrypted);
|
||||
log << log1 << "AddUser: problem with encrypting, the password will not be encrypted!" << logend;
|
||||
}
|
||||
|
||||
@@ -327,27 +327,27 @@ return result;
|
||||
}
|
||||
|
||||
|
||||
void Crypt::PassHashCrypt(const std::wstring & salt, const std::wstring & path_to_rsa_private_key, UserPass & up)
|
||||
void Crypt::PassHashCrypt(const std::wstring & salt, const std::wstring & path_to_rsa_private_key, User & user)
|
||||
{
|
||||
PassHash(salt, up);
|
||||
PassCrypt(path_to_rsa_private_key, up);
|
||||
PassHash(salt, user);
|
||||
PassCrypt(path_to_rsa_private_key, user);
|
||||
}
|
||||
|
||||
|
||||
|
||||
void Crypt::PassHashCrypt(UserPass & up)
|
||||
void Crypt::PassHashCrypt(User & user)
|
||||
{
|
||||
up.pass_type = config->pass_type;
|
||||
user.pass_type = config->pass_type;
|
||||
empty.clear();
|
||||
|
||||
if( config->pass_hash_use_salt && !config->pass_hash_salt.empty() )
|
||||
PassHash(config->pass_hash_salt, up);
|
||||
PassHash(config->pass_hash_salt, user);
|
||||
else
|
||||
PassHash(empty, up);
|
||||
PassHash(empty, user);
|
||||
|
||||
|
||||
if( config->pass_use_rsa && !config->pass_rsa_private_key.empty() )
|
||||
PassCrypt(config->pass_rsa_private_key, up);
|
||||
PassCrypt(config->pass_rsa_private_key, user);
|
||||
}
|
||||
|
||||
|
||||
|
@@ -5,7 +5,7 @@
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2011-2014, Tomasz Sowa
|
||||
* Copyright (c) 2011-2021, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
@@ -38,7 +38,7 @@
|
||||
#include <string>
|
||||
#include "run.h"
|
||||
#include "config.h"
|
||||
#include "user.h"
|
||||
#include "models/user.h"
|
||||
#include "winixbase.h"
|
||||
|
||||
|
||||
@@ -177,7 +177,7 @@ public:
|
||||
if there is a problem with generating a hash the method stores a plain text password
|
||||
and changes up.pass_type to zero (plain text passwords are not salted)
|
||||
*/
|
||||
bool PassHash(const std::wstring & salt, UserPass & up);
|
||||
bool PassHash(const std::wstring & salt, User & user);
|
||||
|
||||
|
||||
/*
|
||||
@@ -195,7 +195,7 @@ public:
|
||||
if there is a problem (or the path to the key is empty) then up.pass_encrypted will be empty
|
||||
and the method returns false
|
||||
*/
|
||||
bool PassCrypt(const std::wstring & path_to_rsa_private_key, UserPass & up);
|
||||
bool PassCrypt(const std::wstring & path_to_rsa_private_key, User & user);
|
||||
|
||||
|
||||
/*
|
||||
@@ -217,7 +217,7 @@ public:
|
||||
up.pass_encrypted - encrypted password (if not empty)
|
||||
|
||||
*/
|
||||
void PassHashCrypt(const std::wstring & salt, const std::wstring & path_to_rsa_private_key, UserPass & up);
|
||||
void PassHashCrypt(const std::wstring & salt, const std::wstring & path_to_rsa_private_key, User & user);
|
||||
|
||||
|
||||
/*
|
||||
@@ -232,7 +232,7 @@ public:
|
||||
up.pass_hash_salted - true if the hash is salted (plain text are never salted)
|
||||
up.pass_encrypted - encrypted password (if not empty)
|
||||
*/
|
||||
void PassHashCrypt(UserPass & up);
|
||||
void PassHashCrypt(User & user);
|
||||
|
||||
|
||||
/*
|
||||
|
@@ -1,74 +0,0 @@
|
||||
/*
|
||||
* This file is a part of Winix
|
||||
* and is distributed under the 2-Clause BSD licence.
|
||||
* Author: Tomasz Sowa <t.sowa@ttmath.org>
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2008-2014, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef headerfile_winix_core_group
|
||||
#define headerfile_winix_core_group
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
|
||||
namespace Winix
|
||||
{
|
||||
|
||||
|
||||
|
||||
struct Group
|
||||
{
|
||||
long id;
|
||||
std::wstring name; // group name
|
||||
std::vector<long> members; // users id
|
||||
|
||||
Group()
|
||||
{
|
||||
Clear();
|
||||
}
|
||||
|
||||
|
||||
void Clear()
|
||||
{
|
||||
id = -1;
|
||||
name.clear();
|
||||
members.clear();
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
} // namespace Winix
|
||||
|
||||
|
||||
|
||||
#endif
|
@@ -5,7 +5,7 @@
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2008-2018, Tomasz Sowa
|
||||
* Copyright (c) 2008-2021, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
@@ -63,7 +63,16 @@ void Groups::ReadGroups(Db * db)
|
||||
{
|
||||
Clear();
|
||||
|
||||
db->GetGroups(table);
|
||||
morm::Finder<Group> finder(model_connector);
|
||||
|
||||
std::vector<Group> groups_tmp = finder.
|
||||
select().
|
||||
get_vector();
|
||||
|
||||
for(Group & group : groups_tmp)
|
||||
{
|
||||
table.PushBack(group);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@@ -37,7 +37,7 @@
|
||||
|
||||
#include <map>
|
||||
|
||||
#include "group.h"
|
||||
#include "models/group.h"
|
||||
#include "ugcontainer.h"
|
||||
#include "db/db.h"
|
||||
#include "winixmodel.h"
|
||||
|
@@ -205,6 +205,12 @@ Log & Log::operator<<(const PT::Date & date)
|
||||
}
|
||||
|
||||
|
||||
Log & Log::operator<<(morm::Model & model)
|
||||
{
|
||||
PT::Log::operator<<(model);
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
Log & Log::operator<<(LogManipulators m)
|
||||
{
|
||||
|
@@ -78,6 +78,7 @@ public:
|
||||
virtual Log & operator<<(const PT::Space & space);
|
||||
virtual Log & operator<<(LogManipulators m);
|
||||
virtual Log & operator<<(const PT::Date & date);
|
||||
virtual Log & operator<<(morm::Model & model);
|
||||
|
||||
virtual void PrintDate(const PT::Date & date);
|
||||
|
||||
|
@@ -40,7 +40,7 @@
|
||||
#include <ctime>
|
||||
#include <map>
|
||||
#include "error.h"
|
||||
#include "user.h"
|
||||
#include "models/user.h"
|
||||
#include "plugindata.h"
|
||||
#include "rebus.h"
|
||||
#include "textstream.h"
|
||||
|
@@ -1,83 +0,0 @@
|
||||
/*
|
||||
* This file is a part of Winix
|
||||
* and is distributed under the 2-Clause BSD licence.
|
||||
* Author: Tomasz Sowa <t.sowa@ttmath.org>
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2012-2021, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "user.h"
|
||||
|
||||
|
||||
namespace Winix
|
||||
{
|
||||
|
||||
|
||||
|
||||
User::User()
|
||||
{
|
||||
Clear();
|
||||
}
|
||||
|
||||
|
||||
void User::Clear()
|
||||
{
|
||||
id = -1;
|
||||
name.clear();
|
||||
super_user = false;
|
||||
groups.clear();
|
||||
email.clear();
|
||||
notify = 0;
|
||||
env.clear();
|
||||
aenv.clear();
|
||||
status = WINIX_ACCOUNT_BLOCKED;
|
||||
locale_id = 0;
|
||||
time_zone_id = 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool User::IsMemberOf(long group)
|
||||
{
|
||||
std::vector<long>::iterator i;
|
||||
|
||||
for(i=groups.begin() ; i!=groups.end() ; ++i)
|
||||
if( *i == group )
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
} // namespace Winix
|
||||
|
||||
|
@@ -1,145 +0,0 @@
|
||||
/*
|
||||
* This file is a part of Winix
|
||||
* and is distributed under the 2-Clause BSD licence.
|
||||
* Author: Tomasz Sowa <t.sowa@ttmath.org>
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2008-2014, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef headerfile_winix_core_user
|
||||
#define headerfile_winix_core_user
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include "space/space.h"
|
||||
#include "date/date.h"
|
||||
|
||||
|
||||
namespace Winix
|
||||
{
|
||||
|
||||
|
||||
|
||||
#define WINIX_ACCOUNT_MAX_LOGIN_SIZE 250
|
||||
#define WINIX_ACCOUNT_MAX_PASSWORD_SIZE 250
|
||||
#define WINIX_ACCOUNT_MAX_EMAIL_SIZE 250
|
||||
|
||||
|
||||
|
||||
// account status
|
||||
// 1 - a user has created its account -- an email was sent back to him
|
||||
#define WINIX_ACCOUNT_NOT_ACTIVATED 1
|
||||
|
||||
// 2 - a user clicked on the link in the mail and now can normally use his account
|
||||
// (if has a password set too)
|
||||
#define WINIX_ACCOUNT_READY 2
|
||||
|
||||
// 3 - account was suspended
|
||||
#define WINIX_ACCOUNT_SUSPENDED 3
|
||||
|
||||
// 4 - account was banned
|
||||
#define WINIX_ACCOUNT_BLOCKED 4
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/*
|
||||
a user can login only to an account which status is equal to WINIX_ACCOUNT_READY
|
||||
|
||||
actually there is no difference between WINIX_ACCOUNT_SUSPENDED and WINIX_ACCOUNT_BANNED
|
||||
only a different message will be present on the website
|
||||
|
||||
you can use other values of status in your plugins - this not have any impact on winix
|
||||
the default 'login' winix function only allowes to login a user who has WINIX_ACCOUNT_READY value
|
||||
but you can provide your own 'login' function which can work in a different way
|
||||
|
||||
winix knows that user is login when cur->session->puser pointer is set
|
||||
(when the pointer is not null then winix do not check what the value of 'status' is --
|
||||
the status is only tested in 'login' function)
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
a temporary struct used for hashing and encrypting a user's password
|
||||
*/
|
||||
struct UserPass
|
||||
{
|
||||
bool has_pass; // true if the user has a password set
|
||||
// if false the user cannot login
|
||||
int pass_type; // the kind of hash (WINIX_CRYPT_HASH_* see crypt.h)
|
||||
std::wstring pass; // password hashed or plain text if pass_type==0
|
||||
std::string pass_encrypted; // password encrypted
|
||||
bool pass_hash_salted; // true when the hash was salted (plain text passwords are never salted)
|
||||
};
|
||||
|
||||
|
||||
|
||||
struct User
|
||||
{
|
||||
long id;
|
||||
std::wstring name;
|
||||
bool super_user;
|
||||
std::vector<long> groups;
|
||||
std::wstring email;
|
||||
int notify;
|
||||
|
||||
// environment variables which can be set by this user
|
||||
// use 'env' winix function
|
||||
PT::Space env;
|
||||
|
||||
// environment variables set only by an administrator
|
||||
// an administrator can use 'env' winix function with 'a' parameter
|
||||
PT::Space aenv;
|
||||
|
||||
// account status
|
||||
// WINIX_ACCOUNT_*
|
||||
// a user can normally login only when status is WINIX_ACCOUNT_READY
|
||||
int status;
|
||||
|
||||
// locale identifier
|
||||
size_t locale_id;
|
||||
|
||||
// time zone identifier
|
||||
size_t time_zone_id;
|
||||
|
||||
User();
|
||||
|
||||
void Clear();
|
||||
bool IsMemberOf(long group);
|
||||
bool ReadMonthDayTime(PT::Date & date, const wchar_t * str);
|
||||
bool SetTzFromEnv();
|
||||
|
||||
};
|
||||
|
||||
|
||||
} // namespace Winix
|
||||
|
||||
|
||||
#endif
|
@@ -79,8 +79,18 @@ void Users::Clear()
|
||||
|
||||
void Users::ReadUsers(Db * db)
|
||||
{
|
||||
Clear();
|
||||
db->GetUsers(table);
|
||||
Clear();
|
||||
|
||||
morm::Finder<User> finder(model_connector);
|
||||
|
||||
std::list<User> users_tmp = finder.
|
||||
select().
|
||||
get_list();
|
||||
|
||||
for(User & user : users_tmp)
|
||||
{
|
||||
table.PushBack(user);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@@ -36,7 +36,7 @@
|
||||
#define headerfile_winix_core_users
|
||||
|
||||
#include <map>
|
||||
#include "user.h"
|
||||
#include "models/user.h"
|
||||
#include "ugcontainer.h"
|
||||
#include "lastcontainer.h"
|
||||
#include "cur.h"
|
||||
|
Reference in New Issue
Block a user