diff --git a/cmd/web-app/handlers/routes.go b/cmd/web-app/handlers/routes.go index 1a7b65e..b627d95 100644 --- a/cmd/web-app/handlers/routes.go +++ b/cmd/web-app/handlers/routes.go @@ -40,6 +40,7 @@ func APP(shutdown chan os.Signal, log *log.Logger, env webcontext.Env, staticDir // Construct the web.App which holds all routes as well as common Middleware. app := web.NewApp(shutdown, log, env, middlewares...) + // Register project management pages. p := Projects{ MasterDB: masterDB, @@ -63,6 +64,7 @@ func APP(shutdown chan os.Signal, log *log.Logger, env webcontext.Env, staticDir app.Handle("GET", "/users/:user_id/update", us.Update, mid.AuthenticateSessionRequired(authenticator), mid.HasRole(auth.RoleAdmin)) app.Handle("GET", "/users/:user_id", us.View, mid.AuthenticateSessionRequired(authenticator), mid.HasRole(auth.RoleAdmin)) + // Register user management and authentication endpoints. u := User{ MasterDB: masterDB, @@ -92,6 +94,7 @@ func APP(shutdown chan os.Signal, log *log.Logger, env webcontext.Env, staticDir app.Handle("POST", "/user", u.View, mid.AuthenticateSessionRequired(authenticator), mid.HasAuth()) app.Handle("GET", "/user", u.View, mid.AuthenticateSessionRequired(authenticator), mid.HasAuth()) + // Register account management endpoints. acc := Account{ MasterDB: masterDB, @@ -103,6 +106,7 @@ func APP(shutdown chan os.Signal, log *log.Logger, env webcontext.Env, staticDir app.Handle("POST", "/account", acc.View, mid.AuthenticateSessionRequired(authenticator), mid.HasRole(auth.RoleAdmin)) app.Handle("GET", "/account", acc.View, mid.AuthenticateSessionRequired(authenticator), mid.HasRole(auth.RoleAdmin)) + // Register user management and authentication endpoints. s := Signup{ MasterDB: masterDB, @@ -121,6 +125,7 @@ func APP(shutdown chan os.Signal, log *log.Logger, env webcontext.Env, staticDir app.Handle("GET", "/examples/flash-messages", ex.FlashMessages) app.Handle("GET", "/examples/images", ex.Images) + // Register geo g := Geo{ MasterDB: masterDB, @@ -131,6 +136,7 @@ func APP(shutdown chan os.Signal, log *log.Logger, env webcontext.Env, staticDir app.Handle("GET", "/geo/geonames/postal_code/:postalCode", g.GeonameByPostalCode) app.Handle("GET", "/geo/country/:countryCode/timezones", g.CountryTimezones) + // Register root r := Root{ MasterDB: masterDB, @@ -146,6 +152,7 @@ func APP(shutdown chan os.Signal, log *log.Logger, env webcontext.Env, staticDir app.Handle("GET", "/index.html", r.IndexHtml) app.Handle("GET", "/robots.txt", r.RobotTxt) + // Register health check endpoint. This route is not authenticated. check := Check{ MasterDB: masterDB, @@ -154,6 +161,7 @@ func APP(shutdown chan os.Signal, log *log.Logger, env webcontext.Env, staticDir } app.Handle("GET", "/v1/health", check.Health) + // Handle static files/pages. Render a custom 404 page when file not found. static := func(ctx context.Context, w http.ResponseWriter, r *http.Request, params map[string]string) error { err := web.StaticHandler(ctx, w, r, params, staticDir, "") diff --git a/cmd/web-app/handlers/signup.go b/cmd/web-app/handlers/signup.go index 0a10d8d..43a2a41 100644 --- a/cmd/web-app/handlers/signup.go +++ b/cmd/web-app/handlers/signup.go @@ -112,7 +112,7 @@ func (h *Signup) Step1(ctx context.Context, w http.ResponseWriter, r *http.Reque data["form"] = req - if verr, ok := weberror.NewValidationError(ctx, webcontext.Validator().Struct(signup.SignupRequest{})); ok { + if verr, ok := weberror.NewValidationError(ctx, signup.Validator().Struct(signup.SignupRequest{})); ok { data["validationDefaults"] = verr.(*weberror.Error) } diff --git a/cmd/web-app/templates/content/users-update.gohtml b/cmd/web-app/templates/content/users-update.gohtml new file mode 100644 index 0000000..75a9eda --- /dev/null +++ b/cmd/web-app/templates/content/users-update.gohtml @@ -0,0 +1,83 @@ +{{define "title"}}Update Profile{{end}} +{{define "style"}} + +{{end}} +{{define "content"}} +
+{{end}} +{{define "js"}} + +{{end}} diff --git a/cmd/web-app/templates/content/users-view.gohtml b/cmd/web-app/templates/content/users-view.gohtml new file mode 100644 index 0000000..373eaf6 --- /dev/null +++ b/cmd/web-app/templates/content/users-view.gohtml @@ -0,0 +1,85 @@ +{{define "title"}}Profile{{end}} +{{define "style"}} + +{{end}} +{{define "content"}} ++ {{ .user.Name }} +
+
+ Name
+ {{ .user.Name }}
+
+ Email
+ {{ .user.Email }}
+
+ Timezone
+ {{.user.Timezone }}
+
+ Role
+ {{ if .userAccount }}
+
+ {{ range $r := .userAccount.Roles }}
+ {{ if eq $r "admin" }}
+ {{ $r }}
+ {{else}}
+ {{ $r }}
+ {{end}}
+ {{ end }}
+
+ {{ end }}
+
+ Status
+ {{ if .userAccount }}
+
+ {{ if eq .userAccount.Status.Value "active" }}
+ {{ .userAccount.Status.Title }}
+ {{ else if eq .userAccount.Status.Value "invited" }}
+ {{ .userAccount.Status.Title }}
+ {{else}}
+ {{.userAccount.Status.Title }}
+ {{end}}
+
+ {{ end }}
+
+ ID
+ {{ .user.ID }}
+