From c0ef92fa945bde0a163135c45026f49a5a4a4ee2 Mon Sep 17 00:00:00 2001 From: Paul Date: Sun, 19 Jul 2020 11:52:26 +0200 Subject: [PATCH] add pretty register endpoint --- Makefile | 1 + .../jordan-harrison-1208586-unsplash.jpg | 3 + assets/templates/layouts/auth_2fa.html | 48 ++++++++++ assets/templates/layouts/auth_authorize.html | 64 +++++++++++++ assets/templates/layouts/auth_login.tmpl | 94 ++++++++++++++++--- assets/templates/layouts/auth_register.tmpl | 61 ++++++++++++ .../templates/layouts/auth_set-password.tmpl | 61 ++++++++++++ assets/templates/layouts/landing.tmpl | 3 + internal/templates/templates.go | 2 - internal/web/handlers_auth.go | 25 +++++ internal/web/routes.go | 3 + 11 files changed, 352 insertions(+), 13 deletions(-) create mode 100644 assets/static/images/jordan-harrison-1208586-unsplash.jpg create mode 100644 assets/templates/layouts/auth_2fa.html create mode 100644 assets/templates/layouts/auth_authorize.html create mode 100644 assets/templates/layouts/auth_register.tmpl create mode 100644 assets/templates/layouts/auth_set-password.tmpl diff --git a/Makefile b/Makefile index 7ab5cf5..71f3db8 100644 --- a/Makefile +++ b/Makefile @@ -6,6 +6,7 @@ MODD=modd include .env +# make all these env vars available for executed processes VARS:=$(shell sed -ne 's/ *\#.*$$//; /./ s/=.*$$// p' .env ) $(foreach v,$(VARS),$(eval $(shell echo export $(v)="$($(v))"))) diff --git a/assets/static/images/jordan-harrison-1208586-unsplash.jpg b/assets/static/images/jordan-harrison-1208586-unsplash.jpg new file mode 100644 index 0000000..34c19a5 --- /dev/null +++ b/assets/static/images/jordan-harrison-1208586-unsplash.jpg @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:64b68f6ecba68970d1ca4384db7b694f9691929c3da5031dbd4dd4aff494f840 +size 36118 diff --git a/assets/templates/layouts/auth_2fa.html b/assets/templates/layouts/auth_2fa.html new file mode 100644 index 0000000..d5628ba --- /dev/null +++ b/assets/templates/layouts/auth_2fa.html @@ -0,0 +1,48 @@ + + + + + + + + + + Log In + + + +
+
+
+
+
+
+

Log in

+
+ You have two-factor authentication enabled on this account. Use your TOTP app to + generate a code. +
+
+ + +
+
+ +
+

+ +

+
+
+
+
+
+
+
+
+ + + \ No newline at end of file diff --git a/assets/templates/layouts/auth_authorize.html b/assets/templates/layouts/auth_authorize.html new file mode 100644 index 0000000..3ab8ea7 --- /dev/null +++ b/assets/templates/layouts/auth_authorize.html @@ -0,0 +1,64 @@ + + + + + + + + + + Log In + + + +
+
+
+
+
+

Hey {{.Username}}! {{.Appname}} + requests your permission to connect with your {{.IDPName}} account.

+
+

Authorize

+
+

Allow {{.Appname}} to:

+
    +
  • See my {{.IDPName}} username and signup date.
  • +
  • See my email address.
  • +
  • See my access groups and permissions.
  • +
  • Keep this access for 15 minutes.
  • +
  • Maintain this access indefinitely (or until manually revoked).
  • +
+
+
+ + + + + + + +
+

+ +

+

+ +

+
+ +
+
+
+
+
+
+
+ + + \ No newline at end of file diff --git a/assets/templates/layouts/auth_login.tmpl b/assets/templates/layouts/auth_login.tmpl index cd8b7ae..8061e9f 100644 --- a/assets/templates/layouts/auth_login.tmpl +++ b/assets/templates/layouts/auth_login.tmpl @@ -5,20 +5,92 @@ - Landing Page + + + Log In -

Login

- {{- range .Errors }} -

{{ . }}

- {{- end }} -
- - - {{ .csrfField }} - -
+
+
+
+
+
+ {{- range $i, $error := .Errors }} +
+ + {{ $error }} +
+ {{- end }} +
+

