feat(123): support mail login (close #2218 pr #2276)

pull/2338/head
Code2qing 2022-11-10 09:34:48 +08:00 committed by GitHub
parent 42865486f1
commit c601bb794b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 24 additions and 4 deletions

View File

@ -6,6 +6,7 @@ import (
"net/http"
"github.com/alist-org/alist/v3/drivers/base"
"github.com/alist-org/alist/v3/pkg/utils"
"github.com/go-resty/resty/v2"
jsoniter "github.com/json-iterator/go"
)
@ -13,14 +14,24 @@ import (
// do others that not defined in Driver interface
func (d *Pan123) login() error {
var body base.Json
url := "https://www.123pan.com/api/user/sign_in"
if utils.IsEmailFormat(d.Username) {
body = base.Json{
"mail": d.Username,
"password": d.Password,
"type": 2,
}
} else {
body = base.Json{
"passport": d.Username,
"password": d.Password,
}
}
var resp TokenResp
_, err := base.RestyClient.R().
SetResult(&resp).
SetBody(base.Json{
"passport": d.Username,
"password": d.Password,
}).Post(url)
SetBody(body).Post(url)
if err != nil {
return err
}

9
pkg/utils/email.go Normal file
View File

@ -0,0 +1,9 @@
package utils
import "regexp"
func IsEmailFormat(email string) bool {
pattern := `^[0-9a-z][_.0-9a-z-]{0,31}@([0-9a-z][0-9a-z-]{0,30}[0-9a-z]\.){1,4}[a-z]{2,4}$`
reg := regexp.MustCompile(pattern)
return reg.MatchString(email)
}