Skip to content

Commit

Permalink
feat(emozi): add api IsValid
Browse files Browse the repository at this point in the history
  • Loading branch information
fumiama committed Oct 14, 2024
1 parent b54f37c commit 6979a83
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions emozi/login.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"encoding/hex"
"encoding/json"
"errors"
"net/http"
"net/url"

"github.com/FloatTech/floatbox/binary"
Expand Down Expand Up @@ -65,3 +66,15 @@ func (usr *User) Login() error {
usr.auth = r.Get("result.token").Str
return nil
}

// IsValid 检查是否有效
func (usr *User) IsValid() bool {
if usr.name == "" || usr.pswd == "" || usr.auth == "" {
return false
}
_, err := web.RequestDataWithHeaders(http.DefaultClient, api+"", "GET", func(r *http.Request) error {
r.Header.Set("Authorization", usr.auth)
return nil
}, nil)
return err == nil
}

0 comments on commit 6979a83

Please sign in to comment.