generated from Sithas/conan_template
Перепись с const std::string& на std::string_view
This commit is contained in:
+5
-5
@@ -11,14 +11,14 @@ class IAuthDAO
|
||||
{
|
||||
public:
|
||||
virtual std::string Login(
|
||||
const std::string& registrated_user_uuid,
|
||||
const std::string& auth_token) = 0;
|
||||
std::string_view registrated_user_uuid,
|
||||
std::string_view auth_token) = 0;
|
||||
|
||||
virtual bool HasAuthorized(const std::string& auth_token) = 0;
|
||||
virtual bool HasAuthorized(std::string_view auth_token) = 0;
|
||||
|
||||
virtual std::string_view GetUUID(const std::string& auth_token) = 0;
|
||||
virtual std::string_view GetUUID(std::string_view auth_token) = 0;
|
||||
|
||||
virtual bool Logout(const std::string& user_token) = 0;
|
||||
virtual bool Logout(std::string_view user_token) = 0;
|
||||
|
||||
virtual ~IAuthDAO() = default;
|
||||
};
|
||||
|
||||
+12
-12
@@ -11,33 +11,33 @@ MemoryAuthDAO::MemoryAuthDAO(mysqlx::Session& session): session_(session)
|
||||
}
|
||||
|
||||
std::string MemoryAuthDAO::Login(
|
||||
const std::string& registrated_user_uuid,
|
||||
const std::string& auth_token)
|
||||
std::string_view registrated_user_uuid,
|
||||
std::string_view auth_token)
|
||||
{
|
||||
users_uuids_to_auth_tokens_[registrated_user_uuid] = auth_token;
|
||||
auth_tokens_to_users_uuids_[auth_token] = registrated_user_uuid;
|
||||
users_uuids_to_auth_tokens_[registrated_user_uuid.data()] = auth_token;
|
||||
auth_tokens_to_users_uuids_[auth_token.data()] = registrated_user_uuid;
|
||||
|
||||
return auth_token;
|
||||
return auth_token.data();
|
||||
}
|
||||
|
||||
bool MemoryAuthDAO::HasAuthorized(const std::string& auth_token)
|
||||
bool MemoryAuthDAO::HasAuthorized(std::string_view auth_token)
|
||||
{
|
||||
return auth_tokens_to_users_uuids_.count(auth_token) > 0;
|
||||
return auth_tokens_to_users_uuids_.count(auth_token.data()) > 0;
|
||||
}
|
||||
|
||||
std::string_view MemoryAuthDAO::GetUUID(const std::string& auth_token)
|
||||
std::string_view MemoryAuthDAO::GetUUID(std::string_view auth_token)
|
||||
{
|
||||
return auth_tokens_to_users_uuids_.at(auth_token);
|
||||
return auth_tokens_to_users_uuids_.at(auth_token.data());
|
||||
}
|
||||
|
||||
bool MemoryAuthDAO::Logout(const std::string& auth_token)
|
||||
bool MemoryAuthDAO::Logout(std::string_view auth_token)
|
||||
{
|
||||
if (!HasAuthorized(auth_token)) return false;
|
||||
|
||||
string user_uuid = auth_tokens_to_users_uuids_[auth_token];
|
||||
string user_uuid = auth_tokens_to_users_uuids_[auth_token.data()];
|
||||
|
||||
users_uuids_to_auth_tokens_.erase(user_uuid);
|
||||
auth_tokens_to_users_uuids_.erase(auth_token);
|
||||
auth_tokens_to_users_uuids_.erase(auth_token.data());
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -20,13 +20,13 @@ public:
|
||||
explicit MemoryAuthDAO(mysqlx::Session& session);
|
||||
|
||||
std::string Login(
|
||||
const std::string& registrated_user_uuid,
|
||||
const std::string& auth_token) override;
|
||||
std::string_view registrated_user_uuid,
|
||||
std::string_view auth_token) override;
|
||||
|
||||
bool HasAuthorized(const std::string& auth_token) override;
|
||||
bool HasAuthorized(std::string_view auth_token) override;
|
||||
|
||||
std::string_view GetUUID(const std::string& auth_token) override;
|
||||
std::string_view GetUUID(std::string_view auth_token) override;
|
||||
|
||||
bool Logout(const std::string& auth_token) override;
|
||||
bool Logout(std::string_view auth_token) override;
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user