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. | |
User (Row &aRow) | |
Class constructor. | |
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. | |
string | loginName () |
Returns the username used to log into the system. | |
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 user. | |
static User * | userByID (int anUid) |
User constructor by ID. | |
static User * | login (string username, string passwd) |
User login. | |
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.
References LOG_CTOR.
User::User | ( | Row & | aRow | ) |
Class constructor.
Constructs an instance of User and fill it with data taken from mysqlpp::Row
aRow | Record fetched from the database |
References LOG_CTOR.
User::~User | ( | ) | [virtual] |
Default destructor.
References LOG_DTOR.
User * User::factory | ( | string | aName, | |
string | aSurname, | |||
string | aLogin, | |||
string | aPasswd, | |||
string | anAddress = "" , |
|||
string | aCity = "" | |||
) | [static] |
Create a new user.
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(), UserMenu::displayAdminMenu(), UserMenu::displayUnprivilegedMenu(), 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.
polymorphic approach (it's anyway possible to use getUser()->boolForKey(KEY_USR_ADMIN);
Referenced by UserMenu::display().
User * User::login | ( | string | username, | |
string | passwd | |||
) | [static] |
User login.
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(), Singleton< Database >::instance(), KEY_USR_ADMIN, and QUERY_LOGIN.
Referenced by UserMenu::login(), and testDataModel().
string User::loginName | ( | ) |
Returns the username used to log into the system.
References KEY_USR_LOGIN, and ManagedObject::valueForKey().
Referenced by UserMenu::disableUser().
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 AdminUser::changeUserPassword(), and Order::ordersForUser().
User * User::userByID | ( | int | anUid | ) | [static] |
User constructor by ID.
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(), Singleton< Database >::instance(), KEY_USR_ADMIN, and QUERY_FETCH.
Referenced by UserMenu::disableUser(), Order::Order(), and testDataModel().
ostream& operator<< | ( | ostream & | aStream, | |
User & | u | |||
) | [friend] |