diff --git a/invites.go b/invites.go index 1bd75e6..f7dcd7a 100644 --- a/invites.go +++ b/invites.go @@ -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 { diff --git a/templates/user/invite-instructions.tmpl b/templates/user/invite-instructions.tmpl index 8bd2a30..a70acd8 100644 --- a/templates/user/invite-instructions.tmpl +++ b/templates/user/invite-instructions.tmpl @@ -11,14 +11,18 @@

Invite Instructions

-

This is a special link that you can send to anyone you want to join {{ .SiteName }}. 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.

- + {{ if .Expired }} +

This invite link is expired.

+ {{ else }} +

This is a special link that you can send to anyone you want to join {{ .SiteName }}. 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.

+ + {{ end }}
{{template "footer" .}}