Skip to content

Commit

Permalink
feat(123): support mail login (close #2218 pr #2276)
Browse files Browse the repository at this point in the history
  • Loading branch information
Code2qing committed Nov 10, 2022
1 parent 4286548 commit c601bb7
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
19 changes: 15 additions & 4 deletions drivers/123/util.go
Expand Up @@ -6,21 +6,32 @@ 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"
)

// 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
}
Expand Down
9 changes: 9 additions & 0 deletions pkg/utils/email.go
@@ -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)
}

0 comments on commit c601bb7

Please sign in to comment.