MCPcopy Create free account
hub / github.com/1Panel-dev/1Panel / Login

Method Login

core/app/api/v2/auth.go:31–84  ·  view source on GitHub ↗

@Tags Auth @Summary User login @Accept json @Param EntranceCode header string true "安全入口 base64 加密串" @Param request body dto.Login true "request" @Success 200 {object} dto.UserLoginInfo @Router /core/auth/login [post]

(c *gin.Context)

Source from the content-addressed store, hash-verified

29// @Success 200 {object} dto.UserLoginInfo
30// @Router /core/auth/login [post]
31func (b *BaseApi) Login(c *gin.Context) {
32 var req dto.Login
33 if err := helper.CheckBindAndValidate(&req, c); err != nil {
34 return
35 }
36
37 ip := common.GetRealClientIP(c)
38 if global.IPTracker.IsLocked(ip) {
39 helper.BadAuth(c, "ErrLoginLocked", nil)
40 return
41 }
42 needCaptcha := global.IPTracker.NeedCaptcha(ip)
43 if needCaptcha {
44 if errMsg := captcha.VerifyCode(req.CaptchaID, req.Captcha); errMsg != "" {
45 helper.BadAuth(c, errMsg, nil)
46 return
47 }
48 }
49
50 entranceItem := c.Request.Header.Get("EntranceCode")
51 var entrance []byte
52 if len(entranceItem) != 0 {
53 entrance, _ = base64.StdEncoding.DecodeString(entranceItem)
54 }
55 if len(entrance) == 0 {
56 cookieValue, err := c.Cookie("SecurityEntrance")
57 if err == nil {
58 entrance, _ = base64.StdEncoding.DecodeString(cookieValue)
59 }
60 }
61
62 user, msgKey, err := xpack.AuthProvider.Login(c, req, string(entrance))
63 if user == nil || user.MfaStatus != constant.StatusEnable {
64 go saveLoginLogs(c, req.Name, wrapLoginErr(msgKey, err))
65 }
66 if msgKey == "ErrAuth" || msgKey == "ErrEntrance" || msgKey == "ErrNoneNode" {
67 if msgKey == "ErrAuth" {
68 global.IPTracker.RecordFailure(ip)
69 global.IPTracker.SetNeedCaptcha(ip)
70 }
71 helper.BadAuth(c, msgKey, err)
72 return
73 }
74 if err != nil {
75 global.IPTracker.RecordFailure(ip)
76 global.IPTracker.SetNeedCaptcha(ip)
77 helper.InternalServer(c, err)
78 return
79 }
80 if user == nil || user.MfaStatus != constant.StatusEnable {
81 global.IPTracker.Clear(ip)
82 }
83 helper.SuccessWithData(c, user)
84}
85
86// @Tags Auth
87// @Summary User login with mfa

Callers

nothing calls this directly

Calls 10

saveLoginLogsFunction · 0.85
wrapLoginErrFunction · 0.85
IsLockedMethod · 0.80
NeedCaptchaMethod · 0.80
SetNeedCaptchaMethod · 0.80
VerifyCodeMethod · 0.65
GetMethod · 0.65
LoginMethod · 0.65
ClearMethod · 0.65
RecordFailureMethod · 0.45

Tested by

no test coverage detected