Add registration

This commit is contained in:
Jan Bader 2016-12-20 13:34:34 +01:00
parent cb6558a8ce
commit 7b235f83ad
2 changed files with 60 additions and 0 deletions

View File

@ -29,6 +29,7 @@ func (h *Handler) Serve() {
router.GET("/", func(c *gin.Context) { c.HTML(http.StatusOK, "index", nil) })
router.GET("/login", h.login)
router.GET("/register", h.register)
api := router.Group("/api/v1")
{
api.GET("/logout", logout)
@ -85,6 +86,15 @@ func (h *Handler) login(c *gin.Context) {
c.HTML(http.StatusOK, "login", nil)
}
func (h *Handler) register(c *gin.Context) {
if _, err := h.verifyLogin(c); err == nil {
c.Redirect(http.StatusTemporaryRedirect, "/api/v1/hello")
return
}
c.HTML(http.StatusOK, "register", nil)
}
func logout(c *gin.Context) {
clearLogin(c)
}

50
templates/register.html Normal file
View File

@ -0,0 +1,50 @@
{{define "register"}}
<!DOCTYPE html>
<html>
<head>
<title>Registration</title>
{{template "head"}}
<script>
$(document).ready(function() {
$('#invalidCredentials').hide();
$('#loginForm').ajaxForm({
success: function() {
window.location.href = "/api/v1/restricted";
},
error: function() {
$('#invalidCredentials').show();
}
});
});
</script>
</head>
<body>
<div class="container" id="head">
Budgeteer
</div>
<div class="container col-lg-12" id="content">
<form id="loginForm" action="/api/v1/login" method="POST" class="center-block">
<label for="email">E-Mail</label>
<input type="text" name="email" /><br />
<label for="name">Name</label>
<input type="text" name="name" /><br />
<label for="password">Password</label>
<input type="password" name="password" /><br />
<label for="password">Verify Password</label>
<input type="password" /><br />
<div id="invalidCredentials">
The entered credentials are invalid
</div>
<input type="submit" value="Login" />
</form>
</div>
</body>
</html>
{{end}}