aboutsummaryrefslogtreecommitdiff
path: root/auth/controller.go
diff options
context:
space:
mode:
authorVidhu Kant Sharma <vidhukant@vidhukant.com>2023-09-03 00:19:03 +0530
committerVidhu Kant Sharma <vidhukant@vidhukant.com>2023-09-03 00:19:03 +0530
commit616a151764fd1780eb0b6dc039d5a21539a8a01a (patch)
tree454f73e06880c3635c3f88a5787fd8fbc1c2b363 /auth/controller.go
parent65cb3603ad2682deacff47a72d9050e584a00488 (diff)
added login with id
Diffstat (limited to 'auth/controller.go')
-rw-r--r--auth/controller.go28
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,
+ })
+}