Basically I was suggesting to create a session manager class, which provies a consistant interface / APIs for user authintacation, which can be used by all the widgets / dialogs.
Example:
class SessionManager
: public QObject{
Q_Object;
public:
{
if(isCorrectPassword(user_name, password)) //check the username and password from database
{
userNamer = user_name;
timer = startTimer(5 * 60 * 1000); //Auto Log out in 5 mins
return true;
}
return false;
}
void stopUser(void)
{
userName = "";
}
bool isUserActive(void)
{
return !userName.isEmpty();
}
{
return userName;
}
{
if(!userNmae.isEmpty())
{
timer = startTimer(5 * 60 * 1000); //Auto Log out in 5 mins
return getDataFromDataBase(database_name, table_name)
}
}
protected:
{
if(timer == event->timerId())
{
stopUser(); //Logout user
}
killTimer(event->timerId());
}
private:
int timer ;
}
class SessionManager : public QObject
{
Q_Object;
public:
bool startUser(QString user_name, QString password)
{
if(isCorrectPassword(user_name, password)) //check the username and password from database
{
userNamer = user_name;
timer = startTimer(5 * 60 * 1000); //Auto Log out in 5 mins
return true;
}
return false;
}
void stopUser(void)
{
userName = "";
}
bool isUserActive(void)
{
return !userName.isEmpty();
}
QString activeUser(void)
{
return userName;
}
QString getData(QString database_name, QString table_name)
{
if(!userNmae.isEmpty())
{
timer = startTimer(5 * 60 * 1000); //Auto Log out in 5 mins
return getDataFromDataBase(database_name, table_name)
}
return QString();
}
protected:
void timerEvent(QTimerEvent * event)
{
if(timer == event->timerId())
{
stopUser(); //Logout user
}
killTimer(event->timerId());
}
private:
QString userName;
int timer ;
}
To copy to clipboard, switch view to plain text mode
So all access to database is done only by the session manager class, also if you wish, you can make session manage a singleton class.
Bookmarks