Skip to content

Commit

Permalink
fix stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
shani-asad committed May 19, 2024
1 parent 8ad698b commit 1f33348
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions src/handler/auth_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@ func (h *AuthHandler) Register(c *gin.Context) {
}

// Validate request payload
if(request.Nip == 0) {
log.Println("Register bad request > invalid NIP")
c.JSON(400, gin.H{"status": "bad request", "message": "invalid NIP"})
return
}

err = ValidateRegisterRequest(request.Nip, request.Name, request.Password)
if err != nil {
log.Println("Register bad request ", err)
Expand Down Expand Up @@ -72,6 +78,12 @@ func (h *AuthHandler) Login(c *gin.Context) {
c.JSON(400, gin.H{"status": "bad request", "message": err})
return
}

if(request.Nip == 0) {
log.Println("Register bad request > invalid NIP")
c.JSON(400, gin.H{"status": "bad request", "message": "invalid NIP"})
return
}

nStr := strconv.FormatInt(request.Nip, 10)
if !strings.HasPrefix(nStr, "615") {
Expand Down Expand Up @@ -105,7 +117,8 @@ func (h *AuthHandler) Login(c *gin.Context) {
"data": gin.H{
"nip": userData.Nip,
"name": userData.Name,
"accessToken": token,
"accessToken": token,
"userId": userData.Id,
},
})
}
Expand Down Expand Up @@ -158,7 +171,7 @@ func (h *AuthHandler) LoginNurse(c *gin.Context) {
}

// ValidateRegisterRequest validates the register user request payload
func ValidateRegisterRequest(nip int64, name, password string) error {
func ValidateRegisterRequest(nip int64, name string, password string) error {
// Validate email format
if !isValidNip(nip) {
return errors.New("nip invalid")
Expand Down

0 comments on commit 1f33348

Please sign in to comment.