aboutsummaryrefslogtreecommitdiff
path: root/routes/util.go
blob: 37639c3b3a72228976ec246ebcb9c1f7cd15aaf1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package routes

import (
	"fmt"
	"strings"

	"github.com/gofiber/fiber/v2"
)

func getThemeCookie(c *fiber.Ctx) string {
	cookie := c.Cookies("theme")
	if cookie != "" {
		cookies := strings.SplitN(cookie, "=", 2)
		return cookies[0]
	}

	return "default"
}

func getPassword(r *fiber.Ctx) (string, string) {
	c := r.Cookies("session_token")

	sessionToken := c

	response, err := cache.Do("GET", sessionToken)
	if err != nil {
		return "", ""
	}

	token := fmt.Sprintf("%s", response)

	parts := strings.Split(token, "|")

	if len(parts) > 1 {
		return parts[0], parts[1]
	}

	return "", ""
}