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

Function UpdateCurrentUserInfo

core/app/auth/auth.go:263–293  ·  view source on GitHub ↗
(c *gin.Context, req dto.CurrentUserUpdate)

Source from the content-addressed store, hash-verified

261 return repo.NewISettingRepo().Update("ExpirationTime", buildPasswordExpirationTime(expiredDays))
262}
263func UpdateCurrentUserInfo(c *gin.Context, req dto.CurrentUserUpdate) error {
264 settingRepo := repo.NewISettingRepo()
265 currentName, err := settingRepo.GetValueByKey("UserName")
266 if err != nil {
267 return err
268 }
269 shouldDeleteSession := len(req.Password) != 0 || req.Name != currentName
270 if len(req.Password) != 0 {
271 if len(req.OldPassword) == 0 {
272 return buserr.New("ErrInitialPassword")
273 }
274 oldPassword, err := base64.StdEncoding.DecodeString(req.OldPassword)
275 if err != nil {
276 return err
277 }
278 newPassword, err := base64.StdEncoding.DecodeString(req.Password)
279 if err != nil {
280 return err
281 }
282 if err := HandlePasswordExpired(c, string(oldPassword), string(newPassword)); err != nil {
283 return err
284 }
285 }
286 if err := settingRepo.Update("UserName", req.Name); err != nil {
287 return err
288 }
289 if shouldDeleteSession {
290 deleteCurrentSession(c)
291 }
292 return nil
293}
294
295func GenerateApiKey() (string, error) {
296 apiKey := common.RandStr(32)

Callers

nothing calls this directly

Calls 4

GetValueByKeyMethod · 0.95
UpdateMethod · 0.95
HandlePasswordExpiredFunction · 0.85
deleteCurrentSessionFunction · 0.85

Tested by

no test coverage detected