add pretty register endpoint

This commit is contained in:
paul 2020-07-19 11:52:26 +02:00
parent 28f5a12f94
commit c0ef92fa94
11 changed files with 352 additions and 13 deletions

View file

@ -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))")))

View file

@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:64b68f6ecba68970d1ca4384db7b694f9691929c3da5031dbd4dd4aff494f840
size 36118

View file

@ -0,0 +1,48 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bulma/0.7.2/css/bulma.min.css" integrity="sha256-2pUeJf+y0ltRPSbKOeJh09ipQFYxUdct5nTY6GAXswA="
crossorigin="anonymous" />
<link rel="stylesheet" href="style.css">
<title>Log In</title>
</head>
<body>
<div class="hero is-success is-fullheight auth-background">
<div class="hero-body">
<div class="container">
<div class="columns">
<div class="column is-one-third-desktop is-offset-one-third-desktop is-half-tablet is-offset-one-quarter-tablet">
<div class="content box">
<h2 class="has-text-centered is-size-3">Log in</h2>
<div class="notification">
You have two-factor authentication enabled on this account. Use your TOTP app to
generate a code.
</div>
<form class="form" action="authorize.html">
<input type="hidden" name="next" value="">
<input type="hidden" name="csrf_token" value="">
<div class="field has-addons">
<div class="control is-expanded">
<input id="code" class="input is-large is-uppercase is-family-code is-expanded" type="text" name="code" autofocus="autofocus" >
</div>
<p class="control">
<button class="button is-large is-fullwidth is-success" value="authorize" type="submit">
Check Code
</button>
</p>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
</div>
</body>
</html>

View file

@ -0,0 +1,64 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bulma/0.7.2/css/bulma.min.css" integrity="sha256-2pUeJf+y0ltRPSbKOeJh09ipQFYxUdct5nTY6GAXswA="
crossorigin="anonymous" />
<link rel="stylesheet" href="style.css">
<title>Log In</title>
</head>
<body>
<div class="hero is-success is-fullheight auth-background">
<div class="hero-body">
<div class="container">
<div class="columns">
<div class="column is-one-third-desktop is-offset-one-third-desktop is-half-tablet is-offset-one-quarter-tablet">
<p class="subtitle is-size-5">Hey <strong>{{.Username}}</strong>! <strong>{{.Appname}}</strong>
requests your permission to connect with your {{.IDPName}} account.</p>
<div class="content box">
<h2 class="has-text-centered is-size-3">Authorize</h2>
<div class="notification content">
<p>Allow <strong>{{.Appname}}</strong> to:</p>
<ul>
<li>See my {{.IDPName}} username and signup date.</li>
<li>See my email address.</li>
<li>See my access groups and permissions.</li>
<li>Keep this access for 15 minutes.</li>
<li>Maintain this access indefinitely (or until manually revoked).</li>
</ul>
</div>
<form class="form" action="">
<input type="hidden" name="client_id" value="">
<input type="hidden" name="redirect_uri" value="">
<input type="hidden" name="scope" value="">
<input type="hidden" name="state" value="">
<input type="hidden" name="response_type" value="">
<input type="hidden" name="duration" value="">
<input type="hidden" name="csrf_token" value="">
<div class="field is-grouped is-grouped-right">
<p class="control">
<button class="button is-medium is-fullwidth is-warning" value="authorize" type="submit">
Allow Access
</button>
</p>
<p class="control">
<button class="button is-medium is-fullwidth" value="authorize" type="submit">
Cancel
</button>
</p>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
</div>
</body>
</html>

View file

@ -5,20 +5,92 @@
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Landing Page</title>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bulma/0.8.0/css/bulma.min.css"
integrity="sha256-D9M5yrVDqFlla7nlELDaYZIpXfFWDytQtiV+TaH6F1I=" crossorigin="anonymous" />
<link rel="stylesheet" href="{{ static "css/style.css" }}">
<title>Log In</title>
</head>
<body>
<h1>Login</h1>
{{- range .Errors }}
<p class="is-error">{{ . }}</p>
{{- end }}
<form action="/login" method="post">
<input type="email" name="login" required>
<input type="password" name="password" required>
{{ .csrfField }}
<input type="submit" value="Log In">
</form>
<div class="hero is-success is-fullheight auth-background">
<div class="hero-body">
<div class="container">
<div class="columns">
<div
class="column is-one-third-desktop is-offset-one-third-desktop is-half-tablet is-offset-one-quarter-tablet">
{{- range $i, $error := .Errors }}
<div class="notification is-warning">
<button class="delete"></button>
{{ $error }}
</div>
{{- end }}
<div class="content box">
<h2 class="has-text-centered is-size-3">{{ i18n "de_DE" "Log in" }}</h2>
<form class="form" method="POST" action="{{ url "login" }}">
<div class="field is-horizontal">
<div class="field-label">
<label for="" class="label">username</label>
</div>
<div class="field-body">
<div class="field">
<div class="control">
<input id="" class="input" type="text" name="" autofocus="autofocus">
</div>
</div>
</div>
</div>
<div class="field is-horizontal">
<div class="field-label">
<label for="" class="label">password</label>
</div>
<div class="field-body">
<div class="field">
<div class="control"><input type="password" name="" id="" class="input">
</div>
</div>
</div>
</div>
{{ .csrf_token }}
<input type="hidden" name="client_id" value="">
<input type="hidden" name="redirect_uri" value="">
<input type="hidden" name="scope" value="">
<input type="hidden" name="state" value="">
<input type="hidden" name="response_type" value="">
<input type="hidden" name="duration" value="">
<input type="hidden" name="csrf_token" value="">
<div class="field is-grouped is-grouped-right">
<p class="control">
<button class="button is-medium is-fullwidth is-success" value="authorize"
type="submit">
Log in
</button>
</p>
</div>
</form>
</div>
<div class="has-text-light-grey has-text-centered">
Don't have an account?
<a class="has-text-white has-text-weight-bold" href="{{ url "register" }}">Sign Up</a>
</div>
</div>
</div>
</div>
</div>
</div>
<script>
document.addEventListener('DOMContentLoaded', () => {
(document.querySelectorAll('.notification .delete') || []).forEach(($delete) => {
$notification = $delete.parentNode;
$delete.addEventListener('click', () => {
$notification.parentNode.removeChild($notification);
});
});
});
</script>
</body>
</html>

View file

@ -0,0 +1,61 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bulma/0.8.0/css/bulma.min.css"
integrity="sha256-D9M5yrVDqFlla7nlELDaYZIpXfFWDytQtiV+TaH6F1I=" crossorigin="anonymous" />
<link rel="stylesheet" href="{{ static "css/style.css" }}">
<title>Log In</title>
</head>
<body>
<div class="hero is-success is-fullheight auth-background">
<div class="hero-body">
<div class="container">
<div class="columns">
<div
class="column is-one-third-desktop is-offset-one-third-desktop is-half-tablet is-offset-one-quarter-tablet">
<div class="content box">
<h2 class="has-text-centered is-size-3">Create Account</h2>
<form class="form" method="POST" action="{{ url "/register" }}">
<div class="field is-horizontal">
<div class="field-label is-normal">
<label for="" class="label">email</label>
</div>
<div class="field-body">
<div class="field">
<div class="control"><input type="text" name="email" id="" class="input">
</div>
<p class="help">The invitation link will be sent to this address</p>
</div>
</div>
</div>
<input type="hidden" name="client_id" value="">
<input type="hidden" name="redirect_uri" value="">
<input type="hidden" name="scope" value="">
<input type="hidden" name="state" value="">
<input type="hidden" name="response_type" value="">
<input type="hidden" name="duration" value="">
<input type="hidden" name="csrf_token" value="">
<div class="field is-grouped is-grouped-right">
<p class="control">
<button class="button is-medium is-fullwidth is-success" value="authorize"
type="submit">
Request invitation
</button>
</p>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
</div>
</body>
</html>

View file

@ -0,0 +1,61 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bulma/0.7.2/css/bulma.min.css" integrity="sha256-2pUeJf+y0ltRPSbKOeJh09ipQFYxUdct5nTY6GAXswA="
crossorigin="anonymous" />
<link rel="stylesheet" href="style.css">
<title>Log In</title>
</head>
<body>
<div class="hero is-success is-fullheight auth-background">
<div class="hero-body">
<div class="container">
<div class="columns">
<div class="column is-one-third-desktop is-offset-one-third-desktop is-half-tablet is-offset-one-quarter-tablet">
<div class="content box">
<h2 class="has-text-centered is-size-3">Set password</h2>
<form class="form" action="login.html">
<div class="field is-horizontal">
<div class="field-label">
<label for="" class="label">password</label>
</div>
<div class="field-body">
<div class="field">
<div class="control"><input type="password" name="" id="" class="input"></div>
</div>
</div>
</div>
<div class="field is-horizontal">
<div class="field-label">
<label for="" class="label">confirm</label>
</div>
<div class="field-body">
<div class="field">
<div class="control"><input type="password" name="" id="" class="input"></div>
</div>
</div>
</div>
<input type="hidden" name="csrf_token" value="">
<div class="field is-grouped is-grouped-right">
<p class="control">
<button class="button is-medium is-fullwidth is-success" value="authorize" type="submit">
Set Password
</button>
</p>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
</div>
</body>
</html>

View file

@ -6,6 +6,9 @@
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Landing Page</title>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bulma/0.8.0/css/bulma.min.css"
integrity="sha256-D9M5yrVDqFlla7nlELDaYZIpXfFWDytQtiV+TaH6F1I=" crossorigin="anonymous" />
<link rel="stylesheet" href="/static/css/style.css">
</head>
<body>

View file

@ -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

View file

@ -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))
}

View file

@ -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) {