added wifi qr code

This commit is contained in:
wt committed 2024-07-12 12:04:09 +07:00
1 parent f4e70b4298
commit f3628c4f9c
6 files changed
+31 -6

No files matched your search

-2
View File
@@ -53,8 +53,6 @@ void get_wifi_qr(const httplib::Request &request, httplib::Response &response) {
std::stringstream toqrstring;
toqrstring << "WIFI:T:WPA;P:" << wifi_password << ";S:" << wifi_name << ";";
std::cout << toqrstring.str() << std::endl;
qrcodegen::QrCode qr0 = qrcodegen::QrCode::encodeText(toqrstring.str().c_str(), qrcodegen::QrCode::Ecc::MEDIUM);
std::string responsedata = toSvgString(qr0, 4);
response.set_content(responsedata, SVG_TYPE);
+1 -1
View File
@@ -7,6 +7,6 @@
#define STRING403 R"({"status":"403"})"
#define JSON_TYPE "application/json"
#define PLAIN_TEXT_TYPE "text/plain"
#define SVG_TYPE "image/svg"
#define SVG_TYPE "image/svg+xml"
#endif // TYPES_H
+1
View File
@@ -210,6 +210,7 @@ tbody>tr>th {
width: 0;
height: 0;
overflow: hidden;
transition: 0.3s;
}
#wifiqrimg.active {
+6 -3
View File
@@ -153,10 +153,13 @@
<button id="shownewpasswordbutton">Show</button>
<input type="password" id="newwifipassword" class="forminput">
</div>
<div class="checkbox-wrapper-2">
<input type="checkbox" class="sc-gJwTLC ikxBAC" id="wifiqr">
<div style="display:flex;align-items:center;justify-content:space-between;">
<label for="wifiqr" class="forminputlabel">Show qr code</label>
<div class="checkbox-wrapper-2">
<input type="checkbox" class="sc-gJwTLC ikxBAC" id="wifiqr">
</div>
<div id="wifiqrimg"></div>
</div>
<img src="" alt="qr to connect" id="wifiqrimg">
</div>
<div class="settingrectfooter onebutton">
<button class="settingrectfooterbutton" id="setwifisettings">Confirm</button>
+1
View File
@@ -33,6 +33,7 @@ const routes = {
wifi_name_set: () => [host, prefix, 'settings', 'wifi', 'name', 'set'].join('/'),
wifi_password_get: () => [host, prefix, 'settings', 'wifi', 'password', 'get'].join('/'),
wifi_password_set: () => [host, prefix, 'settings', 'wifi', 'password', 'set'].join('/'),
wifi_qr_get: () => [host, prefix, 'settings', 'wifi', 'qr', 'get' ].join('/'),
reboot: () => [host, prefix, 'reboot'].join('/'),
syslog: () => [host, prefix, 'syslog'].join('/'),
+22
View File
@@ -142,3 +142,25 @@ shownewpasswordbutton.addEventListener('click', () => {
}
newwifipassword.type = "password"
})
const get_wifi_qr_code = () => {
fetch(routes.wifi_qr_get(), {
method: 'POST',
body: `{"token":"${localStorage.getItem('token')}"}`
}).then(data => data.text()).then(svgdata => {
wifiqrimg.innerHTML = svgdata
}).catch((error) => {
notification(`Ошибка на сервере: ${error}`, "error")
})
}
wifiqr.addEventListener('click', () => {
if (wifiqr.checked) {
get_wifi_qr_code()
wifiqrimg.innerHTML =
wifiqrimg.classList.add('active')
return
}
wifiqrimg.classList.remove('active')
wifiqrimg.innerHTML = ""
})