работающая авторизация
This commit is contained in:
@@ -5,7 +5,8 @@
|
||||
#include "utils.h"
|
||||
|
||||
|
||||
http::auth::User::User(const std::string &username, const std::string &passwordHash): username(username), passwordHash(passwordHash) {}
|
||||
http::auth::User::User(const std::string &username, const std::string &passwordHash): username(username),
|
||||
passwordHash(passwordHash.empty() ? utils::sha256(username) : passwordHash) {}
|
||||
|
||||
bool http::auth::User::checkPassword(const std::string &pass) const {
|
||||
return utils::sha256(pass) == passwordHash;
|
||||
@@ -57,21 +58,16 @@ std::shared_ptr<http::auth::User> http::auth::AuthProvider::doAuth(const std::st
|
||||
}
|
||||
|
||||
std::shared_ptr<http::auth::User> http::auth::AuthProvider::getSession(const server::Request &req) {
|
||||
for (const auto& header: req.headers) {
|
||||
if (boost::iequals(header.name, "cookie")) {
|
||||
auto t = jwt::Jwt::fromCookies(header.value);
|
||||
if (t.isValid()) {
|
||||
const auto name = t.getUsername();
|
||||
// токен валидный, ищем юзера
|
||||
for (auto& u: users) {
|
||||
if (u->username == name) {
|
||||
return u;
|
||||
}
|
||||
}
|
||||
|
||||
BOOST_LOG_TRIVIAL(warning) << "http::auth::AuthProvider::getSession(): Found valid session for a non-existent user " << name;
|
||||
auto t = jwt::Jwt::fromCookies(req.getHeaderValue("cookie"));
|
||||
if (t.isValid()) {
|
||||
const auto name = t.getUsername();
|
||||
// токен валидный, ищем юзера
|
||||
for (auto& u: users) {
|
||||
if (u->username == name) {
|
||||
return u;
|
||||
}
|
||||
}
|
||||
BOOST_LOG_TRIVIAL(warning) << "http::auth::AuthProvider::getSession(): Found valid session for a non-existent user " << name;
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
Reference in New Issue
Block a user