mycq::UserManager Class Reference

Manages users of a MyCQ Server. More...

#include <UserManager.h>

List of all members.

Public Member Functions

virtual void createUser (string username, string password, UserType::Enum userType)=0
 Create a new user.
virtual void deleteUser (string username)=0
 Delete a user.
virtual void changePassword (string username, string password)=0
 Change the password of a user.
virtual void changeUserType (string username, UserType::Enum userType)=0
 Change the type of a user.
virtual std::vector< UserInfogetAllUserInfo ()=0
 Get the user information list of a MyCQ Server.

Detailed Description

Manages users of a MyCQ Server.

#include <iostream>
#include <vector>
#include "../MyCQClientCPP/MyCQClient.h"

using namespace mycq;

void examUserManager()
{           
            //get client instance
            MyCQClient* client = MyCQFactory::getMyCQClient();

            try
            {
                        //connect
                        client->connect("localhost", 3030, "root", "1234");

                        //get user manger
                        UserManager* userManager = client->getUserManager();

                        //create user
                        userManager->createUser("user1", "password1", UserType::SUPER_USER);

                        //change user type
                        userManager->changeUserType("user1", UserType::NORMAL_USER);

                        //change password
                        userManager->changePassword("user1", "password2");

                        //get all user information
                        std::vector<UserInfo> result = userManager->getAllUserInfo();
                        for(size_t i=0; i<result.size(); i++)
                        {
                                    std::cout << result[i].username << ", ";

                                    if(result[i].type == UserType::SUPER_USER)
                                    {
                                                std::cout << "super user" << std::endl;
                                    }
                                    else
                                    {
                                                std::cout << "normal user" << std::endl;
                                    }
                        }

                        //delete user
                        userManager->deleteUser("user1");
            }
            catch(MyCQException& ex)
            {
                        std::cout << "code:" << ex.getCode() << ", message:" << ex.getMessage();
            }

            //close connection
            client->close();

            //delete client instance
            MyCQFactory::close(client);
}

Member Function Documentation

virtual void mycq::UserManager::changePassword ( string  username,
string  password 
) [pure virtual]

Change the password of a user.

Parameters:
username A user name of a MyCQ Server to change the password.
password A password of a user to change. (size:= under 64).
Exceptions:
MyCQException An error occurred while changing the password of a user.
virtual void mycq::UserManager::changeUserType ( string  username,
UserType::Enum  userType 
) [pure virtual]

Change the type of a user.

Parameters:
username A user name of a MyCQ Server to change the user type.
userType A user type of a user to change.
Exceptions:
MyCQException An error occurred while changing the user type of a user.
virtual void mycq::UserManager::createUser ( string  username,
string  password,
UserType::Enum  userType 
) [pure virtual]

Create a new user.

Parameters:
username A user name of a MyCQ Server to create. (size:= under 64). A user name is a combination of alphabets and numerics which starts with alphabet character.
password A password of a user to create. (size:= under 64).
userType A user type of a user to create.
Exceptions:
MyCQException An error occurred while creating a new user.
virtual void mycq::UserManager::deleteUser ( string  username  )  [pure virtual]

Delete a user.

Parameters:
username A user name of a MyCQ Server to delete.
Exceptions:
MyCQException An error occurred while deleting a user.
virtual std::vector<UserInfo> mycq::UserManager::getAllUserInfo (  )  [pure virtual]

Get the user information list of a MyCQ Server.

Returns:
User information list.
Exceptions:
MyCQException An error occurred while getting the user information list.

The documentation for this class was generated from the following file:
 All Classes Namespaces Functions Variables Enumerations Enumerator
MyCQ C++ User's Document. Copyright@MyCQ Inc., All Rights Reserved.