diff options
Diffstat (limited to 'auth/controller.go')
-rw-r--r-- | auth/controller.go | 28 |
1 files changed, 27 insertions, 1 deletions
diff --git a/auth/controller.go b/auth/controller.go index bc9f15a..901d204 100644 --- a/auth/controller.go +++ b/auth/controller.go @@ -20,11 +20,17 @@ package auth import ( "vidhukant.com/openbills/user" "golang.org/x/crypto/bcrypt" + "github.com/spf13/viper" "github.com/gin-gonic/gin" "net/http" ) -func handleSignIn (ctx *gin.Context) { +var COST int +func init() { + COST = viper.GetInt("cryptography.password_hashing_cost") +} + +func handleSignUp (ctx *gin.Context) { var user user.User ctx.Bind(&user) @@ -53,3 +59,23 @@ func handleSignIn (ctx *gin.Context) { "data": user, }) } + +func handleSignIn (ctx *gin.Context) { + var u user.User + ctx.Bind(&u) + + var err error + + err = user.CheckPassword(u.ID, u.Password) + if err != nil { + // TODO: handle potential errors + ctx.Error(err) + ctx.Abort() + return + } + + ctx.JSON(http.StatusOK, gin.H{ + "message": "success", + "data": u, + }) +} |