/* * This file is a part of Winix * and is not publicly distributed * * Copyright (c) 2008-2012, Tomasz Sowa * All rights reserved. * */ #ifndef headerfile_winix_core_user #define headerfile_winix_core_user #include #include #include "space/space.h" #include "date/date.h" #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 groups; std::wstring email; int notify; // !! currently all users have the same offset // option in config: time_zone_offset int time_zone_offset; // 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; // time zone // values here are the same as those in env space // we provide they here to speed up the process of calculating times // time zone offset time_t tz_offset; // true if the time zone has daylight saving time bool tz_has_dst; // time zone daylight saving time (used if tz_has_dst is true) // the 'year' field is ignored PT::Date tz_dst_start, tz_dst_end; User() { Clear(); } void Clear() { id = -1; name.clear(); super_user = false; groups.clear(); email.clear(); notify = 0; time_zone_offset = 0; env.Clear(); aenv.Clear(); status = WINIX_ACCOUNT_BLOCKED; tz_offset = 0; tz_has_dst = false; tz_dst_start.Clear(); tz_dst_end.Clear(); } bool IsMemberOf(long group) { std::vector::iterator i; for(i=groups.begin() ; i!=groups.end() ; ++i) if( *i == group ) return true; return false; } // lepsza nazwe dac void SetTz() { tz_offset = env.Long(L"tz_offset"); } }; #endif