Show status on logged-in expired invite links

Ref T690
pull/183/head
Matt Baer 5 years ago
parent 891b15b8a8
commit 7e9e3cb7eb
  1. 18
      invites.go
  2. 20
      templates/user/invite-instructions.tmpl

@ -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 {

@ -11,14 +11,18 @@
</style> </style>
<div class="snug content-container"> <div class="snug content-container">
<h1>Invite Instructions</h1> <h1>Invite Instructions</h1>
<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> {{ if .Expired }}
<input <p style="font-style: italic">This invite link is expired.</p>
class="copy-link" {{ else }}
type="text" <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>
name="invite-url" <input
value="{{$.Host}}/invite/{{.InviteID}}" class="copy-link"
onfocus="if (this.select) this.select(); else this.setSelectionRange(0, this.value.length);" type="text"
readonly/> name="invite-url"
value="{{$.Host}}/invite/{{.InviteID}}"
onfocus="if (this.select) this.select(); else this.setSelectionRange(0, this.value.length);"
readonly/>
{{ end }}
</div> </div>
{{template "footer" .}} {{template "footer" .}}

Loading…
Cancel
Save