initial commit
This commit is contained in:
29
handler/auth.go
Normal file
29
handler/auth.go
Normal 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)
|
||||
}
|
||||
Reference in New Issue
Block a user