Skip to content

Commit

Permalink
fix(login): correct checking overdue (#40)
Browse files Browse the repository at this point in the history
  • Loading branch information
amtoaer authored Nov 15, 2021
1 parent 944a052 commit 160d5db
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 10 deletions.
6 changes: 0 additions & 6 deletions pkg/cmd/login.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,6 @@ var (
info.FormattedBalance(),
info.FormattedTraffic(),
info.FormattedUsedTime())
if info.Overdue {
console.InfoL("\t状态\t已欠费")
}
}
return nil
},
Expand All @@ -83,9 +80,6 @@ func login(h *handler.IpgwHandler, account *model.Account) error {
return err
}
info := h.GetInfo()
if info.Overdue {
return fmt.Errorf("overdue")
}
if info.Username == "" {
return fmt.Errorf("unknown reason")
}
Expand Down
11 changes: 8 additions & 3 deletions pkg/handler/ipgw.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package handler

import (
"encoding/json"
"fmt"
"io/ioutil"
"net/http"
"net/url"
Expand Down Expand Up @@ -43,22 +44,27 @@ func NewIpgwHandler() *IpgwHandler {
func (h *IpgwHandler) Login(account *model.Account) error {
var (
password string
body string
err error
)
if account.Cookie != "" {
_, err = h.loginCookie(account.Cookie) // 通过cookie登录
body, err = h.loginCookie(account.Cookie) // 通过cookie登录
} else {
password, err = account.GetPassword()
if err != nil {
return err
}
_, err = h.login(account.Username, password) // 通过用户名、密码登录
body, err = h.login(account.Username, password) // 通过用户名、密码登录
}

if err != nil {
return err
}

if strings.Contains(body, "Arrearage users") {
return fmt.Errorf("overdue")
}

return h.ParseBasicInfo() // 解析信息
}

Expand Down Expand Up @@ -145,7 +151,6 @@ func getUsernameAndIPFromJson(data map[string]interface{}) (username, ip string)
func (h *IpgwHandler) ParseBasicInfo() error {
h.getJsonIpgwData()
h.info.Username, h.info.IP = getUsernameAndIPFromJson(h.oriInfo)
h.info.Overdue = h.oriInfo["user_balance"].(float64) < 0
return nil
}

Expand Down
1 change: 0 additions & 1 deletion pkg/model/info.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ type Info struct {
IP string
Traffic, UsedTime int
Balance float64
Overdue bool
}

func (i *Info) FormattedTraffic() string {
Expand Down

0 comments on commit 160d5db

Please sign in to comment.