From 51f3a6d5552bc18f8d9ea69cddf30ee7d8f0b6c7 Mon Sep 17 00:00:00 2001 From: hiker Date: Sat, 8 Mar 2014 10:29:40 +1100 Subject: [PATCH] Added static template function to CurrentUser to create html requests, which will prefill the HTML request with the details of the current user. So far used only in online_profile. --- src/online/current_user.hpp | 29 ++++++++++++++++++++++++----- src/online/online_profile.cpp | 13 ++++--------- 2 files changed, 28 insertions(+), 14 deletions(-) diff --git a/src/online/current_user.hpp b/src/online/current_user.hpp index a48882dae..839c1212b 100644 --- a/src/online/current_user.hpp +++ b/src/online/current_user.hpp @@ -19,6 +19,7 @@ #ifndef HEADER_CURRENT_ONLINE_USER_HPP #define HEADER_CURRENT_ONLINE_USER_HPP +#include "online/http_request.hpp" #include "online/request_manager.hpp" #include "online/server.hpp" #include "online/xml_request.hpp" @@ -166,6 +167,18 @@ namespace Online /**Singleton */ static CurrentUser * get(); static void deallocate(); + template + static C* createHTMLRequest() + { + CurrentUser *cu = CurrentUser::get(); + assert(cu->m_state == US_SIGNED_IN); + assert(cu->m_profile); + C *request = new C(); + request->setServerURL("client-user.php"); + request->addParameter("token", cu->m_token); + request->addParameter("userid", cu->m_profile->getID()); + return request; + } // createRequest void requestSavedSession(); SignInRequest * requestSignIn( const irr::core::stringw &username, @@ -205,14 +218,20 @@ namespace Online irr::core::stringw getUserName() const; uint32_t getID() const; + // ---------------------------------------------------------------- /** Returns the user state. */ - const UserState getUserState() const { return m_state; } + const UserState getUserState() const { return m_state; } + // ---------------------------------------------------------------- /** Returns whether a user is signed in or not. */ - bool isRegisteredUser() const { return m_state == US_SIGNED_IN; } + bool isRegisteredUser() const { return m_state == US_SIGNED_IN; } + // ---------------------------------------------------------------- /** Returns the session token of the signed in user. */ - const std::string & getToken() const { return m_token; } - /** Returns a pointer to the profile associated with the current user. */ - OnlineProfile * getProfile() const { return m_profile; } + const std::string& getToken() const { return m_token; } + // ---------------------------------------------------------------- + /** Returns a pointer to the profile associated with the current + * user. */ + OnlineProfile* getProfile() const { return m_profile; } + // ---------------------------------------------------------------- }; // class CurrentUser diff --git a/src/online/online_profile.cpp b/src/online/online_profile.cpp index fa9e1fd37..ac3aee24a 100644 --- a/src/online/online_profile.cpp +++ b/src/online/online_profile.cpp @@ -153,11 +153,9 @@ void OnlineProfile::fetchAchievements() }; // class AchievementsRequest // ------------------------------------------------------------------------ - AchievementsRequest * request = new AchievementsRequest(); - request->setServerURL("client-user.php"); + AchievementsRequest * request = + CurrentUser::createHTMLRequest(); request->addParameter("action", "get-achievements"); - request->addParameter("token", CurrentUser::get()->getToken()); - request->addParameter("userid", CurrentUser::get()->getID()); request->addParameter("visitingid", m_id); RequestManager::get()->addRequest(request); } // fetchAchievements @@ -207,12 +205,9 @@ void OnlineProfile::fetchFriends() } // callback }; // class FriendsListRequest // ------------------------------------------------------------------------ - - FriendsListRequest * request = new FriendsListRequest(); - request->setServerURL("client-user.php"); + FriendsListRequest* request = + CurrentUser::createHTMLRequest(); request->addParameter("action", "get-friends-list"); - request->addParameter("token", CurrentUser::get()->getToken()); - request->addParameter("userid", CurrentUser::get()->getID()); request->addParameter("visitingid", m_id); RequestManager::get()->addRequest(request); } // fetchFriends