fix register and login handler for future edits

This commit is contained in:
Florian Hoss 2022-04-04 09:15:02 +02:00
parent b5f1ccf98d
commit 177a26a2e9
6 changed files with 97 additions and 43 deletions

View file

@ -2,6 +2,7 @@ package webpage
import (
"app/database"
"fmt"
"github.com/gin-contrib/static"
"github.com/gin-gonic/gin"
"net/http"
@ -12,7 +13,7 @@ func (wp *Webpage) defineRoutes() {
wp.Router.GET("/", func(c *gin.Context) {
c.HTML(http.StatusOK, "index.tmpl", gin.H{
"title": "Register",
"title": "SuperSafe",
})
})
wp.Router.GET("/login", func(c *gin.Context) {
@ -35,10 +36,21 @@ func (wp *Webpage) defineRoutes() {
c.Redirect(http.StatusTemporaryRedirect, "/")
})
wp.Router.POST("/login", func(c *gin.Context) {
username, existing := c.GetPostForm("username")
password, existing := c.GetPostForm("password")
if existing == false || username == "" || password == "" {
c.JSON(400, gin.H{"message": "bad post form"})
return
}
fmt.Println(username, password)
c.JSON(200, gin.H{"message": "login successfull"})
})
wp.Router.POST("/register", func(c *gin.Context) {
username, err := c.GetPostForm("username")
password, err := c.GetPostForm("password")
if err == false {
username, existing := c.GetPostForm("username")
password, existing := c.GetPostForm("password")
if existing == false || username == "" || password == "" {
c.JSON(400, gin.H{"message": "bad post form"})
return
}