MCPcopy
hub / github.com/writefreely/writefreely / handleViewInvite

Function handleViewInvite

invites.go:136–206  ·  view source on GitHub ↗
(app *App, w http.ResponseWriter, r *http.Request)

Source from the content-addressed store, hash-verified

134}
135
136func handleViewInvite(app *App, w http.ResponseWriter, r *http.Request) error {
137 inviteCode := mux.Vars(r)["code"]
138
139 i, err := app.db.GetUserInvite(inviteCode)
140 if err != nil {
141 return err
142 }
143
144 expired := i.Expired()
145 if !expired && i.MaxUses.Valid && i.MaxUses.Int64 > 0 {
146 // Invite has a max-use number, so check if we're past that limit
147 i.uses = app.db.GetUsersInvitedCount(inviteCode)
148 expired = i.uses >= i.MaxUses.Int64
149 }
150
151 if u := getUserSession(app, r); u != nil {
152 // check if invite belongs to another user
153 // error can be ignored as not important in this case
154 if ownInvite, _ := app.db.IsUsersInvite(inviteCode, u.ID); !ownInvite {
155 addSessionFlash(app, w, r, "You're already registered and logged in.", nil)
156 // show homepage
157 return impart.HTTPError{http.StatusFound, "/me/settings"}
158 }
159
160 // show invite instructions
161 p := struct {
162 *UserPage
163 Invite *Invite
164 Expired bool
165 }{
166 UserPage: NewUserPage(app, r, u, "Invite to "+app.cfg.App.SiteName, nil),
167 Invite: i,
168 Expired: expired,
169 }
170 showUserPage(w, "invite-help", p)
171 return nil
172 }
173
174 p := struct {
175 page.StaticPage
176 *OAuthButtons
177 Error string
178 Flashes []template.HTML
179 Invite string
180 }{
181 StaticPage: pageForReq(app, r),
182 OAuthButtons: NewOAuthButtons(app.cfg),
183 Invite: inviteCode,
184 }
185
186 if expired {
187 p.Error = "This invite link has expired."
188 }
189
190 // Tell search engines not to index invite links
191 w.Header().Set("X-Robots-Tag", "noindex")
192
193 // Get error messages

Callers

nothing calls this directly

Calls 12

getUserSessionFunction · 0.85
addSessionFlashFunction · 0.85
NewUserPageFunction · 0.85
showUserPageFunction · 0.85
pageForReqFunction · 0.85
NewOAuthButtonsFunction · 0.85
getSessionFlashesFunction · 0.85
renderPageFunction · 0.85
ExpiredMethod · 0.80
IsUsersInviteMethod · 0.80
GetUserInviteMethod · 0.65
GetUsersInvitedCountMethod · 0.65

Tested by

no test coverage detected