s1llyw0rdz/web/handler/form/settings.go

31 lines
530 B
Go
Raw Permalink Normal View History

2021-11-25 06:37:30 +00:00
package form
import (
2021-12-10 07:33:45 +00:00
"errors"
2021-11-25 06:37:30 +00:00
"net/http"
2021-12-10 07:33:45 +00:00
"strings"
2021-11-25 06:37:30 +00:00
)
type SettingsForm struct {
Homepage string
About string
2021-11-26 22:36:48 +00:00
Picture string
2021-11-28 14:31:51 +00:00
Email string
2021-11-25 06:37:30 +00:00
}
2021-12-10 07:33:45 +00:00
func (f *SettingsForm) Validate() error {
if strings.Contains(f.About, "<script") {
return errors.New("script tag is forbidden")
}
return nil
}
2021-11-25 06:37:30 +00:00
func NewSettingsForm(r *http.Request) *SettingsForm {
return &SettingsForm{
Homepage: r.FormValue("homepage"),
About: r.FormValue("about"),
2021-11-26 22:36:48 +00:00
Picture: r.FormValue("picture"),
2021-11-28 14:31:51 +00:00
Email: r.FormValue("email"),
2021-11-25 06:37:30 +00:00
}
}