Wittyshare  0.2
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
WsUserSession.cpp
Go to the documentation of this file.
1 /*
2  *
3  * Filename: WsUserSession.cpp
4  *
5  * Description:
6  *
7  * Created: 03/21/2013 01:47:11 AM
8  * Revision: none
9  *
10  * Author: Benoit Daccache (BD), ben.daccache@gmail.com
11  * Company:
12  *
13  */
14 
15 #include "WsUserSession.h"
16 #include <sys/time.h>
17 using namespace std;
18 
19 WsUserSession::WsUserSession(const string& uid, const string& pass, const string& ip):
20  m_uid(uid),
21  m_pass(pass),
22  m_ip(ip)
23 {
25 }
26 
27 const set<string>& WsUserSession::getGroups()
28 {
29  return m_groups;
30 }
31 
32 void WsUserSession::setGroups(const set<string>& groups)
33 {
34  m_groups = groups;
35 }
36 
37 bool WsUserSession::isValidSession(const string& uid, const string& pass, const string& ip)
38 {
39  if ( m_uid == uid && m_pass == pass && m_ip == ip)
40  return getNowTimestamp() - m_timestamp <= 14400000; //Session is valid for 4 hours
41  return false;
42 }
43 
45 {
46  timeval time;
47  gettimeofday(&time, 0);
48  long millis = (time.tv_sec * 1000) + (time.tv_usec / 1000);
49  return millis;
50 }
51 
52 const string& WsUserSession::getName()
53 {
54  return m_name;
55 }
56 
58 {
59  return m_surname;
60 }
61 
62 const string& WsUserSession::getEmail()
63 {
64  return m_email;
65 }
66 
67 void WsUserSession::setName(const string& name)
68 {
69  m_name = name;
70 }
71 
72 void WsUserSession::setSurname(const string& name)
73 {
74  m_surname = name;
75 }
76 
77 void WsUserSession::setEmail(const string& email)
78 {
79  m_email = email;
80 }
void setSurname(const std::string &surname)
set the surname of the user
std::string m_name
Definition: WsUserSession.h:96
void setName(const std::string &name)
set the name of the user
const std::string & getName()
void setGroups(const std::set< std::string > &groups)
sets the groups of a user
std::set< std::string > m_groups
Definition: WsUserSession.h:99
WsUserSession(const std::string &uid, const std::string &pass="", const std::string &ip="")
Constructor.
const std::string & getEmail()
std::string m_surname
Definition: WsUserSession.h:97
void setEmail(const std::string &email)
set the email of the user
std::string m_uid
Definition: WsUserSession.h:93
std::string m_ip
Definition: WsUserSession.h:95
std::string m_email
Definition: WsUserSession.h:98
const std::set< std::string > & getGroups()
get the groups belonging to the user
const std::string & getSurname()
long getNowTimestamp()
returns the time.now()
std::string m_pass
Definition: WsUserSession.h:94
bool isValidSession(const std::string &uid, const std::string &pass, const std::string &ip)
returns true or false whether the session is valid