MCPcopy Create free account
hub / github.com/aiprodcoder/MIXAPI / Login

Function Login

controller/user.go:27–66  ·  view source on GitHub ↗
(c *gin.Context)

Source from the content-addressed store, hash-verified

25}
26
27func Login(c *gin.Context) {
28 if !common.PasswordLoginEnabled {
29 c.JSON(http.StatusOK, gin.H{
30 "message": "管理员关闭了密码登录",
31 "success": false,
32 })
33 return
34 }
35 var loginRequest LoginRequest
36 err := json.NewDecoder(c.Request.Body).Decode(&loginRequest)
37 if err != nil {
38 c.JSON(http.StatusOK, gin.H{
39 "message": "无效的参数",
40 "success": false,
41 })
42 return
43 }
44 username := loginRequest.Username
45 password := loginRequest.Password
46 if username == "" || password == "" {
47 c.JSON(http.StatusOK, gin.H{
48 "message": "无效的参数",
49 "success": false,
50 })
51 return
52 }
53 user := model.User{
54 Username: username,
55 Password: password,
56 }
57 err = user.ValidateAndFill()
58 if err != nil {
59 c.JSON(http.StatusOK, gin.H{
60 "message": err.Error(),
61 "success": false,
62 })
63 return
64 }
65 setupLogin(&user, c)
66}
67
68// setup session & cookies and then return user info
69func setupLogin(user *model.User, c *gin.Context) {

Callers

nothing calls this directly

Calls 3

ValidateAndFillMethod · 0.95
setupLoginFunction · 0.85
ErrorMethod · 0.80

Tested by

no test coverage detected