Skip to content

Commit

Permalink
optimize account
Browse files Browse the repository at this point in the history
  • Loading branch information
YangSen-qn committed Aug 30, 2023
1 parent 95cd61d commit 9531234
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
17 changes: 13 additions & 4 deletions iqshell/common/account/actions.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,12 +116,21 @@ func getAccount(pt string) (account Account, err *data.CodeError) {
}

acc, dErr := decrypt(string(accountBytes))
if dErr != nil {
err = data.NewEmptyError().AppendDescF("Decrypt account bytes: %s, you can delete account file(%s) and use `account` command to reset the account", dErr, pt)
if dErr == nil {
account = acc
return
}
account = acc
return

if len(acc.Name) == 0 {
return account, data.NewEmptyError().AppendDescF("Decrypt account bytes: %s, you can delete account file(%s) and use `account` command to reset the account", dErr, pt)
}

accs, lErr := LookUp(acc.Name)
if lErr != nil || len(accs) == 0 {
return account, data.NewEmptyError().AppendDescF("Decrypt account bytes: %s, you can delete account file(%s) and use `account` command to reset the account", dErr, pt)
}

return accs[0], nil
}

// qshell 会记录当前的user信息,当切换账户后, 老的账户信息会记录下来
Expand Down
4 changes: 4 additions & 0 deletions iqshell/common/account/crypt.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ func splits(joinStr string) []string {
// 对保存在account.json中的文件字符串进行揭秘操作, 返回Account
func decrypt(joinStr string) (acc Account, err *data.CodeError) {
ss := splits(joinStr)
if len(ss) > 0 {
acc.Name = ss[0]
}

if len(ss) != 3 {
err = data.NewEmptyError().AppendDescF("account json style format error")
return
Expand Down

0 comments on commit 9531234

Please sign in to comment.