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]

List of all members.

Public Member Functions

 User ()
 Default constructor.
 User (Row &aRow)
 Class constructor.
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.
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 Userfactory (string aName, string aSurname, string aLogin, string aPasswd, string anAddress="", string aCity="")
 Create a new user.
static UseruserByID (int anUid)
 User constructor by ID.
static Userlogin (string username, string passwd)
 User login.

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

References LOG_CTOR.

User::User ( Row &  aRow  ) 

Class constructor.

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

Parameters:
aRow Record fetched from the database
See also:
ManagedObject, mysqlpp::Row

References LOG_CTOR.

User::~User (  )  [virtual]

Default destructor.

References LOG_DTOR.


Member Function Documentation

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.

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

Returns:
True if the current user has administration privileges.

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.

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

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.

Returns:
The login name

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

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

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

References Database::getConnection(), Singleton< Database >::instance(), KEY_USR_ADMIN, and QUERY_FETCH.

Referenced by UserMenu::disableUser(), Order::Order(), and testDataModel().


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