Skip to content

Commit

Permalink
admin/volunteer: add dedicated email login pages
Browse files Browse the repository at this point in the history
  • Loading branch information
ezrichards committed Mar 3, 2024
1 parent 3bea19c commit 42ffcd2
Show file tree
Hide file tree
Showing 5 changed files with 90 additions and 7 deletions.
2 changes: 1 addition & 1 deletion internal/admin.go
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ func (a *Application) HandleAdminLogin(w http.ResponseWriter, r *http.Request) {
} else {
log.Info().Msg("sent email")
http.SetCookie(w, &http.Cookie{Name: "admin_email", Value: emailAddress, Path: "/"})
a.ConfirmEmailRenderer(w, r, map[string]any{"Email": emailAddress})
a.AdminConfirmEmailRenderer(w, r, map[string]any{"Email": emailAddress})
}
}

Expand Down
19 changes: 14 additions & 5 deletions internal/application.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,13 @@ type Application struct {
EmailRegex *regexp.Regexp
Config config.Configuration

ConfirmEmailRenderer func(w http.ResponseWriter, r *http.Request, extraData map[string]any)
TeacherLoginRenderer func(w http.ResponseWriter, r *http.Request, extraData map[string]any)
EmailLoginRenderer func(w http.ResponseWriter, r *http.Request, extraData map[string]any)
StudentConfirmInfoRenderer func(w http.ResponseWriter, r *http.Request, extraData map[string]any)
TeamAddMemberRenderer func(w http.ResponseWriter, r *http.Request, extraData map[string]any)
ConfirmEmailRenderer func(w http.ResponseWriter, r *http.Request, extraData map[string]any)
VolunteerConfirmEmailRenderer func(w http.ResponseWriter, r *http.Request, extraData map[string]any)
AdminConfirmEmailRenderer func(w http.ResponseWriter, r *http.Request, extraData map[string]any)
TeacherLoginRenderer func(w http.ResponseWriter, r *http.Request, extraData map[string]any)
EmailLoginRenderer func(w http.ResponseWriter, r *http.Request, extraData map[string]any)
StudentConfirmInfoRenderer func(w http.ResponseWriter, r *http.Request, extraData map[string]any)
TeamAddMemberRenderer func(w http.ResponseWriter, r *http.Request, extraData map[string]any)

TeacherCreateAccountRenderer func(w http.ResponseWriter, r *http.Request, extraData map[string]any)

Expand Down Expand Up @@ -139,6 +141,9 @@ func (a *Application) Start() {
a.TeacherLoginRenderer = a.ServeTemplateExtra(a.Log, "teacherlogin.html", a.GetEmailLoginTemplate)
a.TeacherCreateAccountRenderer = a.ServeTemplateExtra(a.Log, "teachercreateaccount.html", a.GetTeacherCreateAccountTemplate)
a.ConfirmEmailRenderer = a.ServeTemplateExtra(a.Log, "confirmemail.html", a.GetEmailLoginTemplate)
a.VolunteerConfirmEmailRenderer = a.ServeTemplateExtra(a.Log, "volunteerconfirmemail.html", a.GetEmailLoginTemplate)
a.AdminConfirmEmailRenderer = a.ServeTemplateExtra(a.Log, "adminconfirmemail.html", a.GetEmailLoginTemplate)

a.EmailLoginRenderer = a.ServeTemplateExtra(a.Log, "emaillogin.html", a.GetEmailLoginTemplate)
a.StudentConfirmInfoRenderer = a.ServeTemplateExtra(a.Log, "student.html", a.GetStudentConfirmInfoTemplate)
a.TeamAddMemberRenderer = a.ServeTemplateExtra(a.Log, "teamaddmember.html", a.GetTeacherAddMemberTemplate)
Expand All @@ -156,6 +161,10 @@ func (a *Application) Start() {

// Parent
"/register/parent/signforms": {a.ServeTemplateExtra(a.Log, "parent.html", a.GetParentSignFormsTemplate), false},

// Admin & Volunteer
"/register/volunteer/confirmemail": {a.VolunteerConfirmEmailRenderer, true},
"/register/admin/confirmemail": {a.AdminConfirmEmailRenderer, true},
}
for path, rend := range registrationPages {
renderFn := func(path string, rend renderInfo) func(w http.ResponseWriter, r *http.Request) {
Expand Down
2 changes: 1 addition & 1 deletion internal/volunteer.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ func (a *Application) HandleVolunteerLogin(w http.ResponseWriter, r *http.Reques
} else {
log.Info().Msg("sent email")
http.SetCookie(w, &http.Cookie{Name: "volunteer_email", Value: emailAddress, Path: "/"})
a.ConfirmEmailRenderer(w, r, map[string]any{"Email": emailAddress})
a.VolunteerConfirmEmailRenderer(w, r, map[string]any{"Email": emailAddress})
}
}

Expand Down
37 changes: 37 additions & 0 deletions website/templates/adminconfirmemail.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
{{ define "title" }}Confirm Email{{ end }}

{{ define "content" }}
<div class="container">
<div class="row page-header">
<div class="col">
<h1>Confirm Email</h1>
</div>
</div>
</div>

<div class="container page-content confirm-email">
{{ with .Data.Error }}
<div class="row">
<div class="alert alert-danger" role="alert">
<p>That login code was expired or invalid.</p>
<p>
Forgot to confirm your email?
<a href="mailto:support@mineshspc.com">Contact Support</a>.
</p>
</div>
</div>
{{ else }}
<div class="row">
<div class="col m-4 text-center">
<p>
We've sent an email to <b>{{ .Data.Email }}</b>.
</p>
<p style="font-size: 10em; line-height: 0;"><i class="fa fa-envelope-o"></i></p>
<p>
Please check your email and click the link to confirm your email address and log in.
</p>
</div>
</div>
{{ end }}
</div>
{{ end }}
37 changes: 37 additions & 0 deletions website/templates/volunteerconfirmemail.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
{{ define "title" }}Confirm Email{{ end }}

{{ define "content" }}
<div class="container">
<div class="row page-header">
<div class="col">
<h1>Confirm Email</h1>
</div>
</div>
</div>

<div class="container page-content confirm-email">
{{ with .Data.Error }}
<div class="row">
<div class="alert alert-danger" role="alert">
<p>That login code was expired or invalid.</p>
<p>
Forgot to confirm your email?
<a href="mailto:support@mineshspc.com">Contact Support</a>.
</p>
</div>
</div>
{{ else }}
<div class="row">
<div class="col m-4 text-center">
<p>
Thanks for volunteering! We've sent an email to <b>{{ .Data.Email }}</b>.
</p>
<p style="font-size: 10em; line-height: 0;"><i class="fa fa-envelope-o"></i></p>
<p>
Please check your email and click the link to confirm your email address and log in.
</p>
</div>
</div>
{{ end }}
</div>
{{ end }}

0 comments on commit 42ffcd2

Please sign in to comment.