Skip to content

Commit

Permalink
unstable: handlers: login: added userinfo to display
Browse files Browse the repository at this point in the history
  • Loading branch information
pandadiestro committed Nov 26, 2024
1 parent 98ee246 commit 7d1e23e
Show file tree
Hide file tree
Showing 33 changed files with 498 additions and 447 deletions.
7 changes: 5 additions & 2 deletions stiller-backend/cmd/serve/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,22 @@ package main
import (
"log"
"net/http"
"os"
"stiller"
"stiller/internal/router"
"stiller/pkg/loggers"
"time"
)

func main() {
new_router := router.NewStillerRouter()
if new_router == nil {
log.Fatalln("[ ❌ ] invalid router, exiting...")
loggers.GenericErrLog(nil, "invalid router, exiting...")
os.Exit(-1)
}

log.Println(
"[] server started at address",
"[ok] server started at address",
stiller.StillerConfig.Addr,
)

Expand Down
97 changes: 0 additions & 97 deletions stiller-backend/internal/handlers/auth/userlogin/handler.go

This file was deleted.

17 changes: 0 additions & 17 deletions stiller-backend/internal/handlers/gallery/galleryedit/handler.go

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
package userverify
package handlers

import (
"net/http"
"stiller/internal/dbutils"
"stiller/internal/handlers/handleutils"
"stiller/pkg/dbutils"
"stiller/pkg/loggers"
"stiller/pkg/netwrappers"

"github.com/julienschmidt/httprouter"
"zombiezen.com/go/sqlite"
"zombiezen.com/go/sqlite/sqlitex"
)


func NetHandler(w http.ResponseWriter, r *http.Request, params httprouter.Params) {
if handleutils.CORS(w, r) {
func GetAuthCheckUser(w http.ResponseWriter, r *http.Request, params httprouter.Params) {
if netwrappers.CORS(w, r) {
return
}

Expand All @@ -23,7 +23,7 @@ func NetHandler(w http.ResponseWriter, r *http.Request, params httprouter.Params
}

new_dbconn, dbconn_err := dbutils.NewConn()
if handleutils.RequestLog(dbconn_err, "", http.StatusInternalServerError, &w) {
if loggers.RequestLog(dbconn_err, "", http.StatusInternalServerError, &w) {
return
}

Expand All @@ -42,7 +42,7 @@ func NetHandler(w http.ResponseWriter, r *http.Request, params httprouter.Params
},
})

if handleutils.RequestLog(exec_err, "", http.StatusInternalServerError, &w) {
if loggers.RequestLog(exec_err, "", http.StatusInternalServerError, &w) {
return
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package filedel
package handlers

import (
"net/http"
"stiller/internal/check"
"stiller/internal/dbutils"
"stiller/internal/handlers/handleutils"
"stiller/internal/jwtutils"
"stiller/pkg/checkers"
"stiller/pkg/dbutils"
"stiller/pkg/jwt"
"stiller/pkg/loggers"
"stiller/pkg/netwrappers"
"strconv"

"github.com/julienschmidt/httprouter"
Expand All @@ -14,19 +15,19 @@ import (
)


func Nethandler(w http.ResponseWriter, r *http.Request, params httprouter.Params) {
if handleutils.CORS(w, r) {
func GetFileDel(w http.ResponseWriter, r *http.Request, params httprouter.Params) {
if netwrappers.CORS(w, r) {
return
}

file_id_str := params.ByName("file_id")
file_id, file_id_err := strconv.Atoi(file_id_str)
if handleutils.RequestLog(file_id_err, "", http.StatusNotFound, &w) {
if loggers.RequestLog(file_id_err, "", http.StatusNotFound, &w) {
return
}

new_dbconn, conn_err := dbutils.NewConn()
if handleutils.RequestLog(
if loggers.RequestLog(
conn_err,
"",
http.StatusInternalServerError,
Expand All @@ -38,20 +39,20 @@ func Nethandler(w http.ResponseWriter, r *http.Request, params httprouter.Params
defer dbutils.CloseConn(new_dbconn)

user_token := r.Header.Get("token")
user_tk, token_decode_err := jwtutils.Decode(user_token)
if handleutils.RequestLog(token_decode_err, "", http.StatusUnauthorized, &w) {
user_tk, token_decode_err := jwt.Decode(user_token)
if loggers.RequestLog(token_decode_err, "", http.StatusUnauthorized, &w) {
return
}

user_id := user_tk.UserId

is_owner, owner_err := check.IsFileOwner(user_id, file_id, new_dbconn)
if handleutils.RequestLog(owner_err, "", http.StatusInternalServerError, &w) {
is_owner, owner_err := checkers.IsFileOwner(user_id, file_id, new_dbconn)
if loggers.RequestLog(owner_err, "", http.StatusInternalServerError, &w) {
return
}

if !is_owner {
handleutils.RequestLog(nil, "not the owner", http.StatusUnauthorized, &w)
loggers.RequestLog(nil, "not the owner", http.StatusUnauthorized, &w)
return
}

Expand All @@ -68,7 +69,7 @@ func Nethandler(w http.ResponseWriter, r *http.Request, params httprouter.Params
},
)

if handleutils.RequestLog(exec_err, "", http.StatusInternalServerError, &w) {
if loggers.RequestLog(exec_err, "", http.StatusInternalServerError, &w) {
return
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package filedl
package handlers

import (
"log"
"net/http"
"stiller/internal/dbutils"
"stiller/internal/fsutils"
"stiller/internal/handlers/handleutils"
"stiller/pkg/dbutils"
"stiller/pkg/fsop"
"stiller/pkg/loggers"
"stiller/pkg/netwrappers"
"strconv"

"github.com/julienschmidt/httprouter"
Expand All @@ -15,19 +16,19 @@ import (
)


func Nethandler(w http.ResponseWriter, r *http.Request, params httprouter.Params) {
if handleutils.CORS(w, r) {
func GetFileDl(w http.ResponseWriter, r *http.Request, params httprouter.Params) {
if netwrappers.CORS(w, r) {
return
}

file_id_str := params.ByName("file_id")
file_id, file_id_err := strconv.Atoi(file_id_str)
if handleutils.RequestLog(file_id_err, "", http.StatusNotFound, &w) {
if loggers.RequestLog(file_id_err, "", http.StatusNotFound, &w) {
return
}

new_dbconn, conn_err := dbutils.NewConn()
if handleutils.RequestLog(
if loggers.RequestLog(
conn_err,
"",
http.StatusInternalServerError,
Expand Down Expand Up @@ -57,17 +58,17 @@ func Nethandler(w http.ResponseWriter, r *http.Request, params httprouter.Params
},
)

if handleutils.RequestLog(exec_err, "", http.StatusNotFound, &w) {
if loggers.RequestLog(exec_err, "", http.StatusNotFound, &w) {
return
}

fexists, fexists_err := fsutils.FileExists(path)
if handleutils.RequestLog(fexists_err, "", http.StatusInternalServerError, &w) {
fexists, fexists_err := fsop.FileExists(path)
if loggers.RequestLog(fexists_err, "", http.StatusInternalServerError, &w) {
return
}

if !fexists {
handleutils.GenericLog(nil, "path '%s' doesnt exist", path)
loggers.GenericErrLog(nil, "path '%s' doesnt exist", path)
}

log.Println(path)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package filetree
package handlers

import (
"net/http"
"stiller"
"stiller/internal/dbutils"
"stiller/internal/handlers/handleutils"
"stiller/internal/jwtutils"
"stiller/pkg/dbutils"
"stiller/pkg/jwt"
"stiller/pkg/loggers"
"stiller/pkg/netwrappers"
"strconv"

jsonexp "github.com/go-json-experiment/json"
Expand All @@ -15,19 +16,19 @@ import (
"zombiezen.com/go/sqlite/sqlitex"
)

func Nethandler(w http.ResponseWriter, r *http.Request, params httprouter.Params) {
if handleutils.CORS(w, r) {
func GetFile(w http.ResponseWriter, r *http.Request, params httprouter.Params) {
if netwrappers.CORS(w, r) {
return
}

user_token := r.Header.Get("token")
user_tk, token_decode_err := jwtutils.Decode(user_token)
if handleutils.RequestLog(token_decode_err, "", http.StatusUnauthorized, &w) {
user_tk, token_decode_err := jwt.Decode(user_token)
if loggers.RequestLog(token_decode_err, "", http.StatusUnauthorized, &w) {
return
}

new_dbconn, dbconn_err := sqlite.OpenConn(stiller.StillerConfig.DBPath)
if handleutils.RequestLog(dbconn_err, "", http.StatusInternalServerError, &w) {
if loggers.RequestLog(dbconn_err, "", http.StatusInternalServerError, &w) {
return
}

Expand All @@ -49,8 +50,7 @@ func Nethandler(w http.ResponseWriter, r *http.Request, params httprouter.Params
})

if user_count == -1 {
w.WriteHeader(http.StatusNotFound)
handleutils.GenericLog(nil, "user does not exist")
loggers.RequestLog(nil, "user does not exist", http.StatusNotFound, &w)
return
}

Expand All @@ -71,7 +71,7 @@ func Nethandler(w http.ResponseWriter, r *http.Request, params httprouter.Params
},
)

if handleutils.RequestLog(rowlen_exec_err, "", http.StatusInternalServerError, &w) {
if loggers.RequestLog(rowlen_exec_err, "", http.StatusInternalServerError, &w) {
return
}

Expand Down Expand Up @@ -111,7 +111,7 @@ func Nethandler(w http.ResponseWriter, r *http.Request, params httprouter.Params
},
)

if handleutils.RequestLog(exec_err, "", http.StatusInternalServerError, &w) {
if loggers.RequestLog(exec_err, "", http.StatusInternalServerError, &w) {
return
}

Expand Down
Loading

0 comments on commit 7d1e23e

Please sign in to comment.