hello world
This commit is contained in:
34
endpoints/login.go
Normal file
34
endpoints/login.go
Normal file
@@ -0,0 +1,34 @@
|
||||
package endpoints
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"git.zomo.dev/zomo/discord-retokenizer/storage"
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
type LoginBody struct {
|
||||
Username string `json:"username" binding:"required"`
|
||||
Password string `json:"password" binding:"required"`
|
||||
}
|
||||
|
||||
func login(c *gin.Context) {
|
||||
var loginBody LoginBody
|
||||
if err := c.BindJSON(&loginBody); err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
|
||||
loggedIn, token := storage.CheckLogin(loginBody.Username, loginBody.Password)
|
||||
|
||||
if loggedIn {
|
||||
c.JSON(200, gin.H{
|
||||
"token": token,
|
||||
})
|
||||
} else {
|
||||
c.JSON(401, gin.H{
|
||||
"error": "invalid username or password",
|
||||
})
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user