feat:增加HTTP接口登录校验

pull/536/head
lifei6671 2019-05-21 10:09:37 +08:00
parent f0d0ef674b
commit 827965b492
2 changed files with 15 additions and 2 deletions

View File

@ -137,7 +137,8 @@ ldap_filter=objectClass=posixAccount
############# HTTP自定义接口登录 ################
http_login_url=
#md5计算的秘钥
http_login_secret=hzsp*THJUqwbCU%s
##################################
###############配置CDN加速##################

View File

@ -2,6 +2,8 @@
package models
import (
"crypto/md5"
"encoding/hex"
"encoding/json"
"errors"
"fmt"
@ -9,6 +11,7 @@ import (
"net/http"
"net/url"
"regexp"
"strconv"
"strings"
"time"
@ -164,7 +167,16 @@ func (m *Member) httpLogin(account, password string) (*Member, error) {
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)
if err != nil {
beego.Error("通过接口登录失败 -> ", urlStr, account, err)