Skip to content
Snippets Groups Projects
Verified Commit 9158d1e3 authored by Gabriel Zachmann's avatar Gabriel Zachmann
Browse files

improve / fix handling if mail not set

parent cc7294fe
No related branches found
No related tags found
No related merge requests found
......@@ -10,9 +10,9 @@ import (
)
type mailInfo struct {
Mail string `db:"email"`
MailVerified bool `db:"email_verified"`
PreferHTMLMail bool `db:"prefer_html_mail"`
Mail db.NullString `db:"email"`
MailVerified bool `db:"email_verified"`
PreferHTMLMail bool `db:"prefer_html_mail"`
}
// GetMail returns the mail address and verification status for a user linked to a mytoken
......
......@@ -345,16 +345,16 @@ func HandleCalendarEntryViaMail(
res = model.ErrorToInternalServerErrorResponse(err)
return err
}
if !found {
if !found || !mailInfo.Mail.Valid {
res = &model.Response{
Status: http.StatusPreconditionRequired,
Status: http.StatusUnprocessableEntity,
Response: api.ErrorMailRequired,
}
return errors.New("dummy")
}
if !mailInfo.MailVerified {
res = &model.Response{
Status: http.StatusPreconditionRequired,
Status: http.StatusUnprocessableEntity,
Response: api.ErrorMailNotVerified,
}
return errors.New("dummy")
......@@ -364,7 +364,9 @@ func HandleCalendarEntryViaMail(
res = model.ErrorToInternalServerErrorResponse(err)
return err
}
calText, errRes := mailCalendarForMytoken(rlog, tx, id, mtInfo.Name.String, req.Comment, mailInfo.Mail)
calText, errRes := mailCalendarForMytoken(
rlog, tx, id, mtInfo.Name.String, req.Comment, mailInfo.Mail.String,
)
if errRes != nil {
res = errRes
return errors.New("dummy")
......@@ -375,7 +377,7 @@ func HandleCalendarEntryViaMail(
filename = id.Hash()
}
notifier.SendICSMail(
mailInfo.Mail,
mailInfo.Mail.String,
fmt.Sprintf("Mytoken Expiration Calendar Reminder for '%s'", filename),
"You can add the event to your calendar to be notified before the mytoken expires.",
mailing.Attachment{
......
......@@ -213,15 +213,29 @@ func handleNewMailNotification(
if err != nil {
return err
}
if !emailInfo.Mail.Valid {
res = &model.Response{
Status: fiber.StatusUnprocessableEntity,
Response: api.ErrorMailRequired,
}
return errors.New("dummy")
}
if !emailInfo.MailVerified {
res = &model.Response{
Status: fiber.StatusUnprocessableEntity,
Response: api.ErrorMailNotVerified,
}
return errors.New("dummy")
}
notifier.SendTemplateEmail(
emailInfo.Mail, "New Mytoken Notification Subscription",
emailInfo.Mail.String, "New Mytoken Notification Subscription",
emailInfo.PreferHTMLMail, "notification-welcome", welcomeData,
)
tokenUpdate, err := rotation.RotateMytokenAfterOtherForResponse(
rlog, tx, req.Mytoken.JWT, mt, *ctxutils.ClientMetaData(ctx), req.Mytoken.OriginalTokenType,
)
if err != nil {
res = model.ErrorToInternalServerErrorResponse(err)
return err
}
resData := pkg.NotificationsCreateResponse{
......
......@@ -51,7 +51,7 @@ func HandleGet(ctx *fiber.Ctx) error {
}
return &MailSettingsInfoResponse{
MailSettingsInfoResponse: api.MailSettingsInfoResponse{
EmailAddress: info.Mail,
EmailAddress: info.Mail.String,
EmailVerified: info.MailVerified,
PreferHTMLMail: info.PreferHTMLMail,
},
......
......@@ -148,6 +148,9 @@ func sendNotificationsForNotificationInfos(
if err != nil {
return err
}
if !emailInfo.Mail.Valid {
return errors.New("no email set for user")
}
if !emailInfo.MailVerified {
return errors.New("notification email not verified")
}
......@@ -173,7 +176,7 @@ func sendNotificationsForNotificationInfos(
}
rlog.Debug("sending notification mail")
SendTemplateEmail(
emailInfo.Mail, fmt.Sprintf("mytoken notification: %s", notificationClassName),
emailInfo.Mail.String, fmt.Sprintf("mytoken notification: %s", notificationClassName),
emailInfo.PreferHTMLMail, "notification", bindingData,
)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment