TheChess
|
00001 /* 00002 * thechess, chess game web application written in C++ and based on Wt 00003 * Copyright (C) 2010 Boris Nagaev 00004 * 00005 * thechess is licensed under the GNU GPL Version 2. 00006 * Other versions of the GPL do not apply. 00007 * See the LICENSE file for terms of use. 00008 */ 00009 00010 #ifndef THECHESS_MODEL_COOKIESESSION_HPP_ 00011 #define THECHESS_MODEL_COOKIESESSION_HPP_ 00012 00013 #include <string> 00014 00015 #include <Wt/Dbo/Dbo> 00016 #include <Wt/Dbo/ptr> 00017 namespace dbo = Wt::Dbo; 00018 #include <Wt/WDateTime> 00019 #include <Wt/Dbo/WtSqlTraits> 00020 00021 namespace thechess { 00022 namespace model { 00023 class CookieSession; 00024 typedef dbo::ptr<CookieSession> CookieSessionPtr; 00025 typedef dbo::collection<CookieSessionPtr> CookieSessions; 00026 } 00027 } 00028 00029 #include "config.hpp" 00030 #include "model/User.hpp" 00031 00032 namespace thechess { 00033 namespace model { 00034 00035 class CookieSession { 00036 public: 00037 CookieSession(); 00038 CookieSession(const std::string& cookie_id); 00039 00040 template<class Action> 00041 void persist(Action& a) { 00042 dbo::belongsTo(a, user_, "user"); 00043 dbo::id(a, cookie_id_, "cookie_id"); 00044 dbo::field(a, used_, "used"); 00045 } 00046 00047 const std::string& cookie_id() const { 00048 return cookie_id_; 00049 } 00050 00051 UserPtr user() const { 00052 return user_; 00053 } 00054 void set_user(UserPtr user) { 00055 user_ = user; 00056 } 00057 00058 void use() { 00059 used_ = Wt::WDateTime::currentDateTime(); 00060 } 00061 const Wt::WDateTime& used() const { 00062 return used_; 00063 } 00064 00065 private: 00066 UserPtr user_; 00067 std::string cookie_id_; 00068 Wt::WDateTime used_; 00069 }; 00070 00071 } 00072 } 00073 00074 namespace Wt { 00075 namespace Dbo { 00076 00077 template<> 00078 struct dbo_traits<thechess::model::CookieSession> : 00079 public dbo_default_traits { 00080 typedef std::string IdType; 00081 00082 static IdType invalidId() { 00083 return std::string(); 00084 } 00085 00086 static const char *surrogateIdField() { 00087 return 0; 00088 } 00089 }; 00090 00091 } 00092 } 00093 00094 #endif 00095