winix/core/user.h

117 lines
2.6 KiB
C++
Executable File

/*
* This file is a part of Winix
* and is not publicly distributed
*
* Copyright (c) 2008-2014, Tomasz Sowa
* All rights reserved.
*
*/
#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
#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
{
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