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 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 { if u := getUserSession(app, r); u != nil {
// check if invite belongs to another user // check if invite belongs to another user
// error can be ignored as not important in this case // 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 // show homepage
return impart.HTTPError{http.StatusFound, "/me/settings"} return impart.HTTPError{http.StatusFound, "/me/settings"}
} }
// show invite instructions // show invite instructions
p := struct { p := struct {
*UserPage *UserPage
InviteID string InviteID string
Expired bool
}{ }{
UserPage: NewUserPage(app, r, u, "Invite Instructions", nil), UserPage: NewUserPage(app, r, u, "Invite Instructions", nil),
InviteID: inviteCode, InviteID: inviteCode,
Expired: expired,
} }
showUserPage(w, "invite-instructions", p) showUserPage(w, "invite-instructions", p)
return nil return nil
@ -145,16 +155,10 @@ func handleViewInvite(app *App, w http.ResponseWriter, r *http.Request) error {
Invite: inviteCode, Invite: inviteCode,
} }
if i.Expired() { if expired {
p.Error = "This invite link has 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 // Get error messages
session, err := app.sessionStore.Get(r, cookieName) session, err := app.sessionStore.Get(r, cookieName)
if err != nil { if err != nil {

View File

@ -11,6 +11,9 @@
</style> </style>
<div class="snug content-container"> <div class="snug content-container">
<h1>Invite Instructions</h1> <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> <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 <input
class="copy-link" class="copy-link"
@ -19,6 +22,7 @@
value="{{$.Host}}/invite/{{.InviteID}}" value="{{$.Host}}/invite/{{.InviteID}}"
onfocus="if (this.select) this.select(); else this.setSelectionRange(0, this.value.length);" onfocus="if (this.select) this.select(); else this.setSelectionRange(0, this.value.length);"
readonly/> readonly/>
{{ end }}
</div> </div>
{{template "footer" .}} {{template "footer" .}}