Implement user login with password hash verification and username lookup

This commit is contained in:
2025-05-15 12:24:48 +03:30
parent b3fae6b80c
commit d646515776
5 changed files with 39 additions and 8 deletions

View File

@@ -61,15 +61,30 @@ func (appContext *AdminDashboardHandler) Register(c *gin.Context) {
"success": false,
"error": "failed to create user",
})
} else {
c.JSON(200, gin.H{
"success": true,
})
}
c.JSON(200, gin.H{
"success": true,
})
}
func (appContext *AdminDashboardHandler) Login(c *gin.Context) {
c.JSON(200, gin.H{
"YouAreOn": "Login",
})
var input requestmodels.LoginInput
if err := c.ShouldBindJSON(&input); err != nil {
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
return
}
var user = appContext.AppContext.UserService.GetUserByUsername(input.Username)
if auth.CheckPasswordHash(input.Password, user.Password) && user.IsVerified { // TODO: Add verification process
c.JSON(200, gin.H{
"success": true,
})
} else {
c.JSON(200, gin.H{
"success": false,
})
}
}