hlfw.ca

webbing

Download patch

ref: d4d6fbd29958d449e6b00dc3ee66772ff8bfca9c
author: halfwit <michaelmisch1985@gmail.com>
date: Sat Mar 28 07:37:25 PDT 2020

Move forms

--- /dev/null
+++ b/doctor/application.go
@@ -1,0 +1,66 @@
+package forms
+
+import (
+	"fmt"
+	"net/http"
+
+	"github.com/albrow/forms"
+	"github.com/olmaxmedical/olmax_go/plugins"
+	"github.com/olmaxmedical/olmax_go/router"
+	"golang.org/x/text/message"
+)
+
+func init() {
+	b := &router.Form{
+		Access:    router.GuestAuth,
+		Path:      "doctor/application",
+		Validator: application,
+		Redirect:  "/index.html",
+		After:     plugins.EmailForm | plugins.Countries | plugins.Services | plugins.FormToken,
+	}
+	router.AddPost(b)
+}
+
+func application(r *http.Request, p *message.Printer) []string {
+	var errors []string
+	data, err := forms.Parse(r)
+	if err != nil {
+		errors = append(errors, "Internal server error")
+		return errors
+	}
+	val := data.Validator()
+	val.Require("gender").Message(p.Sprint("Please select a biological gender"))
+	if r.PostFormValue("gender") != "male" && r.PostFormValue("gender") != "female" {
+		val.AddError("gender", p.Sprint("Invalid selection for gender"))
+	}
+	val.RequireFile("cv").Message(p.Sprint("Empty or missing CV"))
+	val.AcceptFileExts("cv", "application/msword,applicationvnd.openxmlformats-officedocument.wordprocessingml.document,application/pdf").Message(p.Sprint("Unsupported filetype for CV"))
+	val.RequireFile("diploma").Message(p.Sprint("Empty or missing Diploma/Board Certification"))
+	val.AcceptFileExts("cv", "application/msword,applicationvnd.openxmlformats-officedocument.wordprocessingml.document,application/pdf").Message(p.Sprint("Unsupported filetype for Diploma/Board Certification"))
+	for i := 1; i < 12; i++ {
+		num := fmt.Sprintf("q%d", i)
+		sel, ok := r.Form[num]
+		if !ok {
+			val.AddError(num, p.Sprintf("No selection for question %d", i))
+			continue
+		}
+		if sel[0] == "Yes" || sel[0] == "yes" || sel[0] == "no" || sel[0] == "No" {
+			continue
+		}
+		val.AddError(num, p.Sprintf("Invalid selection for question %d", i))
+	}
+	val.Require("email").Message(p.Sprintf("Valid email required"))
+	val.MatchEmail("email").Message(p.Sprintf("Invalid email"))
+	val.Require("name").Message(p.Sprintf("Full name required"))
+	val.MinLength("name", 2).Message(p.Sprintf("Full name must be at least 2 characters"))
+	if r.PostFormValue("redFlag") != "on" {
+		val.AddError("redFlag", p.Sprint("Invalid selection for confirm element"))
+	}
+	if val.HasErrors() {
+		errors = append(errors, val.Messages()...)
+	}
+	r.Form["pagetitle"] = []string{"Application for doctor"}
+	r.Form["sendto"] = []string{"olmaxmedical@gmail.com"}
+	delete(r.Form, "redFlag")
+	return errors
+}
--- /dev/null
+++ b/doctor/profile.go
@@ -1,0 +1,53 @@
+package forms
+
+import (
+	"net/http"
+	"time"
+
+	"github.com/albrow/forms"
+	"github.com/olmaxmedical/olmax_go/plugins"
+	"github.com/olmaxmedical/olmax_go/router"
+	"golang.org/x/text/message"
+)
+
+func init() {
+	b := &router.Form{
+		Access:    router.DoctorAuth,
+		Path:      "doctor/profile",
+		Validator: profile,
+		Redirect:  "/doctor/profile.html",
+		After:     plugins.FormToken | plugins.AddAppointment,
+	}
+	router.AddPost(b)
+}
+
+func profile(r *http.Request, p *message.Printer) []string {
+	var errors []string
+	data, err := forms.Parse(r)
+	if err != nil {
+		errors = append(errors, "Internal server error")
+		return errors
+	}
+	val := data.Validator()
+	val.Require("BTCperU").Message(p.Sprint("Please enter a rate (Bitcoin/15min)"))
+	bcu := data.GetFloat("BTCperU")
+	if 0.0 > bcu || bcu > 1.0 {
+		val.AddError("BTCperU", p.Sprint("BTC/15min rate out of range"))
+	}
+	val.Require("startDate").Message(p.Sprint("Start date required"))
+	_, err = time.Parse("2006-01-02T15:04:05", r.Form.Get("startDate"))
+	if err != nil {
+		val.AddError("startDate", p.Sprint("Invalid start-date entered"))
+	}
+
+	val.Require("endDate").Message(p.Sprint("End date required"))
+	_, err = time.Parse("2006-01-02T15:04:05", r.Form.Get("endDate"))
+	if err != nil {
+		val.AddError("endDate", p.Sprint("Invalid end-date entered"))
+	}
+
+	if val.HasErrors() {
+		errors = append(errors, val.Messages()...)
+	}
+	return errors
+}
--- /dev/null
+++ b/login.go
@@ -1,0 +1,39 @@
+package forms
+
+import (
+	"net/http"
+
+	"github.com/albrow/forms"
+	"github.com/olmaxmedical/olmax_go/plugins"
+	"github.com/olmaxmedical/olmax_go/router"
+	"golang.org/x/text/message"
+)
+
+func init() {
+	b := &router.Form{
+		Access:    router.GuestAuth,
+		Path:      "login",
+		Validator: login,
+		After:     plugins.ValidateLogin,
+		Redirect:  "/profile.html",
+	}
+	router.AddPost(b)
+}
+
+func login(r *http.Request, p *message.Printer) []string {
+	var errors []string
+	data, err := forms.Parse(r)
+	if err != nil {
+		errors = append(errors, p.Sprint("Internal server error"))
+		return errors
+	}
+	val := data.Validator()
+	val.Require("email").Message(p.Sprint("Username required"))
+	val.MatchEmail("email").Message(p.Sprint("User name must be a valid email"))
+	val.Require("pass").Message(p.Sprint("Password required"))
+	val.MinLength("pass", 8).Message(p.Sprint("Password must be at least 8 characters"))
+	if val.HasErrors() {
+		errors = append(errors, val.Messages()...)
+	}
+	return errors
+}
--- /dev/null
+++ b/newpassword.go
@@ -1,0 +1,42 @@
+package forms
+
+import (
+	"net/http"
+
+	"github.com/albrow/forms"
+	"github.com/olmaxmedical/olmax_go/plugins"
+	"github.com/olmaxmedical/olmax_go/router"
+	"golang.org/x/text/message"
+)
+
+func init() {
+	b := &router.Form{
+		Access:    router.GuestAuth,
+		Path:      "newpassword",
+		Validator: newPassword,
+		Redirect:  "/login.html",
+		After:     plugins.ResetPassword | plugins.FormToken,
+	}
+	router.AddPost(b)
+}
+
+func newPassword(r *http.Request, p *message.Printer) []string {
+	var errors []string
+	data, err := forms.Parse(r)
+	if err != nil {
+		errors = append(errors, "Internal server error")
+		return errors
+	}
+	val := data.Validator()
+	val.Require("password").Message(p.Sprintf("Password required"))
+	val.MinLength("password", 8).Message(p.Sprintf("Password must be at least 8 characters"))
+	val.Require("reenter").Message(p.Sprintf("Re-enter same password"))
+	val.MinLength("reenter", 8).Message(p.Sprintf("Password must be at least 8 characters"))
+	if val.HasErrors() {
+		errors = append(errors, val.Messages()...)
+	}
+	if data.Get("reenter") != data.Get("password") {
+		errors = append(errors, p.Sprint("Passwords do not match"))
+	}
+	return errors
+}
--- /dev/null
+++ b/patient/offer.go
@@ -1,0 +1,53 @@
+package forms
+
+import (
+	"net/http"
+	"time"
+
+	"github.com/albrow/forms"
+	"github.com/olmaxmedical/olmax_go/plugins"
+	"github.com/olmaxmedical/olmax_go/router"
+	"golang.org/x/text/message"
+)
+
+func init() {
+	b := &router.Form{
+		Access:    router.PatientAuth,
+		Path:      "patient/offer",
+		Validator: offer,
+		After:     plugins.Search | plugins.Services,
+		Redirect:  "results.html",
+	}
+	router.AddPost(b)
+}
+
+func offer(r *http.Request, p *message.Printer) []string {
+	var errors []string
+	data, err := forms.Parse(r)
+	if err != nil {
+		errors = append(errors, p.Sprint("Internal server error"))
+		return errors
+	}
+	val := data.Validator()
+	val.Require("Amount").Message(p.Sprint("Please enter a target rate (Bitcoin/15min)"))
+	bcu := data.GetFloat("Amount")
+	if 0.0 > bcu || bcu > 1.0 {
+		val.AddError("Amount", p.Sprint("BTC/15min rate out of range"))
+	}
+	val.Require("startDate").Message(p.Sprint("Start date required"))
+	_, err = time.Parse("2006-01-02T15:04:05", r.Form.Get("startDate"))
+	if err != nil {
+		val.AddError("startDate", p.Sprint("Invalid start-date entered"))
+	}
+
+	val.Require("endDate").Message(p.Sprint("End date required"))
+	_, err = time.Parse("2006-01-02T15:04:05", r.Form.Get("endDate"))
+	if err != nil {
+		val.AddError("endDate", p.Sprint("Invalid end-date entered"))
+	}
+	val.Require("")
+	if val.HasErrors() {
+		errors = append(errors, val.Messages()...)
+	}
+	return errors
+}
--- /dev/null
+++ b/patient/profile.go
@@ -1,0 +1,35 @@
+package forms
+
+import (
+	"net/http"
+
+	"github.com/albrow/forms"
+	"github.com/olmaxmedical/olmax_go/router"
+	"golang.org/x/text/message"
+)
+
+func init() {
+	b := &router.Form{
+		Access:    router.PatientAuth,
+		Path:      "patient/profile",
+		Validator: profile,
+		After:     0,
+		Redirect:  "/patient/profile.html",
+	}
+	router.AddPost(b)
+}
+
+func profile(r *http.Request, p *message.Printer) []string {
+	var errors []string
+	data, err := forms.Parse(r)
+	if err != nil {
+		errors = append(errors, p.Sprint("Internal server error"))
+		return errors
+	}
+	val := data.Validator()
+	//
+	if val.HasErrors() {
+		errors = append(errors, val.Messages()...)
+	}
+	return errors
+}
--- /dev/null
+++ b/patient/symptoms.go
@@ -1,0 +1,79 @@
+package forms
+
+import (
+	"net/http"
+	"time"
+
+	"github.com/albrow/forms"
+	"github.com/olmaxmedical/olmax_go/plugins"
+	"github.com/olmaxmedical/olmax_go/router"
+	"golang.org/x/text/message"
+)
+
+func init() {
+	b := &router.Form{
+		Access:    router.PatientAuth,
+		Path:      "patient/symptoms",
+		Validator: symptoms,
+		After:     plugins.EmailForm,
+		Redirect:  "patient/profile.html",
+	}
+	router.AddPost(b)
+}
+
+func symptoms(r *http.Request, p *message.Printer) []string {
+	var errors []string
+	data, err := forms.Parse(r)
+	if err != nil {
+		errors = append(errors, p.Sprint("Internal server error"))
+		return errors
+	}
+	val := data.Validator()
+	// TODO(halfwit): Date must be in a reasonable range
+	val.Require("bday").Message(p.Sprint("Birth date required"))
+	_, err = time.Parse("2006-01-02T15:04:05", r.Form.Get("bday"))
+	if err != nil {
+		val.AddError("bday", p.Sprint("Invalid birth date"))
+	}
+	val.Require("onset").Message(p.Sprint("Please enter the date and time your symptoms started"))
+	_, err = time.Parse("2006-01-02T15:04:05", r.Form.Get("onset"))
+	if err != nil {
+		val.AddError("bday", p.Sprint("Invalid date"))
+	}
+	val.Require("gender").Message(p.Sprint("Please select a biological gender"))
+	if r.PostFormValue("gender") != "male" && r.PostFormValue("gender") != "female" {
+		val.AddError("gender", p.Sprint("Invalid selection for gender"))
+	}
+	val.GreaterOrEqual("duration", 0).Message(p.Sprint("Invalid value entered for how long symptoms have lasted"))
+	val.Require("reason").Message(p.Sprint("Please provide the reason for visit"))
+	val.Require("location").Message(p.Sprint("Please list the area the symptom(s) appear"))
+	val.Require("characteristic").Message(p.Sprint("Please provide a description of your symptoms"))
+	val.Require("aggreAlevi").Message(p.Sprint("Please note anything which improves/worsens your symptoms"))
+	for _, i := range []string{
+		"feversChills",
+		"wtGainLoss",
+		"vision",
+		"lung",
+		"heart",
+		"bowel",
+		"renal",
+		"musSkel",
+		"neuro",
+		"psych",
+	} {
+		sel, ok := r.Form[i]
+		if !ok {
+			val.AddError(i, p.Sprintf("No selection for %s", i))
+			continue
+		}
+		if sel[0] == "Yes" || sel[0] == "yes" || sel[0] == "no" || sel[0] == "No" {
+			continue
+		}
+		val.AddError(i, p.Sprintf("Invalid selection for %s", i))
+	}
+	r.Form["pagetitle"] = []string{"Client symptoms"}
+	if val.HasErrors() {
+		errors = append(errors, val.Messages()...)
+	}
+	return errors
+}
--- /dev/null
+++ b/resetpassword.go
@@ -1,0 +1,37 @@
+package forms
+
+import (
+	"net/http"
+
+	"github.com/albrow/forms"
+	"github.com/olmaxmedical/olmax_go/plugins"
+	"github.com/olmaxmedical/olmax_go/router"
+	"golang.org/x/text/message"
+)
+
+func init() {
+	b := &router.Form{
+		Access:    router.GuestAuth,
+		Path:      "resetpassword",
+		Validator: reset,
+		Redirect:  "/login.html",
+		After:     plugins.ResetPassword,
+	}
+	router.AddPost(b)
+}
+
+func reset(r *http.Request, p *message.Printer) []string {
+	var errors []string
+	data, err := forms.Parse(r)
+	if err != nil {
+		errors = append(errors, "Internal server error")
+		return errors
+	}
+	val := data.Validator()
+	val.Require("email").Message(p.Sprintf("Valid email required"))
+	val.MatchEmail("email").Message(p.Sprintf("Invalid email"))
+	if val.HasErrors() {
+		errors = append(errors, val.Messages()...)
+	}
+	return errors
+}
--- /dev/null
+++ b/signup.go
@@ -1,0 +1,43 @@
+package forms
+
+import (
+	"net/http"
+
+	"github.com/albrow/forms"
+	"github.com/olmaxmedical/olmax_go/plugins"
+	"github.com/olmaxmedical/olmax_go/router"
+	"golang.org/x/text/message"
+)
+
+func init() {
+	b := &router.Form{
+		Access:    router.GuestAuth,
+		Path:      "signup",
+		Validator: signin,
+		Redirect:  "/login.html",
+		After:     plugins.SendSignup,
+	}
+	router.AddPost(b)
+}
+
+func signin(r *http.Request, p *message.Printer) []string {
+	var errors []string
+	data, err := forms.Parse(r)
+	if err != nil {
+		errors = append(errors, "Internal server error")
+		return errors
+	}
+	val := data.Validator()
+	val.Require("fname").Message(p.Sprintf("First name required"))
+	val.MinLength("fname", 2).Message(p.Sprintf("First name must be at least 2 characters"))
+	val.Require("lname").Message(p.Sprintf("Last name required"))
+	val.MinLength("lname", 2).Message(p.Sprintf("Last name must be at least 2 characters"))
+	val.Require("email").Message(p.Sprintf("Valid email required"))
+	val.MatchEmail("email").Message(p.Sprintf("Invalid email"))
+	val.Require("pass").Message(p.Sprintf("Password required"))
+	val.MinLength("pass", 8).Message(p.Sprintf("Password must be at least 8 characters"))
+	if val.HasErrors() {
+		errors = append(errors, val.Messages()...)
+	}
+	return errors
+}