Compare commits

..

2 commits

Author SHA1 Message Date
231c8d7fd6 Korrigiere Prüfung von Mailsuffixen 2022-11-15 11:42:58 +01:00
f1dd952344 Mache Start- und Endzeiten konfigurierbar 2022-11-15 11:42:23 +01:00
4 changed files with 64 additions and 15 deletions

View file

@ -23,6 +23,14 @@ type Config struct {
} }
Date struct { Date struct {
MinuteGranularity int // Restricts the minutes on which office hours can start and end to multiples of it. MinuteGranularity int // Restricts the minutes on which office hours can start and end to multiples of it.
EarliestStartTime struct {
Hour int
Minute int
}
LatestStartTime struct {
Hour int
Minute int
}
} }
Request struct { Request struct {
SecretLength int // Length of the secret token for requests SecretLength int // Length of the secret token for requests
@ -86,6 +94,26 @@ func validateConfig(conf *Config) error {
err = fmt.Errorf("Validating config: Minute granularity must be between 1 and 60, but is %d.", conf.Date.MinuteGranularity) err = fmt.Errorf("Validating config: Minute granularity must be between 1 and 60, but is %d.", conf.Date.MinuteGranularity)
log.Println(err.Error()) log.Println(err.Error())
} }
if !(conf.Date.EarliestStartTime.Hour >= 0 && conf.Date.EarliestStartTime.Hour <= 23) {
err = fmt.Errorf("Validating config: Earliest start time hour must be between 0 and 23, but is %d.", conf.Date.EarliestStartTime.Hour)
log.Println(err.Error())
}
if !(conf.Date.EarliestStartTime.Minute >= 0 && conf.Date.EarliestStartTime.Minute <= 60) {
err = fmt.Errorf("Validating config: Earliest start time minute must be between 0 and 60, but is %d.", conf.Date.EarliestStartTime.Minute)
log.Println(err.Error())
}
if !(conf.Date.LatestStartTime.Hour >= 0 && conf.Date.LatestStartTime.Hour <= 23) {
err = fmt.Errorf("Validating config: Latest start time hour must be between 0 and 23, but is %d.", conf.Date.LatestStartTime.Hour)
log.Println(err.Error())
}
if !(conf.Date.LatestStartTime.Minute >= 0 && conf.Date.LatestStartTime.Minute <= 60) {
err = fmt.Errorf("Validating config: Latest start time minute must be between 0 and 60, but is %d.", conf.Date.LatestStartTime.Minute)
log.Println(err.Error())
}
if !(conf.Date.EarliestStartTime.Hour < conf.Date.LatestStartTime.Hour || (conf.Date.EarliestStartTime.Hour == conf.Date.LatestStartTime.Hour && conf.Date.EarliestStartTime.Minute < conf.Date.LatestStartTime.Minute)) {
err = fmt.Errorf("Validating config: Latest start time minute must be after earliest start time.")
log.Println(err.Error())
}
if !(conf.Request.SecretLength >= 5 && conf.Request.SecretLength <= 50) { if !(conf.Request.SecretLength >= 5 && conf.Request.SecretLength <= 50) {
err = fmt.Errorf("Validating config: Requests' secret length must be between 5 and 50, but is %d.", conf.Request.SecretLength) err = fmt.Errorf("Validating config: Requests' secret length must be between 5 and 50, but is %d.", conf.Request.SecretLength)
log.Println(err.Error()) log.Println(err.Error())

View file

@ -6,7 +6,15 @@
"domain": "localhost:8080" "domain": "localhost:8080"
}, },
"date": { "date": {
"minuteGranularity": 5 "minuteGranularity": 5,
"earliestStartTime": {
"hour" : 8,
"minute" : 0
},
"latestStartTime": {
"hour" : 20,
"minute" : 0
}
}, },
"request": { "request": {
"secretLength": 15 "secretLength": 15

View file

@ -16,16 +16,24 @@ type maskData struct {
Courses []models.Course Courses []models.Course
Rooms []models.Room Rooms []models.Room
MinuteGranularity int MinuteGranularity int
SelectedCourse int EarliestStartTime struct {
SelectedRoom int Hour int
Date models.Date Minute int
Duration int }
Roomname string LatestStartTime struct {
Name string Hour int
Email string Minute int
Info string }
Errors []string SelectedCourse int
Config config.Config SelectedRoom int
Date models.Date
Duration int
Roomname string
Name string
Email string
Info string
Errors []string
Config config.Config
} }
// Offer a form to add office hours and validate its input on receiving. // Offer a form to add office hours and validate its input on receiving.
@ -81,8 +89,11 @@ func (b *BaseHandler) AddOfficeHourHandler(w http.ResponseWriter, req *http.Requ
if err != nil { if err != nil {
errors = append(errors, "Die Stunde muss eine ganze Zahl sein.") errors = append(errors, "Die Stunde muss eine ganze Zahl sein.")
} }
if !(hour >= 8 && hour <= 17) { if !(hour > b.config.Date.EarliestStartTime.Hour || (hour == b.config.Date.EarliestStartTime.Hour && minute >= b.config.Date.EarliestStartTime.Minute)) {
errors = append(errors, fmt.Sprintf("Sprechstunden müssen zwischen 08:00 Uhr und 17:%d starten.", 60-b.config.Date.MinuteGranularity)) errors = append(errors, fmt.Sprintf("Sprechstunden müssen nach %02d:%02d Uhr starten.", b.config.Date.EarliestStartTime.Hour, b.config.Date.EarliestStartTime.Minute))
}
if !(hour < b.config.Date.LatestStartTime.Hour || (hour == b.config.Date.LatestStartTime.Hour && minute <= b.config.Date.LatestStartTime.Minute)) {
errors = append(errors, fmt.Sprintf("Sprechstunden müssen vor %02d:%02d Uhr starten.", b.config.Date.LatestStartTime.Hour, b.config.Date.LatestStartTime.Minute))
} }
minute, err = strconv.Atoi(time[1]) minute, err = strconv.Atoi(time[1])
if err != nil { if err != nil {
@ -113,7 +124,7 @@ func (b *BaseHandler) AddOfficeHourHandler(w http.ResponseWriter, req *http.Requ
if err != nil { if err != nil {
email = &mail.Address{Name: "", Address: req.FormValue("email")} email = &mail.Address{Name: "", Address: req.FormValue("email")}
errors = append(errors, "Mailaddresse konnte nicht geparst werden.") errors = append(errors, "Mailaddresse konnte nicht geparst werden.")
} else if !(strings.HasSuffix(email.Address, "@"+b.config.Tutor.MailSuffix) || strings.HasSuffix(email.Address, "."+b.config.Tutor.MailSuffix)) { } else if !(b.config.Tutor.MailSuffix == "" || strings.HasSuffix(email.Address, "@"+b.config.Tutor.MailSuffix) || strings.HasSuffix(email.Address, "."+b.config.Tutor.MailSuffix)) {
errors = append(errors, fmt.Sprintf("Mailaddresse muss auf „%s“ enden.", b.config.Tutor.MailSuffix)) errors = append(errors, fmt.Sprintf("Mailaddresse muss auf „%s“ enden.", b.config.Tutor.MailSuffix))
} }
info := req.FormValue("info") info := req.FormValue("info")
@ -132,6 +143,8 @@ func (b *BaseHandler) AddOfficeHourHandler(w http.ResponseWriter, req *http.Requ
courses, courses,
rooms, rooms,
b.config.Date.MinuteGranularity, b.config.Date.MinuteGranularity,
b.config.Date.EarliestStartTime,
b.config.Date.LatestStartTime,
courseid, courseid,
roomid, roomid,
date, date,

View file

@ -24,7 +24,7 @@
<option value="3"{{if eq 3 $.Date.Day}} selected{{end}}>Donnerstag</option> <option value="3"{{if eq 3 $.Date.Day}} selected{{end}}>Donnerstag</option>
<option value="4"{{if eq 4 $.Date.Day}} selected{{end}}>Freitag</option> <option value="4"{{if eq 4 $.Date.Day}} selected{{end}}>Freitag</option>
</select><br> </select><br>
<label for="startzeit">Startzeit</label>: <input type="time" name="startzeit" id="startzeit" min="08:00" max="17:30" {{if gt $.Date.Hour 7}}value="{{printf "%02d" $.Date.Hour}}:{{printf "%02d" $.Date.Minute}}"{{end}} required><br> <label for="startzeit">Startzeit</label>: <input type="time" name="startzeit" id="startzeit" min="{{printf "%02d" .EarliestStartTime.Hour}}:{{printf "%02d" .EarliestStartTime.Minute}}" max="{{printf "%02d" .LatestStartTime.Hour}}:{{printf "%02d" .LatestStartTime.Minute}}" {{if ge $.Date.Hour .EarliestStartTime.Hour}}value="{{printf "%02d" $.Date.Hour}}:{{printf "%02d" $.Date.Minute}}"{{end}} required><br>
<label for="dauer">Dauer in Minuten</label>: <input name="dauer" id="dauer" type="number" min="{{.MinuteGranularity}}" max="120" step="{{.MinuteGranularity}}" value="{{.Duration}}" required><br> <label for="dauer">Dauer in Minuten</label>: <input name="dauer" id="dauer" type="number" min="{{.MinuteGranularity}}" max="120" step="{{.MinuteGranularity}}" value="{{.Duration}}" required><br>
<label for="raum">Raum</label>: <label for="raum">Raum</label>:
<select name="raum" id="raum"> <select name="raum" id="raum">