Compare commits

..

No commits in common. "231c8d7fd6514f779485685ccbaa90d4a35953cd" and "3db1627680366093b79faa140f5926c1066825a7" have entirely different histories.

4 changed files with 15 additions and 64 deletions

View file

@ -23,14 +23,6 @@ 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
@ -94,26 +86,6 @@ 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,15 +6,7 @@
"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,14 +16,6 @@ type maskData struct {
Courses []models.Course Courses []models.Course
Rooms []models.Room Rooms []models.Room
MinuteGranularity int MinuteGranularity int
EarliestStartTime struct {
Hour int
Minute int
}
LatestStartTime struct {
Hour int
Minute int
}
SelectedCourse int SelectedCourse int
SelectedRoom int SelectedRoom int
Date models.Date Date models.Date
@ -89,11 +81,8 @@ 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 > b.config.Date.EarliestStartTime.Hour || (hour == b.config.Date.EarliestStartTime.Hour && minute >= b.config.Date.EarliestStartTime.Minute)) { if !(hour >= 8 && hour <= 17) {
errors = append(errors, fmt.Sprintf("Sprechstunden müssen nach %02d:%02d Uhr starten.", b.config.Date.EarliestStartTime.Hour, 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))
}
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 {
@ -124,7 +113,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 !(b.config.Tutor.MailSuffix == "" || strings.HasSuffix(email.Address, "@"+b.config.Tutor.MailSuffix) || strings.HasSuffix(email.Address, "."+b.config.Tutor.MailSuffix)) { } else if !(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")
@ -143,8 +132,6 @@ 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="{{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="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="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">