parseUserFromCode returns user by username encoded in code. It returns nil if code or username is invalid.
(code string)
| 403 | // parseUserFromCode returns user by username encoded in code. |
| 404 | // It returns nil if code or username is invalid. |
| 405 | func parseUserFromCode(code string) (user *database.User) { |
| 406 | if len(code) <= tool.TimeLimitCodeLength { |
| 407 | return nil |
| 408 | } |
| 409 | |
| 410 | // Use tail hex username to query user |
| 411 | hexStr := code[tool.TimeLimitCodeLength:] |
| 412 | if b, err := hex.DecodeString(hexStr); err == nil { |
| 413 | if user, err = database.Handle.Users().GetByUsername(gocontext.TODO(), string(b)); user != nil { |
| 414 | return user |
| 415 | } else if !database.IsErrUserNotExist(err) { |
| 416 | log.Error("Failed to get user by name %q: %v", string(b), err) |
| 417 | } |
| 418 | } |
| 419 | |
| 420 | return nil |
| 421 | } |
| 422 | |
| 423 | // verify active code when active account |
| 424 | func verifyUserActiveCode(code string) (user *database.User) { |
no test coverage detected