From e616df98557fe57fc942c360f03f7fafbdb965bd Mon Sep 17 00:00:00 2001 From: Vidhu Kant Sharma Date: Fri, 5 Apr 2024 20:05:11 +0530 Subject: added functionality to get logged in user's data --- user/controller.go | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) (limited to 'user') diff --git a/user/controller.go b/user/controller.go index 4933ea3..15061cc 100644 --- a/user/controller.go +++ b/user/controller.go @@ -1,5 +1,5 @@ /* openbills - Server for web based Libre Billing Software - * Copyright (C) 2023 Vidhu Kant Sharma + * Copyright (C) 2023-2024 Vidhu Kant Sharma * * 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 @@ -18,6 +18,7 @@ package user import ( + e "vidhukant.com/openbills/errors" "github.com/gin-gonic/gin" "net/http" ) @@ -25,12 +26,24 @@ import ( func handleGetUser (ctx *gin.Context) { var user User - //err = getUser(&user, uint(id)) - //if err != nil { - // ctx.Error(err) - // ctx.Abort() - // return - //} + uId, ok := ctx.Get("UserID") + if !ok { + ctx.Error(e.ErrUnauthorized) + ctx.Abort() + return + } + + userId := uId.(uint) + + err := GetUser(&user, userId) + if err != nil { + ctx.Error(err) + ctx.Abort() + return + } + + // remove password hash from response + user.Password = "" ctx.JSON(http.StatusOK, gin.H{ "message": "success", -- cgit v1.2.3