SessionManager.cpp 604 B

12345678910111213141516171819202122232425
  1. #include <libdevcore/Base64.h>
  2. #include "SessionManager.h"
  3. using namespace std;
  4. using namespace dev;
  5. using namespace dev::rpc;
  6. std::string SessionManager::newSession(SessionPermissions const& _p)
  7. {
  8. std::string s = toBase64(h64::random().ref());
  9. m_sessions[s] = _p;
  10. return s;
  11. }
  12. void SessionManager::addSession(std::string const& _session, SessionPermissions const& _p)
  13. {
  14. m_sessions[_session] = _p;
  15. }
  16. bool SessionManager::hasPrivilegeLevel(std::string const& _session, Privilege _l) const
  17. {
  18. auto it = m_sessions.find(_session);
  19. return it != m_sessions.end() && it->second.privileges.count(_l);
  20. }