initial commit

This commit is contained in:
kandrusyak
2023-06-23 20:51:41 +03:00
parent 438dc1a716
commit 8e9eeb989c
13 changed files with 458 additions and 0 deletions

29
handler/auth.go Normal file
View File

@@ -0,0 +1,29 @@
package handler
import (
"astra-users/model"
"crypto/sha256"
"fmt"
"github.com/labstack/echo/v4"
"net/http"
)
func (h *Handler) Login(c echo.Context) (err error) {
// Bind
u := new(model.User)
if err = c.Bind(u); err != nil {
return
}
u.Password = fmt.Sprintf("%x", sha256.Sum256([]byte(u.Password)))
var t = h.DB.Where("user_name = ? AND password = ?", u.UserName, u.Password).First(&u)
if t.RowsAffected == 0 {
return c.NoContent(http.StatusNotFound)
}
u.Password = ""
return c.JSON(http.StatusOK, u)
}