User is the base class to permit login into the system and benefit of all services, such as product browsing, placing an order and so on. More...
#include <User.h>
Public Member Functions | |
User () | |
Default constructor, used to create a new instance to be saved later. | |
User (Row &aRow) | |
Constructs an instance of User and fill it with data taken from mysqlpp::Row. | |
virtual | ~User () |
Default destructor. | |
virtual Basket * | getBasket ()=0 |
virtual Order * | placeOrder ()=0 throw (string) |
ulonglong | uniqueID () |
Returns the user ID which uniquely identifies this instance. | |
string | fullName () |
Returns the full name of current user. | |
bool | isAdmin () |
Returns the authorization level of current user. | |
string | primaryKey () |
Returns the primary for entity "users" (KEY_USR_UID). | |
Static Public Member Functions | |
static User * | factory (string aName, string aSurname, string aLogin, string aPasswd, string anAddress="", string aCity="") |
Create a new instance of an unprivileged user, initialized with parameters. | |
static User * | userByID (int anUid) |
Fetch a user by specifing its ID: if successful, an instance of NormalUser or AdminUser is returned, according to authorization level, NULL otherwise. | |
static User * | login (string username, string passwd) |
Test given user credential to log into the system: if successful an instance of NormalUser or AdminUser is returned, according to authorization level, NULL otherwise. | |
Friends | |
ostream & | operator<< (ostream &, User &) |
User is the base class to permit login into the system and benefit of all services, such as product browsing, placing an order and so on.
It represents instances of the table "users" but it cannot be instantiated directly as it's an abstract class (see methods getBasket and placeOrder).
User::User | ( | ) |
Default constructor, used to create a new instance to be saved later.
User::User | ( | Row & | aRow | ) |
Constructs an instance of User and fill it with data taken from mysqlpp::Row.
aRow | Record fetched from the database |
User::~User | ( | ) | [virtual] |
Default destructor.
User * User::factory | ( | string | aName, | |
string | aSurname, | |||
string | aLogin, | |||
string | aPasswd, | |||
string | anAddress = "" , |
|||
string | aCity = "" | |||
) | [static] |
Create a new instance of an unprivileged user, initialized with parameters.
[in] | aName | The name of the user |
[in] | aSurname | The surname of the user |
[in] | aLogin | The login of the user |
[in] | aPasswd | The password of the user |
[in] | anAddress | The address of the user |
[in] | aCity | The city of the user |
References KEY_USR_ADDRESS, KEY_USR_ADMIN, KEY_USR_CITY, KEY_USR_LOGIN, KEY_USR_NAME, KEY_USR_PASSWD, KEY_USR_SURNAME, KEY_USR_UID, ManagedObject::setIntForKey(), ManagedObject::setValueForKey(), and ManagedObject::store().
Referenced by UserMenu::registerNewUser().
string User::fullName | ( | ) |
Returns the full name of current user.
References KEY_USR_NAME, KEY_USR_SURNAME, and ManagedObject::valueForKey().
Referenced by UserMenu::disableUser(), and operator<<().
virtual Basket* User::getBasket | ( | ) | [pure virtual] |
Implemented in AdminUser, and NormalUser.
Referenced by UserMenu::placeNewOrder().
bool User::isAdmin | ( | ) |
Returns the authorization level of current user.
Referenced by UserMenu::display().
User * User::login | ( | string | username, | |
string | passwd | |||
) | [static] |
Test given user credential to log into the system: if successful an instance of NormalUser or AdminUser is returned, according to authorization level, NULL otherwise.
[in] | username | The username to test |
[in] | passwd | The password to test |
References Database::getConnection(), Database::Instance(), KEY_USR_ADMIN, and QUERY_LOGIN.
Referenced by UserMenu::login().
virtual Order* User::placeOrder | ( | ) | throw (string) [pure virtual] |
Implemented in AdminUser, and NormalUser.
Referenced by UserMenu::placeNewOrder().
string User::primaryKey | ( | ) | [virtual] |
Returns the primary for entity "users" (KEY_USR_UID).
Implements ManagedObject.
References KEY_USR_UID.
ulonglong User::uniqueID | ( | ) |
Returns the user ID which uniquely identifies this instance.
References ManagedObject::intForKey(), and KEY_USR_UID.
Referenced by Order::ordersForUser().
User * User::userByID | ( | int | anUid | ) | [static] |
Fetch a user by specifing its ID: if successful, an instance of NormalUser or AdminUser is returned, according to authorization level, NULL otherwise.
[in] | anUid | User ID to be fetched |
References Database::getConnection(), Database::Instance(), KEY_USR_ADMIN, and QUERY_FETCH.
Referenced by Order::Order().
ostream& operator<< | ( | ostream & | aStream, | |
User & | u | |||
) | [friend] |