User Class Reference

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>

Inheritance diagram for User:
Inheritance graph
[legend]
Collaboration diagram for User:
Collaboration graph
[legend]

List of all members.

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 BasketgetBasket ()=0
virtual OrderplaceOrder ()=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 Userfactory (string aName, string aSurname, string aLogin, string aPasswd, string anAddress="", string aCity="")
 Create a new instance of an unprivileged user, initialized with parameters.
static UseruserByID (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 Userlogin (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 &)

Detailed Description

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).

Note:
Class destructor needs to be virtual so that will be called when a derived class is used.
See also:
getBasket, placeOrder

Constructor & Destructor Documentation

User::User (  ) 

Default constructor, used to create a new instance to be saved later.

See also:
factory, ManagedObject
User::User ( Row &  aRow  ) 

Constructs an instance of User and fill it with data taken from mysqlpp::Row.

Parameters:
aRow Record fetched from the database
See also:
ManagedObject
User::~User (  )  [virtual]

Default destructor.


Member Function Documentation

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.

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.

Returns:
The full name

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.

Returns:
True if the current user has administration privileges.

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.

Parameters:
[in] username The username to test
[in] passwd The password to test
Returns:
An instance of User class

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).

Returns:
The primary key of the entity

Implements ManagedObject.

References KEY_USR_UID.

ulonglong User::uniqueID (  ) 

Returns the user ID which uniquely identifies this instance.

Returns:
The user ID

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.

Parameters:
[in] anUid User ID to be fetched
Returns:
An instance of User

References Database::getConnection(), Database::Instance(), KEY_USR_ADMIN, and QUERY_FETCH.

Referenced by Order::Order().


Friends And Related Function Documentation

ostream& operator<< ( ostream &  aStream,
User u 
) [friend]

The documentation for this class was generated from the following files:

Generated by  doxygen 1.6.2