Factor out common post parsing code for sms message
This commit is contained in:
parent
b0ee388986
commit
2626e044ca
2 changed files with 37 additions and 17 deletions
21
sync/sudo.go
21
sync/sudo.go
|
|
@ -30,20 +30,13 @@ type FormSMS struct {
|
|||
Phone string `schema:"smsPhone"`
|
||||
}
|
||||
|
||||
func postSudoSMS(w http.ResponseWriter, r *http.Request, u *models.User) {
|
||||
err := r.ParseForm()
|
||||
if err != nil {
|
||||
respondError(w, "Failed to parse form", err, http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
var sms FormSMS
|
||||
|
||||
err = decoder.Decode(&sms, r.PostForm)
|
||||
if err != nil {
|
||||
respondError(w, "Failed to decode form", err, http.StatusInternalServerError)
|
||||
return
|
||||
func postSudoSMS(ctx context.Context, u *models.User, sms FormSMS) (string, *errorWithStatus) {
|
||||
if u.Role != enums.UserroleRoot {
|
||||
return "", &errorWithStatus{
|
||||
Message: "You must have sudo powers to do this",
|
||||
Status: http.StatusForbidden,
|
||||
}
|
||||
}
|
||||
log.Info().Str("msg", sms.Message).Str("phone", sms.Phone).Msg("Got SMS")
|
||||
http.Redirect(w, r, "/sudo", http.StatusFound)
|
||||
return "/sudo", nil
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue