64 lines
1.2 KiB
Go
64 lines
1.2 KiB
Go
package props
|
|
|
|
import (
|
|
"lishwist/http/props/htmlx"
|
|
"lishwist/http/templates"
|
|
)
|
|
|
|
type Register struct {
|
|
Navbar templates.NavCollapse
|
|
GeneralError string `json:",omitempty"`
|
|
Username htmlx.Input
|
|
Password htmlx.Input
|
|
ConfirmPassword htmlx.Input
|
|
}
|
|
|
|
func (p *Register) Validate() (valid bool) {
|
|
valid = true
|
|
|
|
if p.Password.Value != p.ConfirmPassword.Value {
|
|
p.ConfirmPassword.Error = "Passwords didn't match"
|
|
valid = false
|
|
}
|
|
|
|
if !p.Username.Validate() {
|
|
valid = false
|
|
}
|
|
|
|
if !p.Password.Validate() {
|
|
valid = false
|
|
}
|
|
|
|
if !p.ConfirmPassword.Validate() {
|
|
valid = false
|
|
}
|
|
|
|
return
|
|
}
|
|
|
|
func NewRegister(usernameVal, passwordVal, confirmPassVal string) *Register {
|
|
return &Register{
|
|
Navbar: templates.DefaultNavCollapse(),
|
|
GeneralError: "",
|
|
Username: htmlx.Input{
|
|
Name: "username",
|
|
Required: true,
|
|
MinLength: 4,
|
|
Value: usernameVal,
|
|
},
|
|
Password: htmlx.Input{
|
|
Type: "password",
|
|
Name: "newPassword",
|
|
Required: true,
|
|
MinLength: 5,
|
|
Value: passwordVal,
|
|
},
|
|
ConfirmPassword: htmlx.Input{
|
|
Type: "password",
|
|
Name: "confirmPassword",
|
|
Required: true,
|
|
Value: confirmPassVal,
|
|
},
|
|
}
|
|
}
|