aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/user/controller.go
diff options
context:
space:
mode:
authorVidhu Kant Sharma <vidhukant@vidhukant.com>2025-10-12 00:05:30 +0530
committerVidhu Kant Sharma <vidhukant@vidhukant.com>2025-10-12 00:05:30 +0530
commita356803594ab36fa69e7dbcbd79261d8b46f4262 (patch)
tree0146efe4c52b1c65c1967ab1f412306c410c10d4 /user/controller.go
parent193be465b21838d2796fafbe1c5d9854038a3f8c (diff)
removed useless user fields and functions, added rolesv0.19.0
Diffstat (limited to 'user/controller.go')
-rw-r--r--user/controller.go116
1 files changed, 2 insertions, 114 deletions
diff --git a/user/controller.go b/user/controller.go
index 1dc85da..7dd519a 100644
--- a/user/controller.go
+++ b/user/controller.go
@@ -1,5 +1,5 @@
/* openbills - Server for web based Libre Billing Software
- * Copyright (C) 2023-2024 Vidhu Kant Sharma <vidhukant@vidhukant.com>
+ * Copyright (C) 2023-2025 Vidhu Kant Sharma <vidhukant@vidhukant.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -20,8 +20,6 @@ package user
import (
e "vidhukant.com/openbills/errors"
"github.com/gin-gonic/gin"
- "github.com/google/uuid"
- "github.com/spf13/viper"
"net/http"
)
@@ -37,7 +35,7 @@ func handleGetUser (ctx *gin.Context) {
userId := uId.(uint)
- err := GetUser(&user, userId)
+ err := GetUserById(&user, userId)
if err != nil {
ctx.Error(err)
ctx.Abort()
@@ -48,116 +46,6 @@ func handleGetUser (ctx *gin.Context) {
user.Password = ""
ctx.JSON(http.StatusOK, gin.H{
- "message": "success",
"data": user,
})
}
-
-func handleUploadLogo(ctx *gin.Context) {
- var user User
-
- uId, ok := ctx.Get("UserID")
- if !ok {
- ctx.Error(e.ErrUnauthorized)
- ctx.Abort()
- return
- }
-
- userId := uId.(uint)
- user.ID = userId
-
- // TODO: handle potential errors
- file, err := ctx.FormFile("logo")
- if err != nil {
- ctx.Error(err)
- ctx.Abort()
- return
- }
-
- dest := uuid.New().String()
-
- // TODO: handle potential errors
- err = ctx.SaveUploadedFile(file, viper.GetString("data.upload_dir") + dest)
- if err != nil {
- ctx.Error(err)
- ctx.Abort()
- return
- }
-
- // TODO: delete old file (if any)
- err = user.update(map[string]interface{}{"logo_file": dest})
- if err != nil {
- ctx.Error(err)
- ctx.Abort()
- return
- }
-
- ctx.JSON(http.StatusOK, gin.H{
- "message": "success",
- })
-}
-
-func handleUploadSignature(ctx *gin.Context) {
- var user User
-
- uId, ok := ctx.Get("UserID")
- if !ok {
- ctx.Error(e.ErrUnauthorized)
- ctx.Abort()
- return
- }
-
- userId := uId.(uint)
- user.ID = userId
-
- // TODO: handle potential errors
- file, err := ctx.FormFile("signature")
- if err != nil {
- ctx.Error(err)
- ctx.Abort()
- return
- }
-
- dest := uuid.New().String()
-
- // TODO: handle potential errors
- err = ctx.SaveUploadedFile(file, viper.GetString("data.upload_dir") + dest)
- if err != nil {
- ctx.Error(err)
- ctx.Abort()
- return
- }
-
- // TODO: delete old file (if any)
- err = user.update(map[string]interface{}{"signature_file": dest})
- if err != nil {
- ctx.Error(err)
- ctx.Abort()
- return
- }
-
- ctx.JSON(http.StatusOK, gin.H{
- "message": "success",
- })
-}
-
-// TODO: fix this stuff
-// also add some kind of 2 factor verification
-func handleDelUser (ctx *gin.Context) {
- id := uint(1) // get from JWT
-
- var user User
- user.ID = id
-
- // TODO: add a verification mechanism
- err := user.del()
- if err != nil {
- ctx.Error(err)
- ctx.Abort()
- return
- }
-
- ctx.JSON(http.StatusOK, gin.H{
- "message": "success",
- })
-}