Remove Repository and use Database instead
This commit is contained in:
@ -68,7 +68,7 @@ func (h *Handler) loginPost(c *gin.Context) {
|
||||
username, _ := c.GetPostForm("username")
|
||||
password, _ := c.GetPostForm("password")
|
||||
|
||||
user, err := h.Service.DB.GetUserByUsername(c.Request.Context(), username)
|
||||
user, err := h.Service.GetUserByUsername(c.Request.Context(), username)
|
||||
if err != nil {
|
||||
c.AbortWithError(http.StatusUnauthorized, err)
|
||||
return
|
||||
@ -84,7 +84,7 @@ func (h *Handler) loginPost(c *gin.Context) {
|
||||
c.AbortWithError(http.StatusUnauthorized, err)
|
||||
}
|
||||
|
||||
go h.Service.DB.UpdateLastLogin(context.Background(), user.ID)
|
||||
go h.Service.UpdateLastLogin(context.Background(), user.ID)
|
||||
|
||||
maxAge := (int)((expiration * time.Hour).Seconds())
|
||||
c.SetCookie(authCookie, t, maxAge, "", "", false, true)
|
||||
@ -98,7 +98,7 @@ func (h *Handler) registerPost(c *gin.Context) {
|
||||
password, _ := c.GetPostForm("password")
|
||||
name, _ := c.GetPostForm("name")
|
||||
|
||||
_, err := h.Service.DB.GetUserByUsername(c.Request.Context(), email)
|
||||
_, err := h.Service.GetUserByUsername(c.Request.Context(), email)
|
||||
if err == nil {
|
||||
c.AbortWithStatus(http.StatusUnauthorized)
|
||||
return
|
||||
@ -115,7 +115,7 @@ func (h *Handler) registerPost(c *gin.Context) {
|
||||
Password: hash,
|
||||
Email: email,
|
||||
}
|
||||
_, err = h.Service.DB.CreateUser(c.Request.Context(), createUser)
|
||||
_, err = h.Service.CreateUser(c.Request.Context(), createUser)
|
||||
if err != nil {
|
||||
c.AbortWithError(http.StatusInternalServerError, err)
|
||||
}
|
||||
|
Reference in New Issue
Block a user