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.
This commit is contained in:
parent
809cb27d89
commit
51f3a6d555
@ -19,6 +19,7 @@
|
|||||||
#ifndef HEADER_CURRENT_ONLINE_USER_HPP
|
#ifndef HEADER_CURRENT_ONLINE_USER_HPP
|
||||||
#define HEADER_CURRENT_ONLINE_USER_HPP
|
#define HEADER_CURRENT_ONLINE_USER_HPP
|
||||||
|
|
||||||
|
#include "online/http_request.hpp"
|
||||||
#include "online/request_manager.hpp"
|
#include "online/request_manager.hpp"
|
||||||
#include "online/server.hpp"
|
#include "online/server.hpp"
|
||||||
#include "online/xml_request.hpp"
|
#include "online/xml_request.hpp"
|
||||||
@ -166,6 +167,18 @@ namespace Online
|
|||||||
/**Singleton */
|
/**Singleton */
|
||||||
static CurrentUser * get();
|
static CurrentUser * get();
|
||||||
static void deallocate();
|
static void deallocate();
|
||||||
|
template <class C>
|
||||||
|
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();
|
void requestSavedSession();
|
||||||
SignInRequest * requestSignIn( const irr::core::stringw &username,
|
SignInRequest * requestSignIn( const irr::core::stringw &username,
|
||||||
@ -205,14 +218,20 @@ namespace Online
|
|||||||
|
|
||||||
irr::core::stringw getUserName() const;
|
irr::core::stringw getUserName() const;
|
||||||
uint32_t getID() const;
|
uint32_t getID() const;
|
||||||
|
// ----------------------------------------------------------------
|
||||||
/** Returns the user state. */
|
/** 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. */
|
/** 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. */
|
/** Returns the session token of the signed in user. */
|
||||||
const std::string & getToken() const { return m_token; }
|
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; }
|
/** Returns a pointer to the profile associated with the current
|
||||||
|
* user. */
|
||||||
|
OnlineProfile* getProfile() const { return m_profile; }
|
||||||
|
// ----------------------------------------------------------------
|
||||||
|
|
||||||
}; // class CurrentUser
|
}; // class CurrentUser
|
||||||
|
|
||||||
|
@ -153,11 +153,9 @@ void OnlineProfile::fetchAchievements()
|
|||||||
}; // class AchievementsRequest
|
}; // class AchievementsRequest
|
||||||
// ------------------------------------------------------------------------
|
// ------------------------------------------------------------------------
|
||||||
|
|
||||||
AchievementsRequest * request = new AchievementsRequest();
|
AchievementsRequest * request =
|
||||||
request->setServerURL("client-user.php");
|
CurrentUser::createHTMLRequest<AchievementsRequest>();
|
||||||
request->addParameter("action", "get-achievements");
|
request->addParameter("action", "get-achievements");
|
||||||
request->addParameter("token", CurrentUser::get()->getToken());
|
|
||||||
request->addParameter("userid", CurrentUser::get()->getID());
|
|
||||||
request->addParameter("visitingid", m_id);
|
request->addParameter("visitingid", m_id);
|
||||||
RequestManager::get()->addRequest(request);
|
RequestManager::get()->addRequest(request);
|
||||||
} // fetchAchievements
|
} // fetchAchievements
|
||||||
@ -207,12 +205,9 @@ void OnlineProfile::fetchFriends()
|
|||||||
} // callback
|
} // callback
|
||||||
}; // class FriendsListRequest
|
}; // class FriendsListRequest
|
||||||
// ------------------------------------------------------------------------
|
// ------------------------------------------------------------------------
|
||||||
|
FriendsListRequest* request =
|
||||||
FriendsListRequest * request = new FriendsListRequest();
|
CurrentUser::createHTMLRequest<FriendsListRequest>();
|
||||||
request->setServerURL("client-user.php");
|
|
||||||
request->addParameter("action", "get-friends-list");
|
request->addParameter("action", "get-friends-list");
|
||||||
request->addParameter("token", CurrentUser::get()->getToken());
|
|
||||||
request->addParameter("userid", CurrentUser::get()->getID());
|
|
||||||
request->addParameter("visitingid", m_id);
|
request->addParameter("visitingid", m_id);
|
||||||
RequestManager::get()->addRequest(request);
|
RequestManager::get()->addRequest(request);
|
||||||
} // fetchFriends
|
} // fetchFriends
|
||||||
|
Loading…
Reference in New Issue
Block a user