1
0
mirror of https://github.com/hrfee/jfa-go.git synced 2024-12-22 09:00:10 +00:00

Partial check for invite page, 404 handling

The invite route no longer calls checkInvite, instead just chekcing the
invite exists. This speeds up page loading. the 404 and invalidCode
pages are now loaded when necessary.
This commit is contained in:
Harvey Tindall 2020-07-31 13:03:36 +01:00
parent 961b9afa75
commit e5ebcef684
5 changed files with 31 additions and 18 deletions

View File

@ -13,16 +13,16 @@
<meta name="theme-color" content="#ffffff">
<title>404</title>
<link rel="stylesheet" type="text/css" href="{{ css_file }}">
{% if not bs5 %}
<link rel="stylesheet" type="text/css" href="{{ .cssFile }}">
{{ if not .bs5 }}
<script src="https://code.jquery.com/jquery-3.5.1.slim.min.js" integrity="sha384-DfXdz2htPH0lsSSs5nCTpuj/zy4C+OGpamoFVy38MVBnE+IbbVYUew+OrCXaRkfj" crossorigin="anonymous"></script>
{% endif %}
{{ end }}
<script src="https://cdn.jsdelivr.net/npm/popper.js@1.16.0/dist/umd/popper.min.js" integrity="sha384-Q6E9RHvbIyZFJoft+2mJbHaEWldlvI9IOYy5n3zV9zzTtmI3UksdQRVvoxMfooAo" crossorigin="anonymous"></script>
{% if bs5 %}
{{ if .bs5 }}
<script src="https://stackpath.bootstrapcdn.com/bootstrap/5.0.0-alpha1/js/bootstrap.min.js" integrity="sha384-oesi62hOLfzrys4LxRF63OJCXdXDipiYWBnvTl9Y9/TRlw5xlKIEHpNyvvDShgf/" crossorigin="anonymous"></script>
{% else %}
{{ else }}
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/js/bootstrap.min.js" integrity="sha384-OgVRvuATP1z7JjHLkuOU7Xw704+h835Lr+6QL9UvYjZE3Ipu6Tp75j7Bh/kR0JKI" crossorigin="anonymous"></script>
{% endif %}
{{ end }}
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
<style>
.messageBox {
@ -34,7 +34,7 @@
<div class="messageBox">
<h1>Page not found.</h1>
<p>
{{ contactMessage }}
{{ .contactMessage }}
</p>
</div>
</body>

View File

@ -5,16 +5,16 @@
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<title>Invalid Code</title>
<!-- Bootstrap CSS -->
<link rel="stylesheet" type="text/css" href="{{ css_file }}">
{% if not bs5 %}
<link rel="stylesheet" type="text/css" href="{{ .cssFile }}">
{{ if not .bs5 }}
<script src="https://code.jquery.com/jquery-3.5.1.slim.min.js" integrity="sha384-DfXdz2htPH0lsSSs5nCTpuj/zy4C+OGpamoFVy38MVBnE+IbbVYUew+OrCXaRkfj" crossorigin="anonymous"></script>
{% endif %}
{{ end }}
<script src="https://cdn.jsdelivr.net/npm/popper.js@1.16.0/dist/umd/popper.min.js" integrity="sha384-Q6E9RHvbIyZFJoft+2mJbHaEWldlvI9IOYy5n3zV9zzTtmI3UksdQRVvoxMfooAo" crossorigin="anonymous"></script>
{% if bs5 %}
{{ if .bs5 }}
<script src="https://stackpath.bootstrapcdn.com/bootstrap/5.0.0-alpha1/js/bootstrap.min.js" integrity="sha384-oesi62hOLfzrys4LxRF63OJCXdXDipiYWBnvTl9Y9/TRlw5xlKIEHpNyvvDShgf/" crossorigin="anonymous"></script>
{% else %}
{{ else }}
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/js/bootstrap.min.js" integrity="sha384-OgVRvuATP1z7JjHLkuOU7Xw704+h835Lr+6QL9UvYjZE3Ipu6Tp75j7Bh/kR0JKI" crossorigin="anonymous"></script>
{% endif %}
{{ end }}
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
<style>
.messageBox {
@ -26,7 +26,7 @@
<div class="messageBox">
<h1>Invalid Code.</h1>
<p>The above code is either incorrect, or has expired.</p>
<p>{{ contactMessage }}</p>
<p>{{ .contactMessage }}</p>
</div>
</body>
</html>

View File

@ -143,6 +143,7 @@ func main() {
router.GET("/getToken", ctx.GetToken)
router.POST("/newUser", ctx.NewUser)
router.GET("/invite/:invCode", ctx.InviteProxy)
router.NoRoute(ctx.NoRouteHandler)
api := router.Group("/", ctx.webAuth())
api.POST("/generateInvite", ctx.GenerateInvite)
api.GET("/getInvites", ctx.GetInvites)

View File

@ -40,7 +40,6 @@ func (vd *Validator) validate(password string) map[string]bool {
}
}
}
fmt.Println(count)
results := map[string]bool{}
for criterion, num := range count {
if num < vd.criteria[criterion] {
@ -49,7 +48,6 @@ func (vd *Validator) validate(password string) map[string]bool {
results[criterion] = true
}
}
fmt.Println(results)
return results
}

View File

@ -20,7 +20,9 @@ func (ctx *appContext) AdminPage(gc *gin.Context) {
func (ctx *appContext) InviteProxy(gc *gin.Context) {
code := gc.Param("invCode")
if ctx.checkInvite(code, false, "") {
/* Don't actually check if the invite is valid, just if it exists, just so the page loads quicker. Invite is actually checked on submit anyway. */
// if ctx.checkInvite(code, false, "") {
if _, ok := ctx.storage.invites[code]; ok {
email := ctx.storage.invites[code].Email
gc.HTML(http.StatusOK, "form.html", gin.H{
"bs5": ctx.config.Section("ui").Key("bs5").MustBool(false),
@ -35,6 +37,18 @@ func (ctx *appContext) InviteProxy(gc *gin.Context) {
"username": !ctx.config.Section("email").Key("no_username").MustBool(false),
})
} else {
respond(401, "Invalid code", gc)
gc.HTML(404, "invalidCode.html", gin.H{
"bs5": ctx.config.Section("ui").Key("bs5").MustBool(false),
"cssFile": ctx.cssFile,
"contactMessage": ctx.config.Section("ui").Key("contac_message").String(),
})
}
}
func (ctx *appContext) NoRouteHandler(gc *gin.Context) {
gc.HTML(404, "404.html", gin.H{
"bs5": ctx.config.Section("ui").Key("bs5").MustBool(false),
"cssFile": ctx.cssFile,
"contactMessage": ctx.config.Section("ui").Key("contact_message").String(),
})
}