UserMenu Class Reference

Display menus and handles user input. More...

#include <UserMenu.h>

List of all members.

Public Member Functions

 UserMenu ()
 Default constructor.
 ~UserMenu ()
 Default destructor.
void mainMenu ()
 Main menu.
bool login ()
 User login.
void display () throw (BadAuthException)
 Display a menu to the screen, according to authorization level of current user.
void registerNewUser ()
 Give the user the opportunity to register as new user.

Protected Member Functions

void enableSttyEcho (bool bValue=true)
 Enable or disable STTY echo.

Private Member Functions

void printCatalog (int aCid=0)
 Display all product beloging to a category ID.
void browseProductCatalog () throw (BadAuthException)
 Browse product catalog by category.
void showProductDetail () throw (BadAuthException)
 Display all details of a given product.
void showConfigurationByProduct () throw (BadAuthException)
 Show all product configurations which include a given product.
void showUserProfile () throw (BadAuthException)
 Show user profile and all his orders.
void placeNewOrder () throw (BadAuthException)
 Place a new order.
void addNewCategory () throw (BadAuthException)
 Admin operation to create a new category of products.
void addNewProduct () throw (BadAuthException)
 Admin operation to add a new product.
void changeProductDetail () throw (BadAuthException)
 Admin operation to update an existing product.
void disableUser () throw (BadAuthException)
 Admin operation to disable a registered user.
void displayMonthlyTrend () throw (BadAuthException)
 Admin operation to display monthly trend of sales.
void deleteProduct () throw (BadAuthException)
 Delete a product (even if already sold).
void displayUnprivilegedMenu () throw (BadAuthException)
 Display user menu (for not-admin users).
void displayAdminMenu () throw (BadAuthException)
 Display all available admin operations.
void wait ()
 Wait for user to press enter/return to continue.
bool getNotEmptyLine (const string &msg, string *buffer)
 Get input from standard input.

Private Attributes

User_currentUser
map< int, opusr_operations
map< int, opadm_operations

Detailed Description

Display menus and handles user input.


Constructor & Destructor Documentation

UserMenu::UserMenu (  ) 
UserMenu::~UserMenu (  ) 

Default destructor.

Dealloc the logged user, if any.

References _currentUser, and LOG_DTOR.


Member Function Documentation

void UserMenu::addNewCategory (  )  throw (BadAuthException) [private]

Admin operation to create a new category of products.

Exceptions:
BadAuthException If called without being authenticated

References _currentUser, CLEAR_SCREEN_CMD, Category::factory(), getNotEmptyLine(), ManagedObject::store(), and wait().

Referenced by UserMenu().

void UserMenu::addNewProduct (  )  throw (BadAuthException) [private]

Admin operation to add a new product.

Exceptions:
BadAuthException If called without being authenticated

References _currentUser, Category::catalog(), CLEAR_SCREEN_CMD, Product::factory(), getNotEmptyLine(), ManagedObject::store(), and wait().

Referenced by UserMenu().

void UserMenu::browseProductCatalog (  )  throw (BadAuthException) [private]

Browse product catalog by category.

Display all products belonging to a category or display them all if any category is chosen.

Exceptions:
BadAuthException If called without being authenticated

References _currentUser, Category::catalog(), CLEAR_SCREEN_CMD, printCatalog(), and wait().

Referenced by UserMenu().

void UserMenu::changeProductDetail (  )  throw (BadAuthException) [private]

Admin operation to update an existing product.

Exceptions:
BadAuthException If called without being authenticated

References _currentUser, getNotEmptyLine(), KEY_PRD_DESCR, KEY_PRD_NAME, KEY_PRD_PRICE, printCatalog(), Product::productByID(), ManagedObject::setValueForKey(), ManagedObject::update(), and wait().

Referenced by UserMenu().

void UserMenu::deleteProduct (  )  throw (BadAuthException) [private]

Delete a product (even if already sold).

Exceptions:
BadAuthException If called by client programmer without any logged user
See also:
AdminUser::deleteProduct()

References _currentUser, CLEAR_SCREEN_CMD, AdminUser::deleteProduct(), printCatalog(), and wait().

Referenced by UserMenu().

void UserMenu::disableUser (  )  throw (BadAuthException) [private]

Admin operation to disable a registered user.

Exceptions:
BadAuthException If called without being authenticated or not authorized
See also:
AdminUser::changeUserPassword()

References _currentUser, AdminUser::changeUserPassword(), CLEAR_SCREEN_CMD, User::fullName(), User::loginName(), User::userByID(), AdminUser::userList(), and wait().

Referenced by UserMenu().

void UserMenu::display (  )  throw (BadAuthException)

Display a menu to the screen, according to authorization level of current user.

Exceptions:
BadAuthException If called by client programmer without any logged user
See also:
displayAdminMenu(), displayUnprivilegedMenu()

References _currentUser, displayAdminMenu(), displayUnprivilegedMenu(), and User::isAdmin().

Referenced by mainMenu().

void UserMenu::displayAdminMenu (  )  throw (BadAuthException) [private]

Display all available admin operations.

Exceptions:
BadAuthException if called without the correct level of authorization.

References _currentUser, adm_operations, CLEAR_SCREEN_CMD, and User::fullName().

Referenced by display().

void UserMenu::displayMonthlyTrend (  )  throw (BadAuthException) [private]

Admin operation to display monthly trend of sales.

Exceptions:
BadAuthException If called without being authenticated or not authorized

References _currentUser, CLEAR_SCREEN_CMD, AdminUser::showMonthlyTrend(), and wait().

Referenced by UserMenu().

void UserMenu::displayUnprivilegedMenu (  )  throw (BadAuthException) [private]

Display user menu (for not-admin users).

Exceptions:
BadAuthException if called without the correct level of authorization.

References _currentUser, CLEAR_SCREEN_CMD, User::fullName(), and usr_operations.

Referenced by display().

void UserMenu::enableSttyEcho ( bool  bValue = true  )  [protected]

Enable or disable STTY echo.

This function disables (or enables) the echo of input coming from the STTY, such as the keyboard; calling this method is useful when the user is asked to enter his password and this data don't need to be echo-ed to screen.

See also:
login()

Referenced by login().

bool UserMenu::getNotEmptyLine ( const string &  msg,
string *  buffer 
) [private]

Get input from standard input.

Parameters:
[in] msg String to prompt before getting input
[out] buffer Pointer to string to fill with data
Returns:
True if operation was successful and buffer has been filled

Referenced by addNewCategory(), addNewProduct(), changeProductDetail(), and registerNewUser().

bool UserMenu::login (  ) 

User login.

Ask user to enter his crendentials and test the access: if successful, an instance of User is allocated and assigned to _currentUser.

Returns:
True if user logged in successfully (credentials were valid).
See also:
User::login(), enableSttyEcho()

References _currentUser, CLEAR_SCREEN_CMD, enableSttyEcho(), User::login(), and wait().

Referenced by mainMenu(), and registerNewUser().

void UserMenu::mainMenu (  ) 

Main menu.

Displays the main menu: user is allowed to login into the system, register himself as new user or quit the application.

See also:
login(), registerNewUser(), display()

References CLEAR_SCREEN_CMD, display(), login(), and registerNewUser().

Referenced by main().

void UserMenu::placeNewOrder (  )  throw (BadAuthException) [private]

Place a new order.

Help the user to choose one or more items from available products and add them to his basket; after last confirmation, a new order is created.

Exceptions:
BadAuthException if called without the correct level of authorization.

References _currentUser, Basket::addProduct(), CLEAR_SCREEN_CMD, User::getBasket(), Basket::itemCount(), User::placeOrder(), printCatalog(), Basket::total(), and wait().

Referenced by UserMenu().

void UserMenu::printCatalog ( int  aCid = 0  )  [private]

Display all product beloging to a category ID.

Parameters:
[in] aCid Category ID
Exceptions:
BadAuthException if called without the correct level of authorization.

References ProductProxy::catalog(), ProductProxy::getCategory(), ProductProxy::getName(), ProductProxy::getPrice(), and ProductProxy::uniqueID().

Referenced by browseProductCatalog(), changeProductDetail(), deleteProduct(), placeNewOrder(), showConfigurationByProduct(), and showProductDetail().

void UserMenu::registerNewUser (  ) 

Give the user the opportunity to register as new user.

See also:
User::factory

References CLEAR_SCREEN_CMD, User::factory(), getNotEmptyLine(), login(), and wait().

Referenced by mainMenu().

void UserMenu::showConfigurationByProduct (  )  throw (BadAuthException) [private]

Show all product configurations which include a given product.

Exceptions:
BadAuthException if called without the correct level of authorization.

References _currentUser, CLEAR_SCREEN_CMD, printCatalog(), Product::showCompatibleProducts(), and wait().

Referenced by UserMenu().

void UserMenu::showProductDetail (  )  throw (BadAuthException) [private]

Display all details of a given product.

Exceptions:
BadAuthException if called without the correct level of authorization.

References _currentUser, CLEAR_SCREEN_CMD, ProductProxy::isValid(), printCatalog(), and wait().

Referenced by UserMenu().

void UserMenu::showUserProfile (  )  throw (BadAuthException) [private]

Show user profile and all his orders.

Exceptions:
BadAuthException if called without the correct level of authorization.

References _currentUser, CLEAR_SCREEN_CMD, ProductProxy::getName(), Order::ordersForUser(), Order::products(), and wait().

Referenced by UserMenu().

void UserMenu::wait (  )  [private]

Member Data Documentation

map<int, op> UserMenu::adm_operations [private]

Referenced by displayAdminMenu(), and UserMenu().

map<int, op> UserMenu::usr_operations [private]

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

Generated by  doxygen 1.6.2