(app *App, u *User, w http.ResponseWriter, r *http.Request)
| 97 | } |
| 98 | |
| 99 | func 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 | |
| 136 | func handleViewInvite(app *App, w http.ResponseWriter, r *http.Request) error { |
| 137 | inviteCode := mux.Vars(r)["code"] |
nothing calls this directly
no test coverage detected