MCPcopy
hub / github.com/awake1t/linglong / GetAuth

Function GetAuth

routers/api/auth.go:18–53  ·  view source on GitHub ↗
(c *gin.Context)

Source from the content-addressed store, hash-verified

16}
17
18func GetAuth(c *gin.Context) {
19 username := c.Query("username")
20 password := c.Query("password")
21
22 valid := validation.Validation{}
23 a := auth{Username: username, Password: password}
24 ok, _ := valid.Valid(&a)
25
26 data := make(map[string]interface{})
27 code := e.INVALID_PARAMS
28 if ok {
29 isExist := models.CheckAuth(username, password)
30 if isExist {
31 token, err := utils.GenerateToken(username, password)
32 if err != nil {
33 code = e.ERROR
34 } else {
35 data["token"] = token
36 code = e.SUCCESS
37 }
38
39 } else {
40 code = e.ERROR
41 }
42 } else {
43 for _, err := range valid.Errors {
44 log.Println(err.Key, err.Message)
45 }
46 }
47
48 c.JSON(http.StatusOK, gin.H{
49 "code" : code,
50 "msg" : e.GetMsg(code),
51 "data" : data,
52 })
53}

Callers

nothing calls this directly

Calls 3

CheckAuthFunction · 0.92
GenerateTokenFunction · 0.92
GetMsgFunction · 0.92

Tested by

no test coverage detected