Noah Petherbridge
6d3de7da69
Since most of the `render.Vars{}` fields were hardcoded/not really editable for the templates, apart from .Data, this struct is now locked away in the render subpackage. End http.HandlerFunc's can then make any arbitrary template data structure they want to, available inside the templates as `.Data`.
33 lines
690 B
Go
33 lines
690 B
Go
package forms
|
|
|
|
import (
|
|
"errors"
|
|
"net/http"
|
|
)
|
|
|
|
// Setup is for the initial blog setup page at /initial-setup.
|
|
type Setup struct {
|
|
Username string
|
|
Password string
|
|
Confirm string
|
|
}
|
|
|
|
// Parse form values.
|
|
func (f *Setup) ParseForm(r *http.Request) {
|
|
f.Username = r.FormValue("username")
|
|
f.Password = r.FormValue("password")
|
|
f.Confirm = r.FormValue("confirm")
|
|
}
|
|
|
|
// Validate the form.
|
|
func (f Setup) Validate() error {
|
|
if len(f.Username) == 0 {
|
|
return errors.New("admin username is required")
|
|
} else if len(f.Password) == 0 {
|
|
return errors.New("admin password is required")
|
|
} else if f.Password != f.Confirm {
|
|
return errors.New("your passwords do not match")
|
|
}
|
|
return nil
|
|
}
|