aboutsummaryrefslogtreecommitdiff
path: root/db
diff options
context:
space:
mode:
Diffstat (limited to 'db')
-rw-r--r--db/redis.go98
-rw-r--r--db/verification.go17
2 files changed, 4 insertions, 111 deletions
diff --git a/db/redis.go b/db/redis.go
deleted file mode 100644
index 1650b4f..0000000
--- a/db/redis.go
+++ /dev/null
@@ -1,98 +0,0 @@
-package db
-
-import (
- "bufio"
- "fmt"
- "os"
- "strings"
-
- "github.com/FChannel0/FChannel-Server/config"
- "github.com/gofiber/fiber/v2"
- "github.com/gomodule/redigo/redis"
-)
-
-var Cache redis.Conn
-
-func InitCache() error {
- conn, err := redis.DialURL(config.Redis)
- Cache = conn
- return err
-}
-
-func CloseCache() error {
- return Cache.Close()
-}
-
-func GetClientKey() (string, error) {
- file, err := os.Open("clientkey")
- if err != nil {
- return "", err
- }
- defer file.Close()
-
- scanner := bufio.NewScanner(file)
- var line string
- for scanner.Scan() {
- line = fmt.Sprintf("%s", scanner.Text())
- }
-
- return line, nil
-}
-
-func GetPasswordFromSession(c *fiber.Ctx) (string, string) {
-
- cookie := c.Cookies("session_token")
-
- if cookie == "" {
- return "", ""
- }
-
- sessionToken := cookie
-
- 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 "", ""
-}
-
-/* TODO: Convert to fiber ctx
-func CheckSession(w http.ResponseWriter, r *http.Request) (interface{}, error) {
- c, err := r.Cookie("session_token")
-
- if err != nil {
- if err == http.ErrNoCookie {
- w.WriteHeader(http.StatusUnauthorized)
- return nil, err
- }
-
- w.WriteHeader(http.StatusBadRequest)
- return nil, err
- }
-
- sessionToken := c.Value
-
- response, err := Cache.Do("GET", sessionToken)
-
- if err != nil {
- w.WriteHeader(http.StatusInternalServerError)
- return nil, err
- }
- if response == nil {
- w.WriteHeader(http.StatusUnauthorized)
- return nil, err
- }
-
- return response, nil
- }
-*/
diff --git a/db/verification.go b/db/verification.go
index 562503d..a178d52 100644
--- a/db/verification.go
+++ b/db/verification.go
@@ -491,7 +491,7 @@ func Captcha() string {
}
func HasValidation(ctx *fiber.Ctx, actor activitypub.Actor) bool {
- id, _ := GetPassword(ctx)
+ id, _ := GetPasswordFromSession(ctx)
if id == "" || (id != actor.Id && id != config.Domain) {
//http.Redirect(w, r, "/", http.StatusSeeOther)
@@ -501,19 +501,10 @@ func HasValidation(ctx *fiber.Ctx, actor activitypub.Actor) bool {
return true
}
-func GetPassword(r *fiber.Ctx) (string, string) {
- c := r.Cookies("session_token")
+func GetPasswordFromSession(r *fiber.Ctx) (string, string) {
+ cookie := 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, "|")
+ parts := strings.Split(cookie, "|")
if len(parts) > 1 {
return parts[0], parts[1]