added wifi qr code
This commit is contained in:
1 parent
f4e70b4298
commit
f3628c4f9c
6 files changed
+31
-6
No files matched your search
@@ -53,8 +53,6 @@ void get_wifi_qr(const httplib::Request &request, httplib::Response &response) {
|
|||||||
std::stringstream toqrstring;
|
std::stringstream toqrstring;
|
||||||
toqrstring << "WIFI:T:WPA;P:" << wifi_password << ";S:" << wifi_name << ";";
|
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);
|
qrcodegen::QrCode qr0 = qrcodegen::QrCode::encodeText(toqrstring.str().c_str(), qrcodegen::QrCode::Ecc::MEDIUM);
|
||||||
std::string responsedata = toSvgString(qr0, 4);
|
std::string responsedata = toSvgString(qr0, 4);
|
||||||
response.set_content(responsedata, SVG_TYPE);
|
response.set_content(responsedata, SVG_TYPE);
|
||||||
|
|||||||
@@ -7,6 +7,6 @@
|
|||||||
#define STRING403 R"({"status":"403"})"
|
#define STRING403 R"({"status":"403"})"
|
||||||
#define JSON_TYPE "application/json"
|
#define JSON_TYPE "application/json"
|
||||||
#define PLAIN_TEXT_TYPE "text/plain"
|
#define PLAIN_TEXT_TYPE "text/plain"
|
||||||
#define SVG_TYPE "image/svg"
|
#define SVG_TYPE "image/svg+xml"
|
||||||
|
|
||||||
#endif // TYPES_H
|
#endif // TYPES_H
|
||||||
@@ -210,6 +210,7 @@ tbody>tr>th {
|
|||||||
width: 0;
|
width: 0;
|
||||||
height: 0;
|
height: 0;
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
|
transition: 0.3s;
|
||||||
}
|
}
|
||||||
|
|
||||||
#wifiqrimg.active {
|
#wifiqrimg.active {
|
||||||
|
|||||||
@@ -153,10 +153,13 @@
|
|||||||
<button id="shownewpasswordbutton">Show</button>
|
<button id="shownewpasswordbutton">Show</button>
|
||||||
<input type="password" id="newwifipassword" class="forminput">
|
<input type="password" id="newwifipassword" class="forminput">
|
||||||
</div>
|
</div>
|
||||||
<div class="checkbox-wrapper-2">
|
<div style="display:flex;align-items:center;justify-content:space-between;">
|
||||||
<input type="checkbox" class="sc-gJwTLC ikxBAC" id="wifiqr">
|
<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>
|
</div>
|
||||||
<img src="" alt="qr to connect" id="wifiqrimg">
|
|
||||||
</div>
|
</div>
|
||||||
<div class="settingrectfooter onebutton">
|
<div class="settingrectfooter onebutton">
|
||||||
<button class="settingrectfooterbutton" id="setwifisettings">Confirm</button>
|
<button class="settingrectfooterbutton" id="setwifisettings">Confirm</button>
|
||||||
|
|||||||
@@ -33,6 +33,7 @@ const routes = {
|
|||||||
wifi_name_set: () => [host, prefix, 'settings', 'wifi', 'name', 'set'].join('/'),
|
wifi_name_set: () => [host, prefix, 'settings', 'wifi', 'name', 'set'].join('/'),
|
||||||
wifi_password_get: () => [host, prefix, 'settings', 'wifi', 'password', 'get'].join('/'),
|
wifi_password_get: () => [host, prefix, 'settings', 'wifi', 'password', 'get'].join('/'),
|
||||||
wifi_password_set: () => [host, prefix, 'settings', 'wifi', 'password', 'set'].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('/'),
|
reboot: () => [host, prefix, 'reboot'].join('/'),
|
||||||
syslog: () => [host, prefix, 'syslog'].join('/'),
|
syslog: () => [host, prefix, 'syslog'].join('/'),
|
||||||
|
|||||||
@@ -142,3 +142,25 @@ shownewpasswordbutton.addEventListener('click', () => {
|
|||||||
}
|
}
|
||||||
newwifipassword.type = "password"
|
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 = ""
|
||||||
|
})
|
||||||
Reference in new issue
Block a user