Skip to content

Commit

Permalink
Merge pull request #39 from Black-Sirius69/master
Browse files Browse the repository at this point in the history
  • Loading branch information
Mr-Emerald-Wolf committed Mar 15, 2024
2 parents fd504b1 + 5368330 commit 419c6d7
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 12 deletions.
7 changes: 0 additions & 7 deletions internal/controllers/auth_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,6 @@ func Login(ctx echo.Context) error {
})
}

if !user.IsProfileComplete {
return ctx.JSON(http.StatusLocked, map[string]interface{}{
"message": "profile not completed",
"status": "fail",
})
}

tokenVersionStr, err := database.RedisClient.Get(
fmt.Sprintf("token_version:%s", user.User.Email))
if err != nil && err != redis.Nil {
Expand Down
12 changes: 8 additions & 4 deletions internal/controllers/user_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -456,6 +456,8 @@ func VerifyUser(ctx echo.Context) error {
})
}

database.RedisClient.Delete("verification:" + user.User.Email)

return ctx.JSON(http.StatusOK, map[string]string{
"message": "User verified",
"status": "success",
Expand Down Expand Up @@ -580,7 +582,7 @@ func RequestResetPassword(ctx echo.Context) error {
})
}

if err := database.RedisClient.Set("resettries"+payload.Email, fmt.Sprint(1), time.Minute*5); err != nil {
if err := database.RedisClient.Set("resettries:"+payload.Email, fmt.Sprint(1), time.Minute*5); err != nil {
return ctx.JSON(http.StatusInternalServerError, map[string]string{
"message": err.Error(),
"status": "error",
Expand Down Expand Up @@ -637,7 +639,7 @@ func ResetPassword(ctx echo.Context) error {
})
}

triesString, err := database.RedisClient.Get("resettries" + payload.Email)
triesString, err := database.RedisClient.Get("resettries:" + payload.Email)
if err != nil {
if err == redis.Nil {
return ctx.JSON(http.StatusForbidden, map[string]string{
Expand All @@ -654,7 +656,7 @@ func ResetPassword(ctx echo.Context) error {
tries, _ := strconv.Atoi(triesString)

if tries >= 10 {
database.RedisClient.Delete("resetpass" + payload.Email)
database.RedisClient.Delete("resetpass:" + payload.Email)
return ctx.JSON(http.StatusGone, map[string]string{
"message": "otp expired",
"status": "fail",
Expand All @@ -676,7 +678,7 @@ func ResetPassword(ctx echo.Context) error {
}

if payload.OTP != otp {
if err := database.RedisClient.Set("resettries"+payload.Email, fmt.Sprint(tries+1), time.Minute*5); err != nil {
if err := database.RedisClient.Set("resettries:"+payload.Email, fmt.Sprint(tries+1), time.Minute*5); err != nil {
return ctx.JSON(http.StatusInternalServerError, map[string]string{
"message": err.Error(),
"status": "error",
Expand Down Expand Up @@ -710,6 +712,8 @@ func ResetPassword(ctx echo.Context) error {
})
}

database.RedisClient.Delete("resetpass:" + payload.Email)

return ctx.JSON(http.StatusOK, map[string]string{
"status": "success",
"message": "password reset successfully",
Expand Down
2 changes: 1 addition & 1 deletion internal/models/user_model.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ type User struct {
RegNo string `json:"reg_no"`
Email string `json:"email"`
Password string `json:"-"`
Phone string `json:"phone"`
Phone string `json:"phone_number"`
College string `json:"college"`
City string `json:"city"`
State string `json:"state"`
Expand Down

0 comments on commit 419c6d7

Please sign in to comment.