Skip to content

Commit

Permalink
fix: login with account name on old protocol (11.00)
Browse files Browse the repository at this point in the history
  • Loading branch information
dudantas committed Oct 26, 2023
1 parent 49de5d6 commit 55ed7c3
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/account/account.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ namespace account {
return ERROR_NO;
}

if (!m_descriptor.empty() && accountRepository.loadByEmail(m_descriptor, m_account)) {
if (!m_descriptor.empty() && accountRepository.loadByEmailOrName(getProtocolCompat(), m_descriptor, m_account)) {
m_accLoaded = true;
return ERROR_NO;
}
Expand Down
2 changes: 1 addition & 1 deletion src/account/account_repository.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ namespace account {
virtual ~AccountRepository() = default;

virtual bool loadByID(const uint32_t &id, AccountInfo &acc) = 0;
virtual bool loadByEmail(const std::string &email, AccountInfo &acc) = 0;
virtual bool loadByEmailOrName(bool oldProtocol, const std::string &emailOrName, AccountInfo &acc) = 0;
virtual bool loadBySession(const std::string &email, AccountInfo &acc) = 0;
virtual bool save(const AccountInfo &accInfo) = 0;

Expand Down
5 changes: 3 additions & 2 deletions src/account/account_repository_db.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@ namespace account {
return load(query, acc);
};

bool AccountRepositoryDB::loadByEmail(const std::string &email, AccountInfo &acc) {
auto query = fmt::format("SELECT `id`, `type`, `premdays`, `lastday`, `creation`, `premdays_purchased`, 0 AS `expires` FROM `accounts` WHERE `email` = {}", db.escapeString(email));
bool AccountRepositoryDB::loadByEmailOrName(bool oldProtocol, const std::string &emailOrName, AccountInfo &acc) {
auto identifier = oldProtocol ? "name" : "email";
auto query = fmt::format("SELECT `id`, `type`, `premdays`, `lastday`, `creation`, `premdays_purchased`, 0 AS `expires` FROM `accounts` WHERE `{}` = {}", identifier, db.escapeString(emailOrName));
return load(query, acc);
};

Expand Down
2 changes: 1 addition & 1 deletion src/account/account_repository_db.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ namespace account {
db(db), logger(logger) { }

bool loadByID(const uint32_t &id, AccountInfo &acc) override;
bool loadByEmail(const std::string &email, AccountInfo &acc) override;
bool loadByEmailOrName(bool oldProtocol, const std::string &emailOrName, AccountInfo &acc) override;
bool loadBySession(const std::string &esseionKey, AccountInfo &acc) override;
bool save(const AccountInfo &accInfo) override;

Expand Down

0 comments on commit 55ed7c3

Please sign in to comment.