begin dashboard

This commit is contained in:
SowinskiBraeden committed 2022-04-20 13:49:38 -07:00
1 parent 6d1611341a
commit e3a811b224
121 files changed
+34389 -1662

No files matched your search

+1 -5
View File
@@ -2,7 +2,6 @@ package controllers
import (
"context"
"fmt"
"os"
"time"
@@ -250,7 +249,6 @@ func Login(c *fiber.Ctx) error {
}
func Logout(c *fiber.Ctx) error {
fmt.Println("here")
cookie := fiber.Cookie{
Name: "jwt",
Value: "",
@@ -259,7 +257,5 @@ func Logout(c *fiber.Ctx) error {
}
c.Cookie(&cookie)
return c.Status(fiber.StatusOK).Render("index", fiber.Map{
"loggedIn": false,
})
return c.Status(fiber.StatusOK).Redirect("/")
}
+26 -6
View File
@@ -71,12 +71,32 @@ func LoginPage(c *fiber.Ctx) error {
})
}
return c.Status(fiber.StatusAccepted).Redirect("/dashboard")
}
func DashboardPage(c *fiber.Ctx) error {
cookie := c.Cookies("jwt")
token, err := jwt.ParseWithClaims(cookie, &jwt.StandardClaims{}, func(token *jwt.Token) (interface{}, error) {
return []byte(SecretKey), nil
})
// This returns not authorized
if err != nil {
return c.Status(fiber.StatusUnauthorized).Redirect("login")
}
claims := token.Claims.(*jwt.StandardClaims)
uid := claims.Issuer
var user models.User
findErr := userCollection.FindOne(context.TODO(), bson.M{"uid": uid}).Decode(&user)
if findErr != nil {
return c.Status(fiber.StatusUnauthorized).Redirect("/login")
}
return c.Status(fiber.StatusAccepted).Render("dashboard", fiber.Map{
"msg": "",
"errorMsg": "",
"username": user.Username,
"email": user.Email,
"firstname": user.Firstname,
"lastname": user.Lastname,
"errorMsg": "",
"msg": "",
"user": user,
})
}