format
This commit is contained in:
@@ -1,30 +1,28 @@
|
|||||||
package controllers
|
package controllers
|
||||||
|
|
||||||
import(
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
|
||||||
"math/rand"
|
"math/rand"
|
||||||
|
"net/http"
|
||||||
|
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
|
|
||||||
"example.com/gin/test/models"
|
"example.com/gin/test/models"
|
||||||
"example.com/gin/test/repositories"
|
"example.com/gin/test/repositories"
|
||||||
"example.com/gin/test/services"
|
"example.com/gin/test/services"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
type UserController struct{}
|
||||||
type UserController struct {}
|
|
||||||
|
|
||||||
func NewUserController() UserController {
|
func NewUserController() UserController {
|
||||||
return UserController{}
|
return UserController{}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
func (uc *UserController) Register(c *gin.Context) {
|
func (uc *UserController) Register(c *gin.Context) {
|
||||||
//Get the email/passwd off req body
|
//Get the email/passwd off req body
|
||||||
var body struct {
|
var body struct {
|
||||||
Name string
|
Name string
|
||||||
Email string
|
Email string
|
||||||
Password string
|
Password string
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -53,11 +51,10 @@ func (uc *UserController) Register(c *gin.Context) {
|
|||||||
c.JSON(http.StatusOK, gin.H{})
|
c.JSON(http.StatusOK, gin.H{})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
func (uc *UserController) Login(c *gin.Context) {
|
func (uc *UserController) Login(c *gin.Context) {
|
||||||
//Get the email/passwd off req body
|
//Get the email/passwd off req body
|
||||||
var body struct {
|
var body struct {
|
||||||
Email string
|
Email string
|
||||||
Password string
|
Password string
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -83,7 +80,7 @@ func (uc *UserController) Login(c *gin.Context) {
|
|||||||
|
|
||||||
// send it back
|
// send it back
|
||||||
c.SetSameSite(http.SameSiteLaxMode)
|
c.SetSameSite(http.SameSiteLaxMode)
|
||||||
c.SetCookie("Authorization", tokenString, 3600 * 24, "", "", false, true)
|
c.SetCookie("Authorization", tokenString, 3600*24, "", "", false, true)
|
||||||
c.JSON(http.StatusOK, gin.H{})
|
c.JSON(http.StatusOK, gin.H{})
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -116,7 +113,6 @@ func (rc *UserController) LoginView(c *gin.Context) {
|
|||||||
c.HTML(http.StatusOK, "login.html", CreateSessionData(c, data))
|
c.HTML(http.StatusOK, "login.html", CreateSessionData(c, data))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
func (rc *UserController) LoginHandler(c *gin.Context) {
|
func (rc *UserController) LoginHandler(c *gin.Context) {
|
||||||
email := c.PostForm("email")
|
email := c.PostForm("email")
|
||||||
password := c.PostForm("password")
|
password := c.PostForm("password")
|
||||||
@@ -139,7 +135,7 @@ func (rc *UserController) LoginHandler(c *gin.Context) {
|
|||||||
|
|
||||||
// send it back
|
// send it back
|
||||||
//c.SetSameSite(http.SameSiteLaxMode)
|
//c.SetSameSite(http.SameSiteLaxMode)
|
||||||
c.SetCookie("Authorization", tokenString, 3600 * 24, "", "", false, true)
|
c.SetCookie("Authorization", tokenString, 3600*24, "", "", false, true)
|
||||||
c.HTML(http.StatusOK, "login.html", CreateSessionData(c, gin.H{}))
|
c.HTML(http.StatusOK, "login.html", CreateSessionData(c, gin.H{}))
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -147,9 +143,8 @@ func CreateSessionData(c *gin.Context, extra any) gin.H {
|
|||||||
_, exists := c.Get("user")
|
_, exists := c.Get("user")
|
||||||
|
|
||||||
return gin.H{
|
return gin.H{
|
||||||
"test": "HEllo World",
|
|
||||||
"loggedIn": exists,
|
"loggedIn": exists,
|
||||||
"data": extra,
|
"data": extra,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -162,7 +157,7 @@ func (rc *UserController) RegisterHandler(c *gin.Context) {
|
|||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
data := gin.H{
|
data := gin.H{
|
||||||
"error": "Registering Failed.",
|
"error": "Registering Failed.",
|
||||||
"success": "",
|
"success": "",
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -171,7 +166,7 @@ func (rc *UserController) RegisterHandler(c *gin.Context) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
data := gin.H{
|
data := gin.H{
|
||||||
"error": "",
|
"error": "",
|
||||||
"success": "You successfully registered. Try logging in.",
|
"success": "You successfully registered. Try logging in.",
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -180,7 +175,7 @@ func (rc *UserController) RegisterHandler(c *gin.Context) {
|
|||||||
|
|
||||||
func (rc *UserController) RegisterView(c *gin.Context) {
|
func (rc *UserController) RegisterView(c *gin.Context) {
|
||||||
data := gin.H{
|
data := gin.H{
|
||||||
"error": "",
|
"error": "",
|
||||||
"success": "",
|
"success": "",
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -191,7 +186,7 @@ func (rc *UserController) ResetView(c *gin.Context) {
|
|||||||
shopItems, _ := repositories.ShopItems.GetAll()
|
shopItems, _ := repositories.ShopItems.GetAll()
|
||||||
|
|
||||||
data := gin.H{
|
data := gin.H{
|
||||||
"title": "shopItem Page",
|
"title": "shopItem Page",
|
||||||
"shopItems": shopItems,
|
"shopItems": shopItems,
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -202,7 +197,7 @@ func (rc *UserController) ResetHandler(c *gin.Context) {
|
|||||||
shopItems, _ := repositories.ShopItems.GetAll()
|
shopItems, _ := repositories.ShopItems.GetAll()
|
||||||
|
|
||||||
data := gin.H{
|
data := gin.H{
|
||||||
"title": "shopItem Page",
|
"title": "shopItem Page",
|
||||||
"shopItems": shopItems,
|
"shopItems": shopItems,
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -214,7 +209,7 @@ func (rc *UserController) MainView(c *gin.Context) {
|
|||||||
fmt.Println(len(shopItems))
|
fmt.Println(len(shopItems))
|
||||||
|
|
||||||
data := CreateSessionData(c, gin.H{
|
data := CreateSessionData(c, gin.H{
|
||||||
"title": "shopItem Page",
|
"title": "shopItem Page",
|
||||||
"shopItems": shopItems,
|
"shopItems": shopItems,
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -227,8 +222,8 @@ type booking struct {
|
|||||||
Booked bool
|
Booked bool
|
||||||
}
|
}
|
||||||
|
|
||||||
type calendarbooking struct{
|
type calendarbooking struct {
|
||||||
Time string
|
Time string
|
||||||
Bookings []booking
|
Bookings []booking
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -236,17 +231,16 @@ func (rc *UserController) CalendarView(c *gin.Context) {
|
|||||||
shopItems, _ := repositories.ShopItems.GetAll()
|
shopItems, _ := repositories.ShopItems.GetAll()
|
||||||
fmt.Println(len(shopItems))
|
fmt.Println(len(shopItems))
|
||||||
|
|
||||||
|
|
||||||
generateBookings := func(amountShopItems int) []calendarbooking {
|
generateBookings := func(amountShopItems int) []calendarbooking {
|
||||||
var result []calendarbooking
|
var result []calendarbooking
|
||||||
time := 6;
|
time := 6
|
||||||
for _ = range 18 {
|
for _ = range 18 {
|
||||||
book := calendarbooking{
|
book := calendarbooking{
|
||||||
Time: fmt.Sprintf("%d:00", time),
|
Time: fmt.Sprintf("%d:00", time),
|
||||||
Bookings: []booking{},
|
Bookings: []booking{},
|
||||||
}
|
}
|
||||||
for _ = range amountShopItems {
|
for _ = range amountShopItems {
|
||||||
book.Bookings = append(book.Bookings, booking{ Booked: rand.Float32() < 0.5 })
|
book.Bookings = append(book.Bookings, booking{Booked: rand.Float32() < 0.5})
|
||||||
}
|
}
|
||||||
|
|
||||||
time += 1
|
time += 1
|
||||||
@@ -276,8 +270,8 @@ func (rc *UserController) CalendarView(c *gin.Context) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
data := CreateSessionData(c, gin.H{
|
data := CreateSessionData(c, gin.H{
|
||||||
"title": "shopItem Page",
|
"title": "shopItem Page",
|
||||||
"bookings": bookings,
|
"bookings": bookings,
|
||||||
"shopItemcount": len(bookings["head"].([]string)) + 1,
|
"shopItemcount": len(bookings["head"].([]string)) + 1,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user