diff --git a/main.go b/main.go index 518159f..5bbe346 100644 --- a/main.go +++ b/main.go @@ -7,6 +7,12 @@ import ( "fmt" ) +// UserLogin Object to recive user credentials in JSON format +type UserLogin struct { + Username string `json:"username" form:"username"` + Password string `json:"password" form:"password"` +} + func main() { // Set Engine diff --git a/models/user.go b/models/user.go index 8101ad6..77bcc47 100644 --- a/models/user.go +++ b/models/user.go @@ -3,9 +3,14 @@ package models import ( "fmt" "golang.org/x/crypto/bcrypt" - "git.mowie.cc/konrad/Library/routes" ) +// UserLogin Object to recive user credentials in JSON format +type UserLogin struct { + Username string `json:"username" form:"username"` + Password string `json:"password" form:"password"` +} + // User holds information about an user type User struct { ID int64 `xorm:"int(11) autoincr not null unique pk"` @@ -29,7 +34,7 @@ func HashPassword(password string) (string, error) { } // CheckUserCredentials checks user credentials -func CheckUserCredentials(u routes.UserLogin) (User, error) { +func CheckUserCredentials(u UserLogin) (User, error) { // Check if the user exists var user = User{Username: u.Username} diff --git a/routes/cors.go b/routes/cors.go index 9138004..16ec23a 100644 --- a/routes/cors.go +++ b/routes/cors.go @@ -6,11 +6,11 @@ import ( ) // SetCORSHeader sets relevant CORS headers for Cross-Site-Requests to the api -func SetCORSHeader (c echo.Context) error { +func SetCORSHeader(c echo.Context) error { res := c.Response() res.Header().Set("Access-Control-Allow-Origin", "*") res.Header().Set("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE") res.Header().Set("Access-Control-Allow-Headers", "authorization,content-type") res.Header().Set("Access-Control-Expose-Headers", "authorization,content-type") return c.String(http.StatusOK, "") -} \ No newline at end of file +} diff --git a/routes/login.go b/routes/login.go index c82a4d2..17e8873 100644 --- a/routes/login.go +++ b/routes/login.go @@ -8,15 +8,9 @@ import ( "time" ) -// User Login-Object to recive user credentials in JSON format -type UserLogin struct { - Username string `json:"username" form:"username"` - Password string `json:"password" form:"password"` -} - // Login is the login handler func Login(c echo.Context) error { - u := new(UserLogin) + u := new(models.UserLogin) if err := c.Bind(u); err != nil { return c.JSON(http.StatusBadRequest, models.Message{"Please provide a username and password."}) } diff --git a/routes/routes.go b/routes/routes.go index dca7526..305bd65 100644 --- a/routes/routes.go +++ b/routes/routes.go @@ -1,10 +1,10 @@ package routes import ( - apiv1 "git.mowie.cc/konrad/Library/routes/api/v1" "github.com/labstack/echo" "github.com/labstack/echo/middleware" + apiv1 "git.mowie.cc/konrad/Library/routes/api/v1" "git.mowie.cc/konrad/Library/models" )