add/rm tokens, register with token

This commit is contained in:
2025-04-15 00:12:34 +02:00
parent 6d63e53200
commit 3955d8626a
7 changed files with 222 additions and 15 deletions

View File

@@ -1,10 +1,12 @@
package controllers
import (
"errors"
"fmt"
"net/http"
"github.com/gin-gonic/gin"
"gorm.io/gorm"
"git.dynamicdiscord.de/kalipso/zineshop/models"
"git.dynamicdiscord.de/kalipso/zineshop/repositories"
@@ -188,13 +190,14 @@ func (rc *UserController) RegisterHandler(c *gin.Context) {
tokenExists, err := repositories.Tokens.Exists(token)
if err != nil {
if err != nil && !errors.Is(err, gorm.ErrRecordNotFound) {
data := gin.H{
"error": err,
"success": "",
}
c.HTML(http.StatusOK, "register.html", data)
return
}
if !tokenExists {
@@ -203,6 +206,7 @@ func (rc *UserController) RegisterHandler(c *gin.Context) {
"success": "",
}
c.HTML(http.StatusOK, "register.html", data)
return
}
_, err = services.Users.Register(name, email, password, false)
@@ -233,9 +237,10 @@ func (rc *UserController) RegisterView(c *gin.Context) {
data := gin.H{
"error": "",
"success": "",
"token": c.Param("token"),
}
c.HTML(http.StatusOK, "register.html", data)
c.HTML(http.StatusOK, "registertoken.html", data)
}
func (rc *UserController) InitAdmin(c *gin.Context) {
@@ -292,6 +297,38 @@ func (rc *UserController) ResetHandler(c *gin.Context) {
c.HTML(http.StatusOK, "passwordreset.html", data)
}
func (rc *UserController) InviteView(c *gin.Context) {
tokens, _ := repositories.Tokens.GetAll()
fmt.Println(tokens)
data := gin.H{
"tokens": tokens,
}
c.HTML(http.StatusOK, "invites.html", data)
}
func (rc *UserController) InviteHandler(c *gin.Context) {
action := c.PostForm("action")
if action == "create" {
_, err := repositories.Tokens.Create()
if err != nil {
fmt.Println(err)
c.HTML(http.StatusBadRequest, "error.html", gin.H{"error": err})
return
}
}
if action == "delete" {
token := c.PostForm("token")
repositories.Tokens.Delete(token)
}
rc.InviteView(c)
}
func (rc *UserController) MainView(c *gin.Context) {
shopItems, _ := repositories.ShopItems.GetAll()
fmt.Println(len(shopItems))