feat: quiz and rbac
This commit is contained in:
@@ -0,0 +1,65 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"html/template"
|
||||
"strings"
|
||||
|
||||
"go.uber.org/zap"
|
||||
|
||||
"github.com/prabhupadasays/spsays-bff/internal/model"
|
||||
)
|
||||
|
||||
// defaultAdminURL is where the welcome email sends new staff when ADMIN_URL
|
||||
// isn't configured (local development leaves it empty).
|
||||
const defaultAdminURL = "https://admin.prabhupadasays.org"
|
||||
|
||||
// sendStaffWelcome tells someone they've been given admin access, and as
|
||||
// what. Fire-and-forget, like the other notification emails: the grant is
|
||||
// already committed, so a mail failure is logged, never surfaced.
|
||||
func (s *StaffService) sendStaffWelcome(m *model.StaffMember) {
|
||||
if s.mail == nil {
|
||||
return
|
||||
}
|
||||
if m.Email == nil || strings.TrimSpace(*m.Email) == "" {
|
||||
s.logger.Info("staff granted; no email on file, skipping welcome",
|
||||
zap.String("user_id", m.UserID))
|
||||
return
|
||||
}
|
||||
var buf bytes.Buffer
|
||||
if err := staffWelcomeEmailTpl.Execute(&buf, map[string]any{
|
||||
"RecipientName": strings.TrimSpace(m.Name),
|
||||
"RoleName": m.RoleName,
|
||||
"AdminURL": s.adminURL,
|
||||
}); err != nil {
|
||||
s.logger.Warn("render staff welcome email failed", zap.Error(err))
|
||||
return
|
||||
}
|
||||
to := strings.TrimSpace(*m.Email)
|
||||
go func() {
|
||||
if err := s.mail.Send(to, "You've been promoted to "+m.RoleName+" — Prabhupāda Says", buf.String()); err != nil {
|
||||
s.logger.Warn("staff welcome email send failed",
|
||||
zap.String("user_id", m.UserID), zap.Error(err))
|
||||
}
|
||||
}()
|
||||
}
|
||||
|
||||
// staffWelcomeEmailTpl — same styling as the other account emails. The role
|
||||
// name is admin-entered (custom roles) and auto-escaped by html/template.
|
||||
var staffWelcomeEmailTpl = template.Must(template.New("staffWelcome").Parse(`<div style="font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,Helvetica,Arial,sans-serif;color:#2a2118;max-width:560px;margin:0 auto;font-size:17px;line-height:1.7">
|
||||
<p style="font-size:18px;color:#9a6b2f;letter-spacing:0.04em;margin-bottom:1em">Hare Kṛṣṇa{{if .RecipientName}}, {{.RecipientName}}{{end}} 🙏</p>
|
||||
|
||||
<p>You have been promoted to <strong>{{.RoleName}}</strong> on Prabhupāda Says.</p>
|
||||
|
||||
<p>Log in with your email and password at
|
||||
<a href="{{.AdminURL}}" style="color:#9a6b2f;font-weight:600">{{.AdminURL}}</a>.</p>
|
||||
|
||||
<p style="margin:1.25em 0">
|
||||
<a href="{{.AdminURL}}" style="display:inline-block;background:#9a6b2f;color:#fff;text-decoration:none;padding:0.6em 1.3em;border-radius:8px;font-weight:600">Open the admin panel</a>
|
||||
</p>
|
||||
|
||||
<p>For any queries, contact your co-ordinator.</p>
|
||||
|
||||
<p style="margin-top:1.5em">Your servants,<br>
|
||||
<strong>The Prabhupāda Says team</strong></p>
|
||||
</div>`))
|
||||
Reference in New Issue
Block a user