<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/> <title>Wt examples: /home/koen/project/wt/public-git/wt/examples/hangman/Session.C Source File</title> <link href="tabs.css" rel="stylesheet" type="text/css"/> <link href="doxygen.css" rel="stylesheet" type="text/css" /> </head> <body> <div id="top"><!-- do not remove this div! --> <div id="titlearea"> <table cellspacing="0" cellpadding="0"> <tbody> <tr style="height: 56px;"> <td style="padding-left: 0.5em;"> <div id="projectname">Wt examples  <span id="projectnumber">3.2.3</span> </div> </td> </tr> </tbody> </table> </div> <!-- Generated by Doxygen 1.7.5.1 --> <div id="navrow1" class="tabs"> <ul class="tablist"> <li><a href="index.html"><span>Main Page</span></a></li> <li><a href="modules.html"><span>Modules</span></a></li> <li><a href="namespaces.html"><span>Namespaces</span></a></li> <li><a href="annotated.html"><span>Classes</span></a></li> <li class="current"><a href="files.html"><span>Files</span></a></li> </ul> </div> <div id="navrow2" class="tabs2"> <ul class="tablist"> <li><a href="files.html"><span>File List</span></a></li> <li><a href="globals.html"><span>File Members</span></a></li> </ul> </div> <div class="header"> <div class="headertitle"> <div class="title">/home/koen/project/wt/public-git/wt/examples/hangman/Session.C</div> </div> </div> <div class="contents"> <a href="Session_8C.html">Go to the documentation of this file.</a><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/*</span> <a name="l00002"></a>00002 <span class="comment"> * Copyright (C) 2011 Emweb bvba, Heverlee, Belgium.</span> <a name="l00003"></a>00003 <span class="comment"> *</span> <a name="l00004"></a>00004 <span class="comment"> * See the LICENSE file for terms of use.</span> <a name="l00005"></a>00005 <span class="comment"> */</span> <a name="l00006"></a>00006 <a name="l00007"></a>00007 <span class="preprocessor">#include "<a class="code" href="Session_8h.html">Session.h</a>"</span> <a name="l00008"></a>00008 <a name="l00009"></a>00009 <span class="preprocessor">#include "Wt/Auth/AuthService"</span> <a name="l00010"></a>00010 <span class="preprocessor">#include "Wt/Auth/HashFunction"</span> <a name="l00011"></a>00011 <span class="preprocessor">#include "Wt/Auth/PasswordService"</span> <a name="l00012"></a>00012 <span class="preprocessor">#include "Wt/Auth/PasswordStrengthValidator"</span> <a name="l00013"></a>00013 <span class="preprocessor">#include "Wt/Auth/PasswordVerifier"</span> <a name="l00014"></a>00014 <span class="preprocessor">#include "Wt/Auth/GoogleService"</span> <a name="l00015"></a>00015 <span class="preprocessor">#include "Wt/Auth/Dbo/AuthInfo"</span> <a name="l00016"></a>00016 <span class="preprocessor">#include "Wt/Auth/Dbo/UserDatabase"</span> <a name="l00017"></a>00017 <a name="l00018"></a>00018 <span class="preprocessor">#include <Wt/WApplication></span> <a name="l00019"></a>00019 <span class="preprocessor">#include <<a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/WLogger.html">Wt/WLogger</a>></span> <a name="l00020"></a>00020 <a name="l00021"></a>00021 <span class="preprocessor">#ifndef WIN32</span> <a name="l00022"></a>00022 <span class="preprocessor"></span><span class="preprocessor">#include <unistd.h></span> <a name="l00023"></a>00023 <span class="preprocessor">#endif</span> <a name="l00024"></a>00024 <span class="preprocessor"></span> <a name="l00025"></a>00025 <span class="preprocessor">#if !defined(WIN32) && !defined(__CYGWIN__) && !defined(ANDROID)</span> <a name="l00026"></a><a class="code" href="Session_8C.html#acba86befdbaa214237a79fe6272ea219">00026</a> <span class="preprocessor"></span><span class="preprocessor">#define HAVE_CRYPT</span> <a name="l00027"></a>00027 <span class="preprocessor"></span><span class="preprocessor">#endif</span> <a name="l00028"></a>00028 <span class="preprocessor"></span> <a name="l00029"></a>00029 <span class="keyword">using namespace </span>Wt; <a name="l00030"></a>00030 <span class="keyword">namespace </span>dbo = Wt::Dbo; <a name="l00031"></a>00031 <a name="l00032"></a>00032 <span class="keyword">namespace </span>{ <a name="l00033"></a>00033 <a name="l00034"></a>00034 <span class="preprocessor">#ifdef HAVE_CRYPT</span> <a name="l00035"></a>00035 <span class="preprocessor"></span><span class="keyword">class </span>UnixCryptHashFunction : <span class="keyword">public</span> Auth::HashFunction <a name="l00036"></a>00036 { <a name="l00037"></a>00037 <span class="keyword">public</span>: <a name="l00038"></a>00038 <span class="keyword">virtual</span> std::string compute(<span class="keyword">const</span> std::string& msg, <a name="l00039"></a>00039 <span class="keyword">const</span> std::string& salt)<span class="keyword"> const</span> <a name="l00040"></a>00040 <span class="keyword"> </span>{ <a name="l00041"></a>00041 std::string md5Salt = <span class="stringliteral">"$1$"</span> + salt; <a name="l00042"></a>00042 <span class="keywordflow">return</span> crypt(msg.c_str(), md5Salt.c_str()); <a name="l00043"></a>00043 } <a name="l00044"></a>00044 <a name="l00045"></a>00045 <span class="keyword">virtual</span> <span class="keywordtype">bool</span> verify(<span class="keyword">const</span> std::string& msg, <a name="l00046"></a>00046 <span class="keyword">const</span> std::string& salt, <a name="l00047"></a>00047 <span class="keyword">const</span> std::string& hash)<span class="keyword"> const</span> <a name="l00048"></a>00048 <span class="keyword"> </span>{ <a name="l00049"></a>00049 <span class="keywordflow">return</span> crypt(msg.c_str(), hash.c_str()) == hash; <a name="l00050"></a>00050 } <a name="l00051"></a>00051 <a name="l00052"></a>00052 <span class="keyword">virtual</span> std::string name ()<span class="keyword"> const </span>{ <a name="l00053"></a>00053 <span class="keywordflow">return</span> <span class="stringliteral">"crypt"</span>; <a name="l00054"></a>00054 } <a name="l00055"></a>00055 }; <a name="l00056"></a>00056 <span class="preprocessor">#endif // HAVE_CRYPT</span> <a name="l00057"></a>00057 <span class="preprocessor"></span> <a name="l00058"></a>00058 <span class="keyword">class </span>MyOAuth : <span class="keyword">public</span> std::vector<const Auth::OAuthService *> <a name="l00059"></a>00059 { <a name="l00060"></a>00060 <span class="keyword">public</span>: <a name="l00061"></a>00061 ~MyOAuth() <a name="l00062"></a>00062 { <a name="l00063"></a>00063 <span class="keywordflow">for</span> (<span class="keywordtype">unsigned</span> i = 0; i < size(); ++i) <a name="l00064"></a>00064 <span class="keyword">delete</span> (*<span class="keyword">this</span>)[i]; <a name="l00065"></a>00065 } <a name="l00066"></a>00066 }; <a name="l00067"></a>00067 <a name="l00068"></a>00068 <a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1Auth_1_1AuthService.html">Auth::AuthService</a> myAuthService; <a name="l00069"></a>00069 <a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1Auth_1_1PasswordService.html">Auth::PasswordService</a> myPasswordService(myAuthService); <a name="l00070"></a>00070 MyOAuth myOAuthServices; <a name="l00071"></a>00071 } <a name="l00072"></a>00072 <a name="l00073"></a><a class="code" href="classSession.html#a02ee7e0bfcaf6470f35661ec30b8cf8b">00073</a> <span class="keywordtype">void</span> <a class="code" href="classSession.html#a02ee7e0bfcaf6470f35661ec30b8cf8b">Session::configureAuth</a>() <a name="l00074"></a>00074 { <a name="l00075"></a>00075 myAuthService.setAuthTokensEnabled(<span class="keyword">true</span>, <span class="stringliteral">"hangmancookie"</span>); <a name="l00076"></a>00076 myAuthService.setEmailVerificationEnabled(<span class="keyword">true</span>); <a name="l00077"></a>00077 <a name="l00078"></a>00078 <a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1Auth_1_1PasswordVerifier.html">Auth::PasswordVerifier</a> *verifier = <span class="keyword">new</span> <a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1Auth_1_1PasswordVerifier.html">Auth::PasswordVerifier</a>(); <a name="l00079"></a>00079 verifier-><a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1Auth_1_1PasswordVerifier.html#ae96fed853a42e5048bed6a5f01ca4f52">addHashFunction</a>(<span class="keyword">new</span> <a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1Auth_1_1BCryptHashFunction.html">Auth::BCryptHashFunction</a>(7)); <a name="l00080"></a>00080 <a name="l00081"></a>00081 <span class="preprocessor">#ifdef HAVE_CRYPT</span> <a name="l00082"></a>00082 <span class="preprocessor"></span> <span class="comment">// We want to still support users registered in the pre - Wt::Auth</span> <a name="l00083"></a>00083 <span class="comment">// version of the hangman example</span> <a name="l00084"></a>00084 verifier-><a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1Auth_1_1PasswordVerifier.html#ae96fed853a42e5048bed6a5f01ca4f52">addHashFunction</a>(<span class="keyword">new</span> UnixCryptHashFunction()); <a name="l00085"></a>00085 <span class="preprocessor">#endif</span> <a name="l00086"></a>00086 <span class="preprocessor"></span> <a name="l00087"></a>00087 myPasswordService.setVerifier(verifier); <a name="l00088"></a>00088 myPasswordService.setStrengthValidator(<span class="keyword">new</span> <a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1Auth_1_1PasswordStrengthValidator.html">Auth::PasswordStrengthValidator</a>()); <a name="l00089"></a>00089 myPasswordService.setAttemptThrottlingEnabled(<span class="keyword">true</span>); <a name="l00090"></a>00090 <a name="l00091"></a>00091 <span class="keywordflow">if</span> (<a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1Auth_1_1GoogleService.html#ab9b1a1d09831fc92a8fdbef39de4899e">Auth::GoogleService::configured</a>()) <a name="l00092"></a>00092 myOAuthServices.push_back(<span class="keyword">new</span> <a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1Auth_1_1GoogleService.html">Auth::GoogleService</a>(myAuthService)); <a name="l00093"></a>00093 } <a name="l00094"></a>00094 <a name="l00095"></a><a class="code" href="classSession.html#ad92ef09b872c9227e38a6efdd4d8a837">00095</a> <a class="code" href="classSession.html#ad92ef09b872c9227e38a6efdd4d8a837">Session::Session</a>() <a name="l00096"></a>00096 : sqlite3_(<a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WApplication.html">WApplication</a>::instance()->appRoot() + <span class="stringliteral">"hangman.db"</span>) <a name="l00097"></a>00097 { <a name="l00098"></a>00098 <a class="code" href="classSession.html#a7de9be5226d297784ae26a79a1267ac2">session_</a>.<a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1Dbo_1_1Session.html#aedcc21944ce9c2bbb2fe2b5ef1860776">setConnection</a>(<a class="code" href="classSession.html#a15a7b5a56a15bff8eed8cf98c87abcd3">sqlite3_</a>); <a name="l00099"></a>00099 <a class="code" href="classSession.html#a15a7b5a56a15bff8eed8cf98c87abcd3">sqlite3_</a>.setProperty(<span class="stringliteral">"show-queries"</span>, <span class="stringliteral">"true"</span>); <a name="l00100"></a>00100 <a name="l00101"></a>00101 <a class="code" href="classSession.html#a7de9be5226d297784ae26a79a1267ac2">session_</a>.<a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1Dbo_1_1Session.html#a22b4750b2665de1381b1fedec7020c75">mapClass</a><<a class="code" href="classUser.html">User</a>>(<span class="stringliteral">"user"</span>); <a name="l00102"></a>00102 <a class="code" href="classSession.html#a7de9be5226d297784ae26a79a1267ac2">session_</a>.<a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1Dbo_1_1Session.html#a22b4750b2665de1381b1fedec7020c75">mapClass</a><<a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1Auth_1_1Dbo_1_1AuthInfo.html">AuthInfo</a>>(<span class="stringliteral">"auth_info"</span>); <a name="l00103"></a>00103 <a class="code" href="classSession.html#a7de9be5226d297784ae26a79a1267ac2">session_</a>.<a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1Dbo_1_1Session.html#a22b4750b2665de1381b1fedec7020c75">mapClass</a><<a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1Auth_1_1Dbo_1_1AuthInfo.html#a100cd93e291e2ff801070aebd9d2941d">AuthInfo::AuthIdentityType</a>>(<span class="stringliteral">"auth_identity"</span>); <a name="l00104"></a>00104 <a class="code" href="classSession.html#a7de9be5226d297784ae26a79a1267ac2">session_</a>.<a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1Dbo_1_1Session.html#a22b4750b2665de1381b1fedec7020c75">mapClass</a><<a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1Auth_1_1Dbo_1_1AuthInfo.html#a58fefb577610dae54b4597ee014e92c1">AuthInfo::AuthTokenType</a>>(<span class="stringliteral">"auth_token"</span>); <a name="l00105"></a>00105 <a name="l00106"></a>00106 <a class="code" href="classSession.html#a791c538e6bb5214c72b974329c419274">users_</a> = <span class="keyword">new</span> <a class="code" href="Session_8h.html#a34c01062ebe1a5567ef968ff473f0354">UserDatabase</a>(<a class="code" href="classSession.html#a7de9be5226d297784ae26a79a1267ac2">session_</a>); <a name="l00107"></a>00107 <a name="l00108"></a>00108 <a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1Dbo_1_1Transaction.html">dbo::Transaction</a> transaction(<a class="code" href="classSession.html#a7de9be5226d297784ae26a79a1267ac2">session_</a>); <a name="l00109"></a>00109 <span class="keywordflow">try</span> { <a name="l00110"></a>00110 <a class="code" href="classSession.html#a7de9be5226d297784ae26a79a1267ac2">session_</a>.<a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1Dbo_1_1Session.html#aba79d84c7c91faae06f954e6d3d390ab">createTables</a>(); <a name="l00111"></a>00111 <a name="l00112"></a>00112 <span class="comment">/*</span> <a name="l00113"></a>00113 <span class="comment"> * Add a default guest/guest account</span> <a name="l00114"></a>00114 <span class="comment"> */</span> <a name="l00115"></a>00115 <a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1Auth_1_1User.html">Auth::User</a> guestUser = users_->registerNew(); <a name="l00116"></a>00116 guestUser.<a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1Auth_1_1User.html#a373651abdd3454d64dc634bbae53ceec">addIdentity</a>(Auth::Identity::LoginName, <span class="stringliteral">"guest"</span>); <a name="l00117"></a>00117 myPasswordService.updatePassword(guestUser, <span class="stringliteral">"guest"</span>); <a name="l00118"></a>00118 <a name="l00119"></a>00119 Wt::log(<span class="stringliteral">"info"</span>) << <span class="stringliteral">"Database created"</span>; <a name="l00120"></a>00120 } <span class="keywordflow">catch</span> (...) { <a name="l00121"></a>00121 Wt::log(<span class="stringliteral">"info"</span>) << <span class="stringliteral">"Using existing database"</span>; <a name="l00122"></a>00122 } <a name="l00123"></a>00123 <a name="l00124"></a>00124 transaction.<a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1Dbo_1_1Transaction.html#a76e109abb03f00cf3ba5a5c6d84529a5">commit</a>(); <a name="l00125"></a>00125 } <a name="l00126"></a>00126 <a name="l00127"></a><a class="code" href="classSession.html#a8753bb9dee966b7d39abc9b7237cd665">00127</a> <a class="code" href="classSession.html#a8753bb9dee966b7d39abc9b7237cd665">Session::~Session</a>() <a name="l00128"></a>00128 { <a name="l00129"></a>00129 <span class="keyword">delete</span> <a class="code" href="classSession.html#a791c538e6bb5214c72b974329c419274">users_</a>; <a name="l00130"></a>00130 } <a name="l00131"></a>00131 <a name="l00132"></a><a class="code" href="classSession.html#ac6e911217514b2714d6d2df86aee9bf7">00132</a> <a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1Dbo_1_1ptr.html">dbo::ptr<User></a> <a class="code" href="classSession.html#ac6e911217514b2714d6d2df86aee9bf7">Session::user</a>()<span class="keyword"> const</span> <a name="l00133"></a>00133 <span class="keyword"></span>{ <a name="l00134"></a>00134 <span class="keywordflow">if</span> (<a class="code" href="classSession.html#a71e5966d537785ddec69daeb7f203dd5">login_</a>.<a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1Auth_1_1Login.html#aece418e93d9e9b3ad5a783225cece9cc">loggedIn</a>()) { <a name="l00135"></a>00135 <a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1Dbo_1_1ptr.html">dbo::ptr<AuthInfo></a> authInfo = <a class="code" href="classSession.html#a791c538e6bb5214c72b974329c419274">users_</a>-><a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1Auth_1_1Dbo_1_1UserDatabase.html#a061113cf6fe3f05cd26a47a853f1a71c">find</a>(<a class="code" href="classSession.html#a71e5966d537785ddec69daeb7f203dd5">login_</a>.<a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1Auth_1_1Login.html#a41667e44dc8a3a5aa95fd38f28b11571">user</a>()); <a name="l00136"></a>00136 <a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1Dbo_1_1ptr.html">dbo::ptr<User></a> <a class="code" href="classSession.html#ac6e911217514b2714d6d2df86aee9bf7">user</a> = authInfo->user(); <a name="l00137"></a>00137 <a name="l00138"></a>00138 <span class="keywordflow">if</span> (!user) { <a name="l00139"></a>00139 user = <a class="code" href="classSession.html#a7de9be5226d297784ae26a79a1267ac2">session_</a>.<a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1Dbo_1_1Session.html#abfbd5bea3a6b964e833c893434e38c8f">add</a>(<span class="keyword">new</span> <a class="code" href="classUser.html">User</a>()); <a name="l00140"></a>00140 authInfo.<a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1Dbo_1_1ptr.html#ac14d20e52b5cd9eee356488c7416c044">modify</a>()-><a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1Auth_1_1Dbo_1_1AuthInfo.html#a59f5bec40360c29e58cc9768a34c3b17">setUser</a>(user); <a name="l00141"></a>00141 } <a name="l00142"></a>00142 <a name="l00143"></a>00143 <span class="keywordflow">return</span> <a class="code" href="classSession.html#ac6e911217514b2714d6d2df86aee9bf7">user</a>; <a name="l00144"></a>00144 } <span class="keywordflow">else</span> <a name="l00145"></a>00145 <span class="keywordflow">return</span> <a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1Dbo_1_1ptr.html">dbo::ptr<User></a>(); <a name="l00146"></a>00146 } <a name="l00147"></a>00147 <a name="l00148"></a><a class="code" href="classSession.html#a4e3ae70e1af1b975bb0cb11c48f8d0a0">00148</a> std::string <a class="code" href="classSession.html#a4e3ae70e1af1b975bb0cb11c48f8d0a0">Session::userName</a>()<span class="keyword"> const</span> <a name="l00149"></a>00149 <span class="keyword"></span>{ <a name="l00150"></a>00150 <span class="keywordflow">if</span> (<a class="code" href="classSession.html#a71e5966d537785ddec69daeb7f203dd5">login_</a>.<a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1Auth_1_1Login.html#aece418e93d9e9b3ad5a783225cece9cc">loggedIn</a>()) <a name="l00151"></a>00151 <span class="keywordflow">return</span> <a class="code" href="classSession.html#a71e5966d537785ddec69daeb7f203dd5">login_</a>.<a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1Auth_1_1Login.html#a41667e44dc8a3a5aa95fd38f28b11571">user</a>().identity(Auth::Identity::LoginName).toUTF8(); <a name="l00152"></a>00152 <span class="keywordflow">else</span> <a name="l00153"></a>00153 <span class="keywordflow">return</span> std::string(); <a name="l00154"></a>00154 } <a name="l00155"></a>00155 <a name="l00156"></a><a class="code" href="classSession.html#aff01ac09a8746ee949eab4e5e0c3885f">00156</a> <span class="keywordtype">void</span> <a class="code" href="classSession.html#aff01ac09a8746ee949eab4e5e0c3885f">Session::addToScore</a>(<span class="keywordtype">int</span> s) <a name="l00157"></a>00157 { <a name="l00158"></a>00158 <a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1Dbo_1_1Transaction.html">dbo::Transaction</a> transaction(<a class="code" href="classSession.html#a7de9be5226d297784ae26a79a1267ac2">session_</a>); <a name="l00159"></a>00159 <a name="l00160"></a>00160 <a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1Dbo_1_1ptr.html">dbo::ptr<User></a> u = <a class="code" href="classSession.html#ac6e911217514b2714d6d2df86aee9bf7">user</a>(); <a name="l00161"></a>00161 <span class="keywordflow">if</span> (u) { <a name="l00162"></a>00162 u.<a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1Dbo_1_1ptr.html#ac14d20e52b5cd9eee356488c7416c044">modify</a>()-><a class="code" href="classUser.html#a11ea6cb2854e33cf589845b12a45f030">score</a> += s; <a name="l00163"></a>00163 ++u.<a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1Dbo_1_1ptr.html#ac14d20e52b5cd9eee356488c7416c044">modify</a>()-><a class="code" href="classUser.html#aaa8e742ce006044c85caa7e25925e52c">gamesPlayed</a>; <a name="l00164"></a>00164 u.<a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1Dbo_1_1ptr.html#ac14d20e52b5cd9eee356488c7416c044">modify</a>()-><a class="code" href="classUser.html#a62c89b6c10a83e2c8ee87c9d2f819ce4">lastGame</a> = WDateTime::currentDateTime(); <a name="l00165"></a>00165 } <a name="l00166"></a>00166 <a name="l00167"></a>00167 transaction.<a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1Dbo_1_1Transaction.html#a76e109abb03f00cf3ba5a5c6d84529a5">commit</a>(); <a name="l00168"></a>00168 } <a name="l00169"></a>00169 <a name="l00170"></a><a class="code" href="classSession.html#a4b155f290b6613f0924855b55adea325">00170</a> std::vector<User> <a class="code" href="classSession.html#a4b155f290b6613f0924855b55adea325">Session::topUsers</a>(<span class="keywordtype">int</span> limit) <a name="l00171"></a>00171 { <a name="l00172"></a>00172 <a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1Dbo_1_1Transaction.html">dbo::Transaction</a> transaction(<a class="code" href="classSession.html#a7de9be5226d297784ae26a79a1267ac2">session_</a>); <a name="l00173"></a>00173 <a name="l00174"></a>00174 <a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1Dbo_1_1collection.html">Users</a> top = <a class="code" href="classSession.html#a7de9be5226d297784ae26a79a1267ac2">session_</a>.<a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1Dbo_1_1Session.html#a1a9aff98561cd85ee82a11a57e1e7a74">find</a><<a class="code" href="classUser.html">User</a>>().orderBy(<span class="stringliteral">"score desc"</span>).limit(20); <a name="l00175"></a>00175 <a name="l00176"></a>00176 std::vector<User> result; <a name="l00177"></a>00177 <span class="keywordflow">for</span> (<a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1Dbo_1_1collection_1_1const__iterator.html">Users::const_iterator</a> i = top.<a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1Dbo_1_1collection.html#a34580ef0194da3b8366182fbbc3b4c49">begin</a>(); i != top.<a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1Dbo_1_1collection.html#a4a6f1178ce470936900f269a9ccf97de">end</a>(); ++i) { <a name="l00178"></a>00178 <a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1Dbo_1_1ptr.html">dbo::ptr<User></a> <a class="code" href="classSession.html#ac6e911217514b2714d6d2df86aee9bf7">user</a> = *i; <a name="l00179"></a>00179 result.push_back(*user); <a name="l00180"></a>00180 <a name="l00181"></a>00181 <a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1Dbo_1_1ptr.html">dbo::ptr<AuthInfo></a> <a class="code" href="classSession.html#a7fe071d1b3aee64cdf9f3601cdeb42fb">auth</a> = *user->authInfos.begin(); <a name="l00182"></a>00182 std::string name = auth->identity(Auth::Identity::LoginName).toUTF8(); <a name="l00183"></a>00183 <a name="l00184"></a>00184 result.back().name = name; <a name="l00185"></a>00185 } <a name="l00186"></a>00186 <a name="l00187"></a>00187 transaction.<a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1Dbo_1_1Transaction.html#a76e109abb03f00cf3ba5a5c6d84529a5">commit</a>(); <a name="l00188"></a>00188 <a name="l00189"></a>00189 <span class="keywordflow">return</span> result; <a name="l00190"></a>00190 } <a name="l00191"></a>00191 <a name="l00192"></a><a class="code" href="classSession.html#a9e2412b2aab36466b71ddf94d509d7b9">00192</a> <span class="keywordtype">int</span> <a class="code" href="classSession.html#a9e2412b2aab36466b71ddf94d509d7b9">Session::findRanking</a>() <a name="l00193"></a>00193 { <a name="l00194"></a>00194 <a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1Dbo_1_1Transaction.html">dbo::Transaction</a> transaction(<a class="code" href="classSession.html#a7de9be5226d297784ae26a79a1267ac2">session_</a>); <a name="l00195"></a>00195 <a name="l00196"></a>00196 <a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1Dbo_1_1ptr.html">dbo::ptr<User></a> u = <a class="code" href="classSession.html#ac6e911217514b2714d6d2df86aee9bf7">user</a>(); <a name="l00197"></a>00197 <span class="keywordtype">int</span> ranking = -1; <a name="l00198"></a>00198 <a name="l00199"></a>00199 <span class="keywordflow">if</span> (u) <a name="l00200"></a>00200 ranking = <a class="code" href="classSession.html#a7de9be5226d297784ae26a79a1267ac2">session_</a>.<a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1Dbo_1_1Session.html#a8cad70bef9cffd6613107d5cd3aeb16a">query</a><<span class="keywordtype">int</span>>(<span class="stringliteral">"select distinct count(score) from user"</span>) <a name="l00201"></a>00201 .where(<span class="stringliteral">"score > ?"</span>).bind(u->score); <a name="l00202"></a>00202 <a name="l00203"></a>00203 transaction.<a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1Dbo_1_1Transaction.html#a76e109abb03f00cf3ba5a5c6d84529a5">commit</a>(); <a name="l00204"></a>00204 <a name="l00205"></a>00205 <span class="keywordflow">return</span> ranking + 1; <a name="l00206"></a>00206 } <a name="l00207"></a>00207 <a name="l00208"></a><a class="code" href="classSession.html#af91c8b22a14acf05e46265698deb8af4">00208</a> <a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1Auth_1_1AbstractUserDatabase.html">Auth::AbstractUserDatabase</a>& <a class="code" href="classSession.html#af91c8b22a14acf05e46265698deb8af4">Session::users</a>() <a name="l00209"></a>00209 { <a name="l00210"></a>00210 <span class="keywordflow">return</span> *<a class="code" href="classSession.html#a791c538e6bb5214c72b974329c419274">users_</a>; <a name="l00211"></a>00211 } <a name="l00212"></a>00212 <a name="l00213"></a><a class="code" href="classSession.html#a7fe071d1b3aee64cdf9f3601cdeb42fb">00213</a> <span class="keyword">const</span> <a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1Auth_1_1AuthService.html">Auth::AuthService</a>& <a class="code" href="classSession.html#a7fe071d1b3aee64cdf9f3601cdeb42fb">Session::auth</a>() <a name="l00214"></a>00214 { <a name="l00215"></a>00215 <span class="keywordflow">return</span> myAuthService; <a name="l00216"></a>00216 } <a name="l00217"></a>00217 <a name="l00218"></a><a class="code" href="classSession.html#a06fdfd453428ecbe0e1cce81470bca69">00218</a> <span class="keyword">const</span> <a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1Auth_1_1AbstractPasswordService.html">Auth::AbstractPasswordService</a>& <a class="code" href="classSession.html#a06fdfd453428ecbe0e1cce81470bca69">Session::passwordAuth</a>() <a name="l00219"></a>00219 { <a name="l00220"></a>00220 <span class="keywordflow">return</span> myPasswordService; <a name="l00221"></a>00221 } <a name="l00222"></a>00222 <a name="l00223"></a><a class="code" href="classSession.html#a22252a55fec95eec790ca74ce9559a54">00223</a> <span class="keyword">const</span> std::vector<const Auth::OAuthService *>& <a class="code" href="classSession.html#a22252a55fec95eec790ca74ce9559a54">Session::oAuth</a>() <a name="l00224"></a>00224 { <a name="l00225"></a>00225 <span class="keywordflow">return</span> myOAuthServices; <a name="l00226"></a>00226 } </pre></div></div> </div> <hr size="1"><address style="text-align: right; margin: 3px"><small> Generated on Thu Nov 1 2012 for <a href="http://www.webtoolkit.eu/wt">the C++ Web Toolkit (Wt)</a> by <a href="http://www.doxygen.org/index.html"><img src="doxygen.png" alt="doxygen" border="0" style="vertical-align: middle; display: inline-block; height: 2em"></a> 1.7.5.1</small></address> </body> </html>