mirror of https://github.com/mindoc-org/mindoc.git
feat:增加HTTP接口登录校验
parent
f0d0ef674b
commit
827965b492
|
@ -137,7 +137,8 @@ ldap_filter=objectClass=posixAccount
|
||||||
|
|
||||||
############# HTTP自定义接口登录 ################
|
############# HTTP自定义接口登录 ################
|
||||||
http_login_url=
|
http_login_url=
|
||||||
|
#md5计算的秘钥
|
||||||
|
http_login_secret=hzsp*THJUqwbCU%s
|
||||||
##################################
|
##################################
|
||||||
|
|
||||||
###############配置CDN加速##################
|
###############配置CDN加速##################
|
||||||
|
|
|
@ -2,6 +2,8 @@
|
||||||
package models
|
package models
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"crypto/md5"
|
||||||
|
"encoding/hex"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
@ -9,6 +11,7 @@ import (
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
"regexp"
|
"regexp"
|
||||||
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
@ -164,7 +167,16 @@ func (m *Member) httpLogin(account, password string) (*Member, error) {
|
||||||
return nil, ErrMemberAuthMethodInvalid
|
return nil, ErrMemberAuthMethodInvalid
|
||||||
}
|
}
|
||||||
|
|
||||||
val := url.Values{"": []string{""}}
|
val := url.Values{
|
||||||
|
"account": []string{account},
|
||||||
|
"password": []string{password},
|
||||||
|
"time": []string{strconv.FormatInt(time.Now().Unix(), 10)},
|
||||||
|
}
|
||||||
|
h := md5.New()
|
||||||
|
h.Write([]byte(val.Encode() + beego.AppConfig.DefaultString("http_login_secret","")))
|
||||||
|
|
||||||
|
val.Add("sn", hex.EncodeToString(h.Sum(nil)))
|
||||||
|
|
||||||
resp, err := http.PostForm(urlStr, val)
|
resp, err := http.PostForm(urlStr, val)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
beego.Error("通过接口登录失败 -> ", urlStr, account, err)
|
beego.Error("通过接口登录失败 -> ", urlStr, account, err)
|
||||||
|
|
Loading…
Reference in New Issue