mirror of
https://github.com/sunnypilot/sunnypilot.git
synced 2026-10-01 01:43:41 +08:00
Fleet Manager: toggle PIN requirement (#160)
* Fleet Manager: toggle PIN requirement * update the entire title * update the param * handle conditions * update on toggle press
This commit is contained in:
@@ -204,14 +204,29 @@ DevicePanel::DevicePanel(SettingsWindow *parent) : ListWidget(parent) {
|
||||
addItem(new LabelControl(tr("Dongle ID"), getDongleId().value_or(tr("N/A"))));
|
||||
addItem(new LabelControl(tr("Serial"), params.get("HardwareSerial").c_str()));
|
||||
|
||||
fleetManagerPin = new LabelControl(tr("Fleet Manager PIN"), pin);
|
||||
fleetManagerPin = new ButtonControl(
|
||||
tr(pin_title) + pin, tr("TOGGLE"),
|
||||
tr("Enable or disable PIN requirement for Fleet Manager access."));
|
||||
connect(fleetManagerPin, &ButtonControl::clicked, [=]() {
|
||||
if (params.getBool("FleetManagerPin")) {
|
||||
if (ConfirmationDialog::confirm(tr("Are you sure you want to turn off PIN requirement?"), tr("Turn Off"), this)) {
|
||||
params.remove("FleetManagerPin");
|
||||
refreshPin();
|
||||
}
|
||||
} else {
|
||||
params.putBool("FleetManagerPin", true);
|
||||
refreshPin();
|
||||
}
|
||||
});
|
||||
addItem(fleetManagerPin);
|
||||
|
||||
fs_watch = new QFileSystemWatcher(this);
|
||||
connect(fs_watch, &QFileSystemWatcher::fileChanged, this, &DevicePanel::onPinFileChanged);
|
||||
|
||||
QString pin_path = "/data/otp/otp.conf";
|
||||
QString pin_require = "/data/params/d/FleetManagerPin";
|
||||
fs_watch->addPath(pin_path);
|
||||
fs_watch->addPath(pin_require);
|
||||
refreshPin();
|
||||
|
||||
// Error Troubleshoot
|
||||
@@ -321,18 +336,24 @@ DevicePanel::DevicePanel(SettingsWindow *parent) : ListWidget(parent) {
|
||||
}
|
||||
|
||||
void DevicePanel::onPinFileChanged(const QString &file_path) {
|
||||
if (file_path == "/data/otp/otp.conf") {
|
||||
if (file_path == "/data/params/d/FleetManagerPin") {
|
||||
refreshPin();
|
||||
} else if (file_path == "/data/otp/otp.conf") {
|
||||
refreshPin();
|
||||
}
|
||||
}
|
||||
|
||||
void DevicePanel::refreshPin() {
|
||||
QFile f("/data/otp/otp.conf");
|
||||
if (f.open(QIODevice::ReadOnly | QIODevice::Text)) {
|
||||
QFile require("/data/params/d/FleetManagerPin");
|
||||
if (!require.exists()) {
|
||||
setSpacing(50);
|
||||
fleetManagerPin->setTitle(QString(pin_title) + "OFF");
|
||||
} else if (f.open(QIODevice::ReadOnly | QIODevice::Text)) {
|
||||
pin = f.readAll();
|
||||
f.close();
|
||||
setSpacing(50);
|
||||
fleetManagerPin->setText(pin);
|
||||
fleetManagerPin->setTitle(QString(pin_title) + pin);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -54,8 +54,9 @@ private slots:
|
||||
private:
|
||||
Params params;
|
||||
|
||||
LabelControl *fleetManagerPin;
|
||||
QString pin;
|
||||
ButtonControl *fleetManagerPin;
|
||||
const char *pin_title = "Fleet Manager PIN: ";
|
||||
QString pin = "OFF";
|
||||
QFileSystemWatcher *fs_watch;
|
||||
};
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@ import subprocess
|
||||
from flask import render_template, request, session
|
||||
from functools import wraps
|
||||
from pathlib import Path
|
||||
from common.params import Params
|
||||
from system.hardware import PC
|
||||
from system.loggerd.config import ROOT as REALDATA
|
||||
from system.loggerd.uploader import listdir_by_creation
|
||||
@@ -23,7 +24,7 @@ else:
|
||||
def login_required(f):
|
||||
@wraps(f)
|
||||
def decorated_route(*args, **kwargs):
|
||||
if not session.get("logged_in"):
|
||||
if not session.get("logged_in") and Params().get_bool("FleetManagerPin"):
|
||||
session["previous_page"] = request.url
|
||||
return render_template("login.html")
|
||||
return f(*args, **kwargs)
|
||||
|
||||
Reference in New Issue
Block a user