Add option to subscribe to mailinglist
This commit is contained in:
parent
47c546b880
commit
5d4fed7180
10 changed files with 43 additions and 23 deletions
3
.gitignore
vendored
3
.gitignore
vendored
|
@ -20,3 +20,6 @@ vendor/
|
||||||
|
|
||||||
# Go workspace file
|
# Go workspace file
|
||||||
go.work
|
go.work
|
||||||
|
|
||||||
|
#IDE files
|
||||||
|
*.geany
|
||||||
|
|
|
@ -25,16 +25,17 @@ type maskData struct {
|
||||||
Hour int
|
Hour int
|
||||||
Minute int
|
Minute int
|
||||||
}
|
}
|
||||||
SelectedCourse int
|
SelectedCourse int
|
||||||
SelectedRoom int
|
SelectedRoom int
|
||||||
Date models.Date
|
Date models.Date
|
||||||
Duration int
|
Duration int
|
||||||
Roomname string
|
Roomname string
|
||||||
Name string
|
Name string
|
||||||
Email string
|
Email string
|
||||||
Info string
|
SubscribeToMailinglist bool
|
||||||
Errors []string
|
Info string
|
||||||
Config config.Config
|
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.
|
||||||
|
@ -129,6 +130,9 @@ func (b *BaseHandler) AddOfficeHourHandler(w http.ResponseWriter, req *http.Requ
|
||||||
} else if !(b.config.Tutor.MailSuffix == "" || 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))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
subscribeToMailinglist := req.FormValue("subscribeToMailinglist") == "subscribe"
|
||||||
|
|
||||||
info := req.FormValue("info")
|
info := req.FormValue("info")
|
||||||
|
|
||||||
allowed, err := b.officeHourRepo.AllowedAt(date, duration, room, true)
|
allowed, err := b.officeHourRepo.AllowedAt(date, duration, room, true)
|
||||||
|
@ -155,6 +159,7 @@ func (b *BaseHandler) AddOfficeHourHandler(w http.ResponseWriter, req *http.Requ
|
||||||
roomname,
|
roomname,
|
||||||
name,
|
name,
|
||||||
email.Address,
|
email.Address,
|
||||||
|
subscribeToMailinglist,
|
||||||
info,
|
info,
|
||||||
errors,
|
errors,
|
||||||
b.config,
|
b.config,
|
||||||
|
@ -164,7 +169,7 @@ func (b *BaseHandler) AddOfficeHourHandler(w http.ResponseWriter, req *http.Requ
|
||||||
// if the data for a new office hour was sent correctly, save it.
|
// if the data for a new office hour was sent correctly, save it.
|
||||||
|
|
||||||
officeHour := models.OfficeHour{Id: 0,
|
officeHour := models.OfficeHour{Id: 0,
|
||||||
Tutor: models.Tutor{Id: 0, Name: name, Email: email.Address},
|
Tutor: models.Tutor{Id: 0, Name: name, Email: email.Address, SubscribeToMailinglist: subscribeToMailinglist},
|
||||||
Date: date,
|
Date: date,
|
||||||
Room: room,
|
Room: room,
|
||||||
RoomName: roomname,
|
RoomName: roomname,
|
||||||
|
|
|
@ -37,7 +37,7 @@ func (b *BaseHandler) GetTimetable(officeHours []models.OfficeHour) (map[models.
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
slots := []int{1, 1, 1, 1, 1}
|
slots := []int{1, 1, 1, 1, 1}
|
||||||
for date, _ := range timetable {
|
for date := range timetable {
|
||||||
if slots[date.Day] < len(timetable[date]) {
|
if slots[date.Day] < len(timetable[date]) {
|
||||||
slots[date.Day] = len(timetable[date])
|
slots[date.Day] = len(timetable[date])
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,7 +12,7 @@ type Request struct {
|
||||||
|
|
||||||
const (
|
const (
|
||||||
RequestActivate RequestAction = iota // Fix integer to represent request for activation of an office hour.
|
RequestActivate RequestAction = iota // Fix integer to represent request for activation of an office hour.
|
||||||
RequestDelete // Fix integer to represent request for deletion of an office hour.
|
RequestDelete // Fix integer to represent request for deletion of an office hour.
|
||||||
)
|
)
|
||||||
|
|
||||||
type RequestRepository interface {
|
type RequestRepository interface {
|
||||||
|
|
|
@ -2,9 +2,13 @@
|
||||||
package models
|
package models
|
||||||
|
|
||||||
type Tutor struct {
|
type Tutor struct {
|
||||||
Id int
|
Id int
|
||||||
Name string
|
Name string
|
||||||
Email string
|
Email string
|
||||||
|
|
||||||
|
// Does the tutor want to subscribe to the mailinglist for student assistents?
|
||||||
|
// This information has to be extracted from the database by hand.
|
||||||
|
SubscribeToMailinglist bool
|
||||||
}
|
}
|
||||||
|
|
||||||
type TutorRepository interface {
|
type TutorRepository interface {
|
||||||
|
|
|
@ -21,7 +21,8 @@ CREATE TABLE `room` (
|
||||||
CREATE TABLE `tutor` (
|
CREATE TABLE `tutor` (
|
||||||
`id` INTEGER PRIMARY KEY AUTO_INCREMENT,
|
`id` INTEGER PRIMARY KEY AUTO_INCREMENT,
|
||||||
`name` tinytext DEFAULT NULL,
|
`name` tinytext DEFAULT NULL,
|
||||||
`email` tinytext DEFAULT NULL
|
`email` tinytext DEFAULT NULL,
|
||||||
|
`subscribeToMailinglist` BOOL DEFAULT false
|
||||||
);
|
);
|
||||||
|
|
||||||
--
|
--
|
||||||
|
|
|
@ -53,7 +53,8 @@ DROP TABLE IF EXISTS `tutor`;
|
||||||
CREATE TABLE `tutor` (
|
CREATE TABLE `tutor` (
|
||||||
`id` INTEGER PRIMARY KEY,
|
`id` INTEGER PRIMARY KEY,
|
||||||
`name` tinytext DEFAULT NULL,
|
`name` tinytext DEFAULT NULL,
|
||||||
`email` tinytext DEFAULT NULL
|
`email` tinytext DEFAULT NULL,
|
||||||
|
`subscribeToMailinglist` BOOL DEFAULT false
|
||||||
);
|
);
|
||||||
|
|
||||||
--
|
--
|
||||||
|
|
|
@ -50,7 +50,7 @@ func (r *TutorRepo) Add(tutor models.Tutor) (int, error) {
|
||||||
//Don't add identical tutors
|
//Don't add identical tutors
|
||||||
existentTutor, err := r.FindByNameAndEmail(tutor.Name, tutor.Email)
|
existentTutor, err := r.FindByNameAndEmail(tutor.Name, tutor.Email)
|
||||||
if errors.Is(err, sql.ErrNoRows) {
|
if errors.Is(err, sql.ErrNoRows) {
|
||||||
sqlResult, err := r.db.Exec("INSERT INTO `tutor` (name, email) VALUES (?,?)", tutor.Name, tutor.Email)
|
sqlResult, err := r.db.Exec("INSERT INTO `tutor` (name, email, subscribeToMailinglist) VALUES (?,?,?)", tutor.Name, tutor.Email, tutor.SubscribeToMailinglist)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err = fmt.Errorf("SQL-error inserting new tutor: %w", err)
|
err = fmt.Errorf("SQL-error inserting new tutor: %w", err)
|
||||||
log.Println(err.Error())
|
log.Println(err.Error())
|
||||||
|
@ -67,7 +67,7 @@ func (r *TutorRepo) Add(tutor models.Tutor) (int, error) {
|
||||||
|
|
||||||
func (r *TutorRepo) getFromRow(row *sql.Row) (models.Tutor, error) {
|
func (r *TutorRepo) getFromRow(row *sql.Row) (models.Tutor, error) {
|
||||||
var tutor models.Tutor
|
var tutor models.Tutor
|
||||||
if err := row.Scan(&tutor.Id, &tutor.Name, &tutor.Email); err != nil {
|
if err := row.Scan(&tutor.Id, &tutor.Name, &tutor.Email, &tutor.SubscribeToMailinglist); err != nil {
|
||||||
err = fmt.Errorf("SQL-error scanning tutor row: %w", err)
|
err = fmt.Errorf("SQL-error scanning tutor row: %w", err)
|
||||||
log.Println(err.Error())
|
log.Println(err.Error())
|
||||||
return models.Tutor{}, err
|
return models.Tutor{}, err
|
||||||
|
@ -79,7 +79,7 @@ func (r *TutorRepo) getFromRows(rows *sql.Rows) ([]models.Tutor, error) {
|
||||||
var tutors []models.Tutor
|
var tutors []models.Tutor
|
||||||
for rows.Next() {
|
for rows.Next() {
|
||||||
var tutor models.Tutor
|
var tutor models.Tutor
|
||||||
if err := rows.Scan(&tutor.Id, &tutor.Name, &tutor.Email); err != nil {
|
if err := rows.Scan(&tutor.Id, &tutor.Name, &tutor.Email, &tutor.SubscribeToMailinglist); err != nil {
|
||||||
err = fmt.Errorf("Error scanning tutor row: %w", err)
|
err = fmt.Errorf("Error scanning tutor row: %w", err)
|
||||||
log.Println(err.Error())
|
log.Println(err.Error())
|
||||||
return tutors, err
|
return tutors, err
|
||||||
|
|
|
@ -31,8 +31,14 @@
|
||||||
{{end}}
|
{{end}}
|
||||||
Die Email-Adresse dient der Vermeidung von Spam und wird nicht veröffentlicht.
|
Die Email-Adresse dient der Vermeidung von Spam und wird nicht veröffentlicht.
|
||||||
</div>
|
</div>
|
||||||
|
<div class="form-check">
|
||||||
|
<input class="form-check-input" name="subscribeToMailinglist" id="subscribeToMailinglist" type="checkbox" value="subscribe" {{if eq .SubscribeToMailinglist true}}checked{{end}}>
|
||||||
|
<label class="form-check-label" for="subscribeToMailinglist"><a href="https://lists.mathebau.de/postorius/lists/shk.mathebau.de/">Mailingliste für SHK abbonieren</a></label>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<div class="form-floating mb-3">
|
<div class="form-floating mb-3">
|
||||||
<select class="form-control form-select required" required name="veranstaltung" id="veranstaltung">
|
<select class="form-control form-select required" required name="veranstaltung" id="veranstaltung">
|
||||||
<option disabled{{if eq $.SelectedCourse 0 }} selected{{end}} value>–– auswählen ––</option>
|
<option disabled{{if eq $.SelectedCourse 0 }} selected{{end}} value>–– auswählen ––</option>
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
From: {{.Config.Mailer.FromName}}
|
From: {{.Config.Mailer.FromName}}
|
||||||
To: {{.Request.OfficeHour.Tutor.Email}}
|
To: {{.Request.OfficeHour.Tutor.Email}}
|
||||||
Subject: Sprechstunde {{if eq .Request.Action 0}}anlegen{{end}}{{if eq .Request.Action 1}}löschen{{end}}
|
Subject: Sprechstunde {{if eq .Request.Action 0}}anlegen{{end}}{{if eq .Request.Action 1}}löschen{{end}}
|
||||||
Message-Id: {{.MessageId}}
|
Message-ID: {{.MessageId}}
|
||||||
|
|
||||||
Hallo {{.Request.OfficeHour.Tutor.Name}},
|
Hallo {{.Request.OfficeHour.Tutor.Name}},
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue