package routing import ( "lishwist/api" "lishwist/rsvp" "net/http" ) func Register(h http.Header, r *rsvp.Request) rsvp.Response { props := api.NewRegisterProps("", "", "") session := r.GetSession() flash := session.FlashGet("register_props") flashProps, _ := flash.(*api.RegisterProps) if flashProps != nil { props.Username.Value = flashProps.Username.Value props.GeneralError = flashProps.GeneralError props.Username.Error = flashProps.Username.Error props.ConfirmPassword.Error = flashProps.ConfirmPassword.Error } return rsvp.Data("register.gotmpl", props).SaveSession(session) } func RegisterPost(h http.Header, r *rsvp.Request) rsvp.Response { form := r.ParseForm() username := form.Get("username") newPassword := form.Get("newPassword") confirmPassword := form.Get("confirmPassword") props := api.Register(username, newPassword, confirmPassword) s := r.GetSession() if props != nil { s.FlashSet(&props, "register_props") return rsvp.SeeOther("/register").SaveSession(s) } s.FlashSet(true, "successful_registration") return rsvp.SeeOther("/").SaveSession(s) }