MCPcopy Index your code
hub / github.com/writefreely/writefreely / handleCreateUserInvite

Function handleCreateUserInvite

invites.go:99–134  ·  view source on GitHub ↗
(app *App, u *User, w http.ResponseWriter, r *http.Request)

Source from the content-addressed store, hash-verified

97}
98
99func handleCreateUserInvite(app *App, u *User, w http.ResponseWriter, r *http.Request) error {
100 muVal := r.FormValue("uses")
101 expVal := r.FormValue("expires")
102
103 if u.IsSilenced() {
104 return ErrUserSilenced
105 }
106
107 var err error
108 var maxUses int
109 if muVal != "0" {
110 maxUses, err = strconv.Atoi(muVal)
111 if err != nil {
112 return impart.HTTPError{http.StatusBadRequest, "Invalid value for 'max_uses'"}
113 }
114 }
115
116 var expDate *time.Time
117 var expires int
118 if expVal != "0" {
119 expires, err = strconv.Atoi(expVal)
120 if err != nil {
121 return impart.HTTPError{http.StatusBadRequest, "Invalid value for 'expires'"}
122 }
123 ed := time.Now().Add(time.Duration(expires) * time.Minute)
124 expDate = &ed
125 }
126
127 inviteID := id.GenerateRandomString("0123456789BCDFGHJKLMNPQRSTVWXYZbcdfghjklmnpqrstvwxyz", 6)
128 err = app.db.CreateUserInvite(inviteID, u.ID, maxUses, expDate)
129 if err != nil {
130 return err
131 }
132
133 return impart.HTTPError{http.StatusFound, "/me/invites"}
134}
135
136func handleViewInvite(app *App, w http.ResponseWriter, r *http.Request) error {
137 inviteCode := mux.Vars(r)["code"]

Callers

nothing calls this directly

Calls 2

IsSilencedMethod · 0.80
CreateUserInviteMethod · 0.65

Tested by

no test coverage detected