-
Notifications
You must be signed in to change notification settings - Fork 0
/
login.go
49 lines (39 loc) · 939 Bytes
/
login.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package handlers
import (
"context"
"net/http"
"github.com/gin-gonic/gin"
"github.com/neo4j/neo4j-go-driver/v5/neo4j"
"github.com/pulpchat/pulpspot/db/models"
"go.uber.org/zap"
)
type LoginRequest struct {
Username string `json:"organization_email"`
Password string `json:"organization_password"`
}
func DefaultLoginRequest() *LoginRequest {
return &LoginRequest{
Username: "",
Password: "",
}
}
func LoginHandler(ctx context.Context, logger *zap.SugaredLogger, neoSess neo4j.SessionWithContext) gin.HandlerFunc {
return func(c *gin.Context) {
user := models.DefaultUser()
lr := DefaultLoginRequest()
err := c.BindJSON(&lr)
if err != nil {
logger.Debugf("failed to bind user json: %v", err)
c.JSON(http.StatusBadRequest, gin.H{
"error": err.Error(),
})
return
}
logger.Debugln(user)
c.JSON(http.StatusOK, gin.H{
"data": map[string]interface{}{
"id": "user.ID",
},
})
}
}