MCPcopy Create free account
hub / github.com/OpenAtomFoundation/SmartIDE / loginAndSaveToken

Function loginAndSaveToken

cli/cmd/login.go:114–136  ·  view source on GitHub ↗

登录

(loginUrl, userName, userPassword string)

Source from the content-addressed store, hash-verified

112
113// 登录
114func loginAndSaveToken(loginUrl, userName, userPassword string) error {
115 url := fmt.Sprint(loginUrl, "/api/smartide/base/cliLogin")
116 params := map[string]interface{}{"username": userName, "password": userPassword}
117 headers := map[string]string{"Content-Type": "application/json"}
118 var response string
119
120 httpClient := common.CreateHttpClientEnableRetry()
121 response, err := httpClient.PostJson(url, params, headers)
122 if err != nil {
123 return err
124 }
125 code := gojsonq.New().JSONString(response).Find("code").(float64)
126 if code != 0 {
127 msg := gojsonq.New().JSONString(response).Find("msg")
128 return fmt.Errorf("login fail %q", msg)
129 } else {
130 token := gojsonq.New().JSONString(response).Find("data.token")
131 common.SmartIDELog.AddEntryptionKeyWithReservePart(fmt.Sprint(token)) // token 加密输出
132 saveToken(loginUrl, userName, token)
133 }
134
135 return nil
136}
137
138func saveToken(loginUrl, userName string, token interface{}) {
139 c := &config.GlobalSmartIdeConfig

Callers 1

login.goFile · 0.85

Calls 4

saveTokenFunction · 0.85
PostJsonMethod · 0.80
FindMethod · 0.80

Tested by

no test coverage detected