{{ i18n "de_DE" "Log in" }}

+
+
+
+ +
+
+
+
+ +
+
+
+ +
+
+
+ +
+
+
+
+
+
+
+
+ + {{ .csrf_token }} + + + + + + + + +
+

+ +

+
+
+
+
+ Don't have an account? + Sign Up +
+
+
+
+
+
+ + \ No newline at end of file diff --git a/assets/templates/layouts/auth_register.tmpl b/assets/templates/layouts/auth_register.tmpl new file mode 100644 index 0000000..bc8d249 --- /dev/null +++ b/assets/templates/layouts/auth_register.tmpl @@ -0,0 +1,61 @@ + + + + + + + + + + Log In + + + +
+
+
+
+
+
+

Create Account

+
+
+
+ +
+
+
+
+
+

The invitation link will be sent to this address

+
+
+
+ + + + + + + + +
+

+ +

+
+
+
+
+
+
+
+
+ + + \ No newline at end of file diff --git a/assets/templates/layouts/auth_set-password.tmpl b/assets/templates/layouts/auth_set-password.tmpl new file mode 100644 index 0000000..a7016e9 --- /dev/null +++ b/assets/templates/layouts/auth_set-password.tmpl @@ -0,0 +1,61 @@ + + + + + + + + + + Log In + + + +
+
+
+
+
+
+

Set password

+
+
+
+ +
+
+
+
+
+
+
+
+
+ +
+
+
+
+
+
+
+ + +
+

+ +

+
+
+
+
+
+
+
+
+ + + \ No newline at end of file diff --git a/assets/templates/layouts/landing.tmpl b/assets/templates/layouts/landing.tmpl index 2812abe..56fe54f 100644 --- a/assets/templates/layouts/landing.tmpl +++ b/assets/templates/layouts/landing.tmpl @@ -6,6 +6,9 @@ Landing Page + + diff --git a/internal/templates/templates.go b/internal/templates/templates.go index e2a81d9..a91b4cf 100644 --- a/internal/templates/templates.go +++ b/internal/templates/templates.go @@ -25,14 +25,12 @@ func LoadTemplatesFS(fs http.FileSystem, dir string) Templates { if err != nil { log.Fatal(err) } - //log.Printf("Loaded %d layouts", len(layouts)) includes, err := vfspath.Glob(fs, dir+"/includes/*.tmpl") if err != nil { log.Fatal(err) } - //log.Printf("Loaded %d includes", len(includes)) funcs := getFuncMap() // generate function map diff --git a/internal/web/handlers_auth.go b/internal/web/handlers_auth.go index 2319c7e..65390cf 100644 --- a/internal/web/handlers_auth.go +++ b/internal/web/handlers_auth.go @@ -104,3 +104,28 @@ func (h *Handlers) LoginPageHandler(w http.ResponseWriter, r *http.Request) { h.Templates().Get("auth_login.tmpl").Execute(w, h.commonRenderContext(r)) } + +// RegisterPageHandler renders the login page, and sets session cookies +// on successful authentication. +func (h *Handlers) RegisterPageHandler(w http.ResponseWriter, r *http.Request) { + if r.Method == http.MethodPost { + type RegisterForm struct { + Email string + } + + registerForm := RegisterForm{ + Email: r.PostFormValue("email"), + } + _ = registerForm + + { + context := h.commonRenderContext(r) + context["Errors"] = []string{"registration disabled"} + h.Templates().Get("auth_register.tmpl").Execute(w, context) + return + } + + } + + h.Templates().Get("auth_register.tmpl").Execute(w, h.commonRenderContext(r)) +} diff --git a/internal/web/routes.go b/internal/web/routes.go index 5b79c4a..894b250 100644 --- a/internal/web/routes.go +++ b/internal/web/routes.go @@ -23,6 +23,9 @@ func registerRoutes(ac *app.App, r chi.Router) { r.Get("/login", h.LoginPageHandler) r.Post("/login", h.LoginPageHandler) + r.Get("/signup", h.RegisterPageHandler) + r.Post("/signup", h.RegisterPageHandler) + r.Get("/", h.LandingPageHandler) r.Route("/app", func(r chi.Router) {