diff options
| author | Vidhu Kant Sharma <vidhukant@vidhukant.com> | 2024-04-05 20:05:11 +0530 | 
|---|---|---|
| committer | Vidhu Kant Sharma <vidhukant@vidhukant.com> | 2024-04-05 20:05:11 +0530 | 
| commit | e616df98557fe57fc942c360f03f7fafbdb965bd (patch) | |
| tree | 410f1d89bf82f2cb33b63e5b97c72c496ac36940 /user | |
| parent | 73d7fe9411f4a9a0b849d9b42051e67ca19c25ec (diff) | |
added functionality to get logged in user's data
Diffstat (limited to 'user')
| -rw-r--r-- | user/controller.go | 27 | 
1 files changed, 20 insertions, 7 deletions
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 <vidhukant@vidhukant.com> + * Copyright (C) 2023-2024  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 @@ -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",  |