feat: allow restrict Pomodoro via password

- introduce password flag in server command line options
- update clientCommand model
- add password requirement for controlling the Pomodoro timer
- document password in README
This commit is contained in:
Sebastian Mark 2024-10-21 15:36:26 +02:00
parent 8deb642a7e
commit f991ba885d
5 changed files with 38 additions and 26 deletions

View file

@ -16,3 +16,5 @@ func ResetToDefault() models.ServerMessage {
Paused: false,
}
}
var PomodoroPassword string

View file

@ -30,26 +30,28 @@ func handleClientCommands(ws *websocket.Conn) {
continue
}
// Process the command
switch clientCommand.Command {
case "start":
if !pomodoro.IsPomodoroOngoing() {
if clientCommand.Config != shared.UnsetPomodoroConfig {
pomodoroConfig = clientCommand.Config
// Process the command if pomodoro password matches
if clientCommand.Password == shared.PomodoroPassword {
switch clientCommand.Command {
case "start":
if !pomodoro.IsPomodoroOngoing() {
if clientCommand.Config != shared.UnsetPomodoroConfig {
pomodoroConfig = clientCommand.Config
}
go pomodoro.RunPomodoro(pomodoroConfig) // Start the timer with the list of clients
}
case "stop":
if pomodoro.IsPomodoroOngoing() {
pomodoro.ResetPomodoro() // Reset Pomodoro
}
case "pause":
if pomodoro.IsPomodoroOngoing() && !pomodoro.IsPomodoroPaused() {
pomodoro.PausePomodoro() // Pause the timer
}
case "resume":
if pomodoro.IsPomodoroOngoing() && pomodoro.IsPomodoroPaused() {
pomodoro.ResumePomodoro() // Resume the timer
}
go pomodoro.RunPomodoro(pomodoroConfig) // Start the timer with the list of clients
}
case "stop":
if pomodoro.IsPomodoroOngoing() {
pomodoro.ResetPomodoro() // Reset Pomodoro
}
case "pause":
if pomodoro.IsPomodoroOngoing() && !pomodoro.IsPomodoroPaused() {
pomodoro.PausePomodoro() // Pause the timer
}
case "resume":
if pomodoro.IsPomodoroOngoing() && pomodoro.IsPomodoroPaused() {
pomodoro.ResumePomodoro() // Resume the timer
}
}