Простой механизм аутентификации дрогонC++

Программы на C++. Форум разработчиков
Ответить
Anonymous
 Простой механизм аутентификации дрогон

Сообщение Anonymous »

Шифрование является временным.

У меня совершенно нечитаемая ошибка во всех экземплярах функции execSqlAsync.
Ошибка:
In template: invalid operands to binary expression ('std::stringstream' (aka 'basic_stringstream') and 'std::exception') error occurred here in instantiation of function template specialization 'drogon::orm::Field::as' requested here in instantiation of function template specialization 'drogon::orm::internal::CallbackHolder::makeValue' requested here in instantiation of function template specialization 'drogon::orm::internal::CallbackHolder::run' requested here in instantiation of function template specialization 'drogon::orm::internal::CallbackHolder::run' requested here in instantiation of member function 'drogon::orm::internal::CallbackHolder::execCallback' requested here in instantiation of function template specialization 'drogon::orm::internal::CallbackHolder::CallbackHolder char {
if (c >= 'a' && c = 'A' && c getJsonObject();
std::string username = json->get("username", "").asString();
std::string password = json->get("password", "").asString();

// Encrypt the password using Caesar cipher
std::string encryptedPassword = caesarCipher(password, 3);

auto client = drogon::app().getDbClient().get();
client->execSqlAsync(
"INSERT INTO users (username, password_hash) VALUES ($1, $2)",
[callback](const Result &result) {
auto response = HttpResponse::newHttpResponse();
response->setStatusCode(HttpStatusCode::k200OK);
response->setBody("Signup successful");
callback(response);
},
[callback](const std::exception &e) { // Correct exception handling
auto response = HttpResponse::newHttpResponse();
response->setStatusCode(HttpStatusCode::k500InternalServerError);
response->setBody(e.what());
callback(response);
},
username, encryptedPassword);
}

void AuthController::login(const HttpRequestPtr &req, std::function &&callback) {
auto json = req->getJsonObject();
std::string username = json->get("username", "").asString();
std::string password = json->get("password", "").asString();

auto client = drogon::app().getDbClient();
client.get()->execSqlAsync(
"SELECT password_hash FROM users WHERE username = $1",
[password, callback](const Result &result) {
std::shared_ptr response;
if (!result.empty()) {
std::string storedHash = result[0]["password_hash"].as();
std::string decryptedPassword = caesarCipher(storedHash, -3);
if (decryptedPassword == password) {
response = HttpResponse::newHttpResponse();
response->setStatusCode(k200OK);
response->setBody("Login successful");
} else {
response = HttpResponse::newHttpResponse();
response->setStatusCode(k401Unauthorized);
response->setBody("Login failed");
}
} else {
response = HttpResponse::newHttpResponse();
response->setStatusCode(k401Unauthorized);
response->setBody("User not found");
}
callback(response);
},
[callback](const std::exception &e) {
auto resp = HttpResponse::newHttpResponse();
resp->setStatusCode(k500InternalServerError);
resp->setBody(e.what());
callback(resp);
},
username);
}


Подробнее здесь: https://stackoverflow.com/questions/783 ... ism-drogon
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «C++»