mirror of
https://github.com/Uttkarsh-raj/Plannerly.git
synced 2025-11-29 21:57:34 +02:00
added errors to auth
This commit is contained in:
@@ -56,13 +56,13 @@ func SignUp() gin.HandlerFunc {
|
||||
var user models.User
|
||||
defer cancel()
|
||||
if err := c.BindJSON(&user); err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error(), "success": false})
|
||||
return
|
||||
}
|
||||
|
||||
validationErr := validate.Struct(user)
|
||||
if validationErr != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": validationErr.Error()})
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": validationErr.Error(), "success": false})
|
||||
return
|
||||
}
|
||||
|
||||
@@ -70,7 +70,7 @@ func SignUp() gin.HandlerFunc {
|
||||
defer cancel()
|
||||
if err != nil {
|
||||
log.Panic(err)
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"error": "error occured while checking for the email"})
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"error": "error occured while checking for the email", "success": false})
|
||||
return
|
||||
}
|
||||
|
||||
@@ -81,7 +81,7 @@ func SignUp() gin.HandlerFunc {
|
||||
defer cancel()
|
||||
if err != nil {
|
||||
log.Panic(err)
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"error": "error occured while checking for the phone number"})
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"error": "error occured while checking for the phone number", "success": false})
|
||||
return
|
||||
}
|
||||
|
||||
@@ -103,12 +103,12 @@ func SignUp() gin.HandlerFunc {
|
||||
log.Printf("resultInsertionNumber %d", resultInsertionNumber)
|
||||
if insertErr != nil {
|
||||
msg := fmt.Sprintf("User item was not created")
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"error": msg})
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"error": msg, "success": false})
|
||||
return
|
||||
}
|
||||
defer cancel()
|
||||
|
||||
c.JSON(http.StatusOK, resultInsertionNumber)
|
||||
c.JSON(http.StatusOK, gin.H{"success": true, "number": resultInsertionNumber})
|
||||
|
||||
}
|
||||
}
|
||||
@@ -121,21 +121,21 @@ func Login() gin.HandlerFunc {
|
||||
var foundUser models.User
|
||||
defer cancel()
|
||||
if err := c.BindJSON(&user); err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error(), "success": false})
|
||||
return
|
||||
}
|
||||
|
||||
err := userCollection.FindOne(ctx, bson.M{"email": user.Email}).Decode(&foundUser)
|
||||
defer cancel()
|
||||
if err != nil {
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"error": "login or passowrd is incorrect"})
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"error": "login or passowrd is incorrect", "success": false})
|
||||
return
|
||||
}
|
||||
|
||||
passwordIsValid, msg := VerifyPassword(*user.Password, *foundUser.Password)
|
||||
defer cancel()
|
||||
if passwordIsValid != true {
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"error": msg})
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"error": msg, "success": false})
|
||||
return
|
||||
}
|
||||
|
||||
@@ -143,7 +143,7 @@ func Login() gin.HandlerFunc {
|
||||
|
||||
helpers.UpdateAllToken(token, refreshToken, foundUser.User_id)
|
||||
|
||||
c.JSON(http.StatusOK, foundUser)
|
||||
c.JSON(http.StatusOK, gin.H{"success": true, "data": foundUser})
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user