Show status on logged-in expired invite links

Ref T690
This commit is contained in:
Matt Baer 2019-09-23 09:45:36 -04:00
parent 891b15b8a8
commit 7e9e3cb7eb
2 changed files with 23 additions and 15 deletions

View File

@ -115,6 +115,13 @@ func handleViewInvite(app *App, w http.ResponseWriter, r *http.Request) error {
return err
}
expired := i.Expired()
if !expired && i.MaxUses.Valid && i.MaxUses.Int64 > 0 {
// Invite has a max-use number, so check if we're past that limit
i.uses = app.db.GetUsersInvitedCount(inviteCode)
expired = i.uses >= i.MaxUses.Int64
}
if u := getUserSession(app, r); u != nil {
// check if invite belongs to another user
// error can be ignored as not important in this case
@ -123,13 +130,16 @@ func handleViewInvite(app *App, w http.ResponseWriter, r *http.Request) error {
// show homepage
return impart.HTTPError{http.StatusFound, "/me/settings"}
}
// show invite instructions
p := struct {
*UserPage
InviteID string
Expired bool
}{
UserPage: NewUserPage(app, r, u, "Invite Instructions", nil),
InviteID: inviteCode,
Expired: expired,
}
showUserPage(w, "invite-instructions", p)
return nil
@ -145,16 +155,10 @@ func handleViewInvite(app *App, w http.ResponseWriter, r *http.Request) error {
Invite: inviteCode,
}
if i.Expired() {
if expired {
p.Error = "This invite link has expired."
}
if i.MaxUses.Valid && i.MaxUses.Int64 > 0 {
if c := app.db.GetUsersInvitedCount(inviteCode); c >= i.MaxUses.Int64 {
p.Error = "This invite link has expired."
}
}
// Get error messages
session, err := app.sessionStore.Get(r, cookieName)
if err != nil {

View File

@ -11,6 +11,9 @@
</style>
<div class="snug content-container">
<h1>Invite Instructions</h1>
{{ if .Expired }}
<p style="font-style: italic">This invite link is expired.</p>
{{ else }}
<p>This is a special link that you can send to anyone you want to join <em>{{ .SiteName }}</em>. Copy the link below and paste it into an email, instant message, or text message and send it to the person you want. When they navigate to the link, they'll be able to create an account.</p>
<input
class="copy-link"
@ -19,6 +22,7 @@
value="{{$.Host}}/invite/{{.InviteID}}"
onfocus="if (this.select) this.select(); else this.setSelectionRange(0, this.value.length);"
readonly/>
{{ end }}
</div>
{{template "footer" .}}