ref: 5ec0dbebf967f911bc1c01318902dc8a7db8d169
parent: 9f5534beb027b614303c19567a5acf32a3685b73
author: Michael Misch <michaelmisch1985@gmail.com>
date: Wed Nov 13 12:22:51 PST 2019
Unbreak sessions
--- a/email/signup.go
+++ b/email/signup.go
@@ -13,8 +13,8 @@
"golang.org/x/text/message"
)
-// This will change!
-var url = "http://192.168.1.101"
+// TODO(halfwit) Update with whichever TLD we land on
+var url = "https://olmaxmedical.com"
// SendSignup - email our prospective clients and create tokens
func SendSignup(first, last, email, pass string, p *message.Printer) {
--- a/forms/patient/symptoms.go
+++ b/forms/patient/symptoms.go
@@ -15,7 +15,7 @@
Access: router.PatientAuth,
Path: "patient/symptoms",
Validator: symptoms,
- After: plugins.EmailForm | plugins.MakeOffer,
+ After: plugins.EmailForm,
Redirect: "patient/profile.html",
}
router.AddPost(b)
--- a/pages/index.go
+++ b/pages/index.go
@@ -1,7 +1,6 @@
package pages
import (
- "github.com/olmaxmedical/olmax_go/plugins"
"github.com/olmaxmedical/olmax_go/router"
"golang.org/x/text/message"
)
@@ -12,7 +11,7 @@
CSS: "index.css",
Path: "index",
Data: index,
- Extra: plugins.ListDoctors | plugins.FormErrors,
+ Extra: 0,
}
router.AddPage(b)
}
--- a/plugins/appointments.go
+++ b/plugins/appointments.go
@@ -1,20 +1,22 @@
package plugins
-import "github.com/olmaxmedical/olmax_go/router"
+import (
+ "github.com/olmaxmedical/olmax_go/router"
+)
// AddAppointment registers an appointment into the appointment book
// TODO(halfwit) message/email client to fill out Symptoms form
-const AddAppointment router.PluginMask = 1
+const AddAppointment router.PluginMask = 1 << 15
func init() {
b := &router.Plugin{
Name: "Add Appointments",
Run: nil,
- Validate: addAppointment,
+ Validate: addAppt,
}
router.AddPlugin(b, AddAppointment)
}
-func addAppointment(s *router.Request) error {
+func addAppt(s *router.Request) error {
return nil
}
--- a/plugins/countries.go
+++ b/plugins/countries.go
@@ -11,7 +11,7 @@
)
// Countries - Populate a localized spinner to select country
-const Countries router.PluginMask = 2
+const Countries router.PluginMask = 1 << 2
// Country - Mapping token to internationalized country code
type Country struct {
@@ -36,7 +36,7 @@
}
sort.Sort(cache)
b := &router.Plugin{
- Name: "countrylist",
+ Name: "country",
Run: listCountries,
Validate: validateCountries,
}
--- a/plugins/doctor.go
+++ b/plugins/doctor.go
@@ -5,7 +5,7 @@
)
// ListDoctors - Bitmask to list doctors of in client country
-const ListDoctors router.PluginMask = 3
+const ListDoctors router.PluginMask = 1 << 3
type doctor struct {
Image string
--- a/plugins/email.go
+++ b/plugins/email.go
@@ -10,29 +10,29 @@
)
// EmailForm - Patient form to gmail
-const EmailForm router.PluginMask = 4
+const EmailForm router.PluginMask = 1 << 4
// SendSignup - Send account creation validation email
-const SendSignup router.PluginMask = 5
+const SendSignup router.PluginMask = 1 << 5
// SendReset - Send password reset email
-const SendReset router.PluginMask = 6
+const SendReset router.PluginMask = 1 << 6
func init() {
b := &router.Plugin{
- Name: "Email client information form",
+ Name: "emailform",
Run: nil,
Validate: emailForm,
}
router.AddPlugin(b, EmailForm)
c := &router.Plugin{
- Name: "Send signup email",
+ Name: "signupEmail",
Run: nil,
Validate: signupEmail,
}
router.AddPlugin(c, SendSignup)
d := &router.Plugin{
- Name: "Send password reset email",
+ Name: "resetPassword",
Run: nil,
Validate: resetPassword,
}
--- a/plugins/errors.go
+++ b/plugins/errors.go
@@ -5,11 +5,11 @@
)
// FormErrors - A list of errors present on a POST request
-const FormErrors router.PluginMask = 7
+const FormErrors router.PluginMask = 1 << 7
func init() {
b := &router.Plugin{
- Name: "Form Errors",
+ Name: "errors",
Run: GetFormErrors,
Validate: nil,
}
--- a/plugins/offers.go
+++ b/plugins/offers.go
@@ -3,7 +3,7 @@
import "github.com/olmaxmedical/olmax_go/router"
// MakeOffer - Request a time slot with doctor
-const MakeOffer router.PluginMask = 8
+const MakeOffer router.PluginMask = 1 << 8
func init() {
b := &router.Plugin{
--- a/plugins/password.go
+++ b/plugins/password.go
@@ -8,20 +8,20 @@
)
// ValidateLogin - Check user/pass combo exists
-const ValidateLogin router.PluginMask = 9
+const ValidateLogin router.PluginMask = 1 << 9
// ResetPassword - Update database entry for password
-const ResetPassword router.PluginMask = 10
+const ResetPassword router.PluginMask = 1 << 10
func init() {
b := &router.Plugin{
- Name: "Validate login",
+ Name: "login",
Run: nil,
Validate: login,
}
router.AddPlugin(b, ValidateLogin)
c := &router.Plugin{
- Name: "Set password",
+ Name: "setPassword",
Run: nil,
Validate: setPass,
}
--- a/plugins/search.go
+++ b/plugins/search.go
@@ -3,11 +3,11 @@
import "github.com/olmaxmedical/olmax_go/router"
// Search - generic search for doctors in area
-const Search router.PluginMask = 11
+const Search router.PluginMask = 1 << 11
func init() {
b := &router.Plugin{
- Name: "Search",
+ Name: "search",
Run: nil,
Validate: search,
}
--- a/plugins/services.go
+++ b/plugins/services.go
@@ -7,7 +7,7 @@
)
// Services - Bitmask to list services in native language
-const Services router.PluginMask = 12
+const Services router.PluginMask = 1 << 12
func init() {
b := &router.Plugin{
--- a/plugins/tokens.go
+++ b/plugins/tokens.go
@@ -7,13 +7,14 @@
"github.com/olmaxmedical/olmax_go/router"
)
+//TODO(halfwit) Set up in memory tokens in db as well as
var tokens []string
// SessionToken - An in-memory token to allow a client to track
-const SessionToken router.PluginMask = 13
+const SessionToken router.PluginMask = 1 << 13
// FormToken - A database-persisted one time use token to relate forms to POST requests
-const FormToken router.PluginMask = 14
+const FormToken router.PluginMask = 1 << 14
func init() {
b := &router.Plugin{
--- a/router/forms.go
+++ b/router/forms.go
@@ -27,6 +27,10 @@
formlist[f.Path+".html"] = f
}
+// We want do redo this logic top down instead
+// Set a message in the plugin itself as the return error message
+// And on error, use it
+
func parseform(p *Request, w http.ResponseWriter, r *http.Request) (*Form, []string) {
var errors []string
form, ok := formlist[p.path]
@@ -37,16 +41,14 @@
if errs := form.Validator(r, p.printer); len(errs) > 0 {
return nil, errs
}
- var errlist []error
for _, key := range pluginKey {
if (form.After&key) != 0 && pluginCache[key].Validate != nil {
if e := pluginCache[key].Validate(p); e != nil {
- errlist = append(errlist, e)
+ fmt.Fprintf(w, "%q\n", e)
+ errors = append(errors, fmt.Sprint(e))
+ return nil, errors
}
}
- }
- if len(errlist) > 0 {
- errors = append(errors, fmt.Sprint(errlist))
}
return form, errors
}
--- a/router/pages.go
+++ b/router/pages.go
@@ -89,8 +89,7 @@
r["header"] = header(p.printer, p.status)
r["footer"] = footer(p.printer)
r["basedir"] = getBaseDir(cache.Path)
- // TODO(halfwit) test running each of these in a goroutine
- // As n increases
+ // TODO(halfwit) Test chunking in to go routines if n gets too large
for _, key := range pluginKey {
if (cache.Extra&key) != 0 && pluginCache[key].Run != nil {
r[pluginCache[key].Name] = pluginCache[key].Run(p)
--- a/router/plugins.go
+++ b/router/plugins.go
@@ -8,7 +8,7 @@
type PluginMask uint32
// DEAD is a magic string to indicate a non-unique plugin key
-const DEAD PluginMask = 0x0666000
+const DEAD PluginMask = 1
var pluginCache map[PluginMask]*Plugin
var pluginKey []PluginMask