Remember logged user information
In my little project, user shoulda log in then have ability to do whatever....
[users kept in Database]
But i don't know how can i hold user information to recognize user when moving between files and dialogs.
In web developing we use SESSIONS to do things like this.
First i thought is better to using file to save logged user info or SETTINGS and ...
Any idea?
Re: Remember logged user information
So which do you want to use, a database or a file?
Depending on your requirements, it might be worthwhile to look at QSqLite
Re: Remember logged user information
I don't think using QSetting / files is a good idea.
You can create user object and pass it around to dialogs (when creating them) or may be, create a kind of session manager (global), which keeps track of logged in user. All the widgets / dialogs can delegate with session manager for authorization.
Re: Remember logged user information
Quote:
Originally Posted by
squidge
So which do you want to use, a database or a file?
Depending on your requirements, it might be worthwhile to look at
QSqLite
I use PostgreSQL(QPSQL) for keeping users data and i want o Authorize them around the application.
tnx squidge
Added after 4 minutes:
Quote:
Originally Posted by
Santosh Reddy
I don't think using QSetting / files is a good idea.
You can create user object and pass it around to dialogs (when creating them) or may be, create a kind of session manager (global), which keeps track of logged in user. All the widgets / dialogs can delegate with session manager for authorization.
First thing came to my mind was that..
But pass the logged user Object around the dialogs i don't thing be good way or in other word best way!
Coz my project have a lot of dialog and actions on database, and i track user actions and keeps Activities history for them..
tnx Santosh
Re: Remember logged user information
then you can create session manager, which will hold the logged in user info, and also act as a gateway to access database. All the dialog can access database only using the session manager, and session manager will return data only if the logged in user is valid..
Re: Remember logged user information
Quote:
Originally Posted by
Santosh Reddy
then you can create session manager, which will hold the logged in user info, and also act as a gateway to access database. All the dialog can access database only using the session manager, and session manager will return data only if the logged in user is valid..
tnx for quick reply!
I don't what you mean exactly about session manager.
Coz even on the web we use file for keeping Sessions data [/tmp]
Of course your idea is acceptable way, But can you add more details about it?
tnx Santosh!
Re: Remember logged user information
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:
Code:
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 ;
}
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.
Re: Remember logged user information
Quote:
Originally Posted by
Santosh Reddy
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.
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.
If i'm wrong you correct me..
With this story, when we need access to user info, shoulda initiale a instance of SessionManager, and it's mean everything will be destroyed, coz this class is in memory!
yeah?
sorry for my persistence behavior!
Re: Remember logged user information
There should be only one instance (Global Instance / Global Variable) of SessionManager, You should not create it at any other time. This is very reason (as I said in my earlier post) SessionManager will an ideal candidate for a Singleton class pattern.
So when you need to access user info you should use the global instance of SessionManager (not create a new one)
Re: Remember logged user information
Yes Singleton Pattern :) !
My bad Santosh, i got it completely.
tnx