Skip to content

Commit bb984ec

Browse files
author
Akshay
committed
fixed code issues
1 parent e7fbe71 commit bb984ec

File tree

2 files changed

+5
-18
lines changed

2 files changed

+5
-18
lines changed

api/handlers/user.go

+5-8
Original file line numberDiff line numberDiff line change
@@ -16,21 +16,21 @@ func Signup(c *gin.Context) {
1616
err := c.ShouldBindJSON(&user)
1717
if err != nil {
1818
log.Println(err)
19-
c.AbortWithStatusJSON(400, gin.H{"Message": "invalid json"})
19+
c.AbortWithStatusJSON(400, gin.H{"Message": "Invalid json"})
2020
return
2121
}
2222

2323
user.Password, err = utils.HashPassword(user.Password)
2424
if err != nil {
2525
log.Println(err.Error())
26-
c.AbortWithStatusJSON(500, gin.H{"Message": "error hashing password"})
26+
c.AbortWithStatusJSON(500, gin.H{"Message": "Error hashing password"})
2727
return
2828
}
2929

3030
err = storage.User.CreateUser(user)
3131
if err != nil {
3232
log.Println(err)
33-
c.AbortWithStatusJSON(500, gin.H{"Message": "error creating user"})
33+
c.AbortWithStatusJSON(500, gin.H{"Message": "Error creating user"})
3434
return
3535
}
3636

@@ -53,7 +53,7 @@ func Login(c *gin.Context) {
5353
return
5454
}
5555

56-
if CheckPassword(payload.Password, payload.Email) {
56+
if !CheckPassword(payload.Password, payload.Email) {
5757
utils.RespondWithError(c.Writer, 401, "Invalid Password")
5858
return
5959
}
@@ -74,7 +74,6 @@ func Login(c *gin.Context) {
7474
tokenResponse := models.LoginResponse{
7575
Token: signedToken,
7676
}
77-
7877
c.JSON(200, tokenResponse)
7978

8079
}
@@ -85,8 +84,6 @@ func CheckUserExists(email string) bool {
8584
}
8685

8786
func CheckPassword(password, email string) bool {
88-
8987
err := storage.User.CheckPassword(password, email)
90-
//log.Println("Inside Check Password")
91-
return err != nil
88+
return err == nil
9289
}

api/utils/helper.go

-10
Original file line numberDiff line numberDiff line change
@@ -57,13 +57,3 @@ func HashPassword(password string) (string, error) {
5757
return string(bytes), nil
5858

5959
}
60-
61-
// func CheckPassword(providedPassword string) error {
62-
// var user models.User
63-
// err := bcrypt.CompareHashAndPassword([]byte(user.Password), []byte(providedPassword))
64-
// if err != nil {
65-
// return err
66-
// }
67-
68-
// return nil
69-
// }

0 commit comments

Comments
 (0)