Rewrote Frontend
This commit is contained in:
@@ -5,7 +5,7 @@
|
||||
#include <botan/base32.h>
|
||||
#include <botan/base64.h>
|
||||
#include <qrcodegen.hpp>
|
||||
#include <lodepng.h>
|
||||
#include <opencv2/opencv.hpp>
|
||||
|
||||
#include "controllers/controllers.h"
|
||||
#include "db/db.h"
|
||||
@@ -24,21 +24,14 @@ std::string create_totp_qrcode(const db::User& user, const std::string& b32_secr
|
||||
const int mod_count = code.getSize();
|
||||
|
||||
const int row_size = qrcode_pixel_size * mod_count;
|
||||
std::vector<uint8_t> secret, image, row;
|
||||
row.reserve(row_size);
|
||||
image.reserve(row_size * row_size);
|
||||
cv::Mat image(mod_count, mod_count, CV_8UC1), scaled_image;
|
||||
std::vector<uint8_t> image_encoded;
|
||||
for (int y = 0; y < mod_count; y++) for (int x = 0; x < mod_count; x++)
|
||||
image.at<uint8_t>(x, y) = code.getModule(x, y) ? 0 : 0xff;
|
||||
cv::resize(image, scaled_image, cv::Size(), qrcode_pixel_size, qrcode_pixel_size, cv::INTER_NEAREST);
|
||||
cv::imencode(".png", scaled_image, image_encoded);
|
||||
|
||||
for (int y = 0; y < mod_count; y++) {
|
||||
row.clear();
|
||||
for (int x = 0; x < mod_count; x++)
|
||||
row.insert(row.end(), qrcode_pixel_size, code.getModule(x, y) ? 0 : 0xff);
|
||||
for (int i = 0; i < qrcode_pixel_size; i++)
|
||||
image.insert(image.end(), row.begin(), row.end());
|
||||
}
|
||||
|
||||
lodepng::encode(secret, image, row_size, row_size, LCT_GREY, 8);
|
||||
|
||||
return "data:image/png;base64," + Botan::base64_encode(secret);
|
||||
return "data:image/png;base64," + Botan::base64_encode(image_encoded);
|
||||
}
|
||||
|
||||
namespace api {
|
||||
@@ -64,7 +57,7 @@ namespace api {
|
||||
std::string code = create_totp_qrcode(user, b32_secret);
|
||||
cbk(dto::Responses::get_tfa_setup_res(b32_secret, code));
|
||||
}
|
||||
} catch (const std::exception&) {
|
||||
} catch (const std::exception& e) {
|
||||
cbk(dto::Responses::get_badreq_res("Validation error"));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
|
||||
#include <jwt-cpp/traits/kazuho-picojson/traits.h>
|
||||
#include <jwt-cpp/jwt.h>
|
||||
#include <mailio/smtp.hpp>
|
||||
#include <SMTPMail.h>
|
||||
|
||||
#include "controllers/controllers.h"
|
||||
#include "db/db.h"
|
||||
@@ -43,15 +43,17 @@ namespace api {
|
||||
char totp[16];
|
||||
std::snprintf(totp, 16, "%06d", Botan::TOTP(Botan::OctetString(totp_secret)).generate_totp(t));
|
||||
|
||||
mailio::message msg;
|
||||
msg.from(mailio::mail_address("Fileserver", "fileserver@mattv.de"));
|
||||
msg.add_recipient(mailio::mail_address(user.getValueOfName(), user.getValueOfName()));
|
||||
msg.subject("Subject: Fileserver - Email 2fa code");
|
||||
msg.content("Your code is: " + std::string(totp) +"\r\nIt is valid for 5 Minutes");
|
||||
|
||||
mailio::smtps conn("mail.mattv.de", 587);
|
||||
conn.authenticate("no-reply@mattv.de", "noreplyLONGPASS123", mailio::smtps::auth_method_t::START_TLS);
|
||||
conn.submit(msg);
|
||||
drogon::app().getPlugin<SMTPMail>()->sendEmail(
|
||||
"mail.mattv.de",
|
||||
587,
|
||||
"fileserver@mattv.de",
|
||||
user.getValueOfName(),
|
||||
"MFileserver - Email 2fa code",
|
||||
"Your code is: " + std::string(totp) +"\r\nIt is valid for 5 Minutes",
|
||||
"no-reply@mattv.de",
|
||||
"noreplyLONGPASS123",
|
||||
false
|
||||
);
|
||||
}
|
||||
|
||||
std::string auth::get_token(const db::User& user) {
|
||||
|
||||
Reference in New Issue
Block a user