Skip to content

Commit

Permalink
implement login form for better ux
Browse files Browse the repository at this point in the history
  • Loading branch information
splattner committed Dec 17, 2024
1 parent 094b64e commit 1d8c705
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 11 deletions.
10 changes: 6 additions & 4 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import (

// templates parses the specified templates and caches the parsed results
// to help speed up response times.
var templates = template.Must(template.ParseFiles("./templates/base.html", "./templates/body.html"))
var templates = template.Must(template.ParseFiles("./templates/base.html", "./templates/body.html", "./templates/login.html"))

var labelSelector = "acend-userconfig=true"
var usernameKey = "username"
Expand Down Expand Up @@ -48,12 +48,14 @@ func logging(next http.Handler) http.Handler {
func index(teacher bool) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {

log.Println(r)

if !teacher {
t := r.URL.Query().Get("token")
if token != "" && t != token {
http.Error(w, fmt.Sprintf("you are not allowed to access this page"), http.StatusForbidden)
if err := templates.ExecuteTemplate(w, "login", nil); err != nil {
http.Error(w, fmt.Sprintf("index: couldn't parse template: %v", err), http.StatusInternalServerError)
return
}
w.WriteHeader(http.StatusOK)
return
}
}
Expand Down
8 changes: 2 additions & 6 deletions templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
<html>
<head>
<title>Welcome to your Training</title>
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-T3c6CoIi6uLrA9TneNEoa7RxnatzjcDSCmG1MXxSR1GAsXEV/Dwwykc2MPK8M2HN" crossorigin="anonymous">
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js" integrity="sha384-C6RzsynM9kWDrMNeT87bh95OGNyZPhcTNXj1NW7RuBCsyN/o0jlpcV8Qyq46cDfL" crossorigin="anonymous"></script>
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-QWTKZyjpPEjISv5WaRU9OFeRpok6YctnYmDr5pNlyT2bRjXh0JMhjY6hW+ALEwIH" crossorigin="anonymous">

<link href="public/main.css" rel="stylesheet">

Expand All @@ -17,10 +16,7 @@
<body>

{{template "body" .}}
<script>


</script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js" integrity="sha384-YvpcrYf0tY3lHB60NNkmXc5s9fDVZLESaAA55NDzOxhy9GkcIdslK1eN7N6jIeHz" crossorigin="anonymous"></script>
</body>
</html>

Expand Down
1 change: 0 additions & 1 deletion templates/body.html
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ <h2>Webshells</h2>
<td>
Username: {{ .Username }}<br />
Namespace: {{ .Username }}<br &>
Azure Account: {{ .Username }}@acend.onmicrosoft.com
</td>
<td>
<span id="password{{ .Username }}">{{ .Password }}</span>
Expand Down
44 changes: 44 additions & 0 deletions templates/login.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
{{define "login"}}
<!DOCTYPE html>
<html>
<head>
<title>Welcome to your Training</title>
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-QWTKZyjpPEjISv5WaRU9OFeRpok6YctnYmDr5pNlyT2bRjXh0JMhjY6hW+ALEwIH" crossorigin="anonymous">

<link href="public/main.css" rel="stylesheet">

<link rel="shortcut icon" href="public/images/favicon.png" type="image/x-icon">
<link rel="icon" href="public/images/favicon.png" type="image/x-icon">

<script src="https://code.iconify.design/iconify-icon/1.0.7/iconify-icon.min.js"></script>

</head>
<body>

<h1 >Welcome to your acend training</h1>

<form action="/" method="GET" class="row row-cols-lg-auto g-3 align-items-center">
<div class="col-auto">
<label class="col-form-label" for="token">Token</label>
</div>
<div class="col-auto">
<div class="input-group">
<input type="text" name="token" class="form-control" id="token" aria-describedby="tokenHint">
</div>
</div>

<div class="col-auto">
<span id="tokenHint" class="form-text">
Token is given by your teacher
</span>
</div>

<div class="col-auto">
<button type="submit" class="btn btn-primary">Start your Training</button>
</div>
</form>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js" integrity="sha384-YvpcrYf0tY3lHB60NNkmXc5s9fDVZLESaAA55NDzOxhy9GkcIdslK1eN7N6jIeHz" crossorigin="anonymous"></script>
</body>
</html>

{{end}}

0 comments on commit 1d8c705

Please sign in to comment.