00001 #ifndef OPEN_LOGIN_H
00002 #define OPEN_LOGIN_H
00003
00004 #include "cgiCookie.h"
00005 #include "openDB.hpp"
00006 #include "connectstring"
00007 #include "../admin/Affiliate.hpp"
00008 #include "cgiTemplates.h"
00009 #include "Session.hpp"
00010 #include "read_base.hpp"
00011
00012
00016 #define ALT_USER_QUERY "select Id, concat(Last, ', ', First) from mohawk.People where Is_Admin > 0"
00017
00021 class openService
00022 {
00023 public:
00024
00025 string id,cat_name,sequence,tree_depth,menu_name,
00026 uri,xml_params;
00027 string xml_param1;
00028 openService()
00029 {;}
00030 virtual ~openService()
00031 {;}
00032 openService(const openService&in):id(in.id), sequence(in.sequence),
00033 tree_depth(in.tree_depth), cat_name(in.cat_name), menu_name(in.menu_name),
00034 uri(in.uri), xml_params(in.xml_params),xml_param1(xml_params)
00035 {;}
00036 openService & operator = ( const openService & in )
00037 {
00038 id=in.id;
00039 sequence=in.sequence;
00040 tree_depth=in.tree_depth;
00041 cat_name=in.cat_name;
00042 menu_name=in.menu_name;
00043 uri=in.uri;
00044 xml_param1 = xml_params=in.xml_params;
00045 return *this;
00046 }
00047 };
00048 typedef map < string, openService > serviceMap;
00049 typedef vector < string > serviceVector;
00050
00051
00056 class openLogin
00057 {
00058 Affiliate_Obj person;
00059 quickQuery qqry;
00060 openRS & rs;
00061 ocString sql;
00062 protected:
00063
00064
00065 Session_Obj session;
00066
00067
00068 serviceMap services;
00069 serviceVector serviceNames;
00070
00071 void setCookieValue( cgiCookie & cookie, const char * name, string & value )
00072 {
00073 if( value.length() == 0 )
00074 {
00075
00076
00077 string & date = cookie.setTimeout( 1, 1, 1970, 0, 0 );
00078 cookie.set( name, value.c_str() );
00079 date = "";
00080 }
00081 else
00082 {
00083 cookie.set( name, value.c_str() );
00084 }
00085 }
00086
00087 public:
00088 string lastError;
00089 string token;
00090 openLogin():person(),qqry(),rs(qqry.getRS()){;}
00091 ~openLogin(){;}
00092
00093
00094 Session_Obj & Session( void )
00095 {
00096 return session;
00097 }
00098
00099
00100 bool fetchServices( string criteria = "" )
00101 {
00102 bool bRet = false;
00103 bool open = false;
00104
00105
00106 sql = "select distinct s.id, s.cat_name, s.menu_name, s.uri, "
00107 "s.sequence, s.tree_depth, "
00108 "rs.xml_params"
00109 " from services s "
00110 "inner join role_services rs on rs.service_id = s.id "
00111 "inner join roles r on r.id = rs.role_id "
00112 "inner join user_roles ur on ur.role_id = r.id "
00113 "where ur.user_id = ";
00114 sql.append(person.Id);
00115 sql += " and s.enabled = 1";
00116 sql += " and ur.enabled = 1";
00117 sql += " and rs.enabled = 1";
00118
00119
00120 if( criteria.length() )
00121 {
00122 sql += " and ";
00123 sql += criteria;
00124 }
00125
00126 sql += " order by s.sequence, s.tree_depth";
00127
00128 for( open = rs.open(sql); open; open = rs.next() )
00129 {
00130 bRet = true;
00131 openService service;
00132
00133
00134
00135
00136 service.id = rs.getField(0).format();
00137 service.cat_name = rs.getField(1).format();
00138 service.menu_name = rs.getField(2).format();
00139 service.uri = rs.getField(3).format();
00140 service.sequence = rs.getField(4).format();
00141 service.tree_depth = rs.getField(5).format();
00142 service.xml_params = rs.getField(6).format();
00143 string key = service.uri;
00144
00145
00146 if( services.find(key) == services.end() )
00147 {
00148 services.insert(make_pair(key,service));
00149 serviceNames.push_back(key);
00150 }
00151 }
00152 rs.close();
00153 if( !bRet )
00154 {
00155 lastError += " no services for ";
00156 lastError += person.First;
00157 lastError += " ";
00158 lastError += person.Last;
00159 lastError += " are enabled. <!--";
00160 lastError += sql;
00161 lastError += " | ";
00162 lastError += rs.getErrors();
00163 lastError += "-->";
00164 }
00165 return bRet;
00166
00167 }
00168
00169 void signOff( void )
00170 {
00171 cgiCookie cookie;
00172
00173 cookie.setPath("/");
00174 string empty="";
00175 setCookieValue( cookie, "intraToken", empty );
00176 }
00177
00178 bool checkUser( const char * user, const char * password )
00179 {
00180
00181 bool bRet = false;
00182
00183 lastError = "Bad Login / Password combination: ";
00184
00185
00186
00187 cgiCookie cookie;
00188
00189 cookie.setPath("/");
00190
00191 if( user && password && strlen(user) && strlen(password) )
00192 {
00193 string wc = " Email='";
00194 wc += user;
00195 wc += "' and Password='";
00196 wc += password;
00197 wc += "'";
00198
00199 if( person.get_data(wc) && person.Id > 0)
00200 {
00201 ocString sId;
00202 sId.append(person.Id);
00203
00204
00205 setCookieValue( cookie, "intraToken", sId );
00206
00207
00208 lastError = "";
00209
00210 bRet = true;
00211 }
00212 else
00213 {
00214 lastError += " No such user " + wc + " on this site, please try again. ";
00215
00216 }
00217 }
00218 else
00219 {
00220 lastError += " Both the login and password must be entered. ";
00221 }
00222 setCookieValue( cookie, "lastError", lastError );
00223 if( bRet )
00224 {
00226 ocString LoginData = "";
00227 LoginData.append( person.Id );
00228 session.SetData( "Affiliate", LoginData );
00229 if( person.Promotion > 1 )
00230 {
00231 LoginData = "";
00232 LoginData.append( person.Promotion );
00233
00234 session.SetData( "Promotion", LoginData );
00235 }
00236 session.Synch();
00237 }
00238 return bRet;
00239 }
00240
00241 bool testLoginStatus( void )
00242 {
00243 bool bRet = false;
00244 cgiCookie cookie;
00245 string & rId = cookie.get("intraToken");
00246
00247 if( rId.length() > 0 )
00248 {
00249 person.Id=atoll(rId.c_str());
00250 person.key(person.Id);
00251 bRet=person.get_data();
00252
00253 }
00254 return bRet;
00255 }
00256 private:
00257 string m_menu;
00258 public:
00259 string menu ( void )
00260 {
00261
00262
00263
00264
00265
00266
00267
00268
00269
00270
00271
00272 return m_menu;
00273 }
00274
00275
00276 string Id( void )
00277 {
00278 ocString temp;
00279 temp.append(person.Id);
00280 return temp;
00281 }
00282 string myStaff( void )
00283 {
00284
00285 return Id();
00286 }
00287 string & Last( void )
00288 {
00289 return person.Last;
00290 }
00291 string & First( void )
00292 {
00293 return person.First;
00294 }
00295 string & Email ( void )
00296 {
00297 return person.Email;
00298 }
00299 string & PhoneNumber ( void )
00300 {
00301 return person.Phone;
00302 }
00303 string & Login ( void )
00304 {
00305 return person.Email;
00306 }
00307 string & Password ( void )
00308 {
00309 return person.Password;
00310 }
00311 string getSql( void )
00312 {
00313 return "";
00314 }
00315 string getLastError( void )
00316 {
00317 return lastError;
00318 }
00319 string FullName( void )
00320 {
00321 return person.First + " " + person.Last;
00322 }
00323
00324
00325
00326 string GroupId( void )
00327 {
00328 return "";
00329 }
00330 bool SiteAdmin( void )
00331 {
00332 return false;
00333 }
00334
00335
00336 serviceMap & Services( void )
00337 {
00338 return services;
00339 }
00340 serviceVector & ServiceNames( void )
00341 {
00342 return serviceNames;
00343 }
00344
00345 Affiliate_Obj & Person( void )
00346 {
00347 return person;
00348 }
00349
00350
00351 };
00352
00353
00354 #endif