- localpass added.
This commit is contained in:
@@ -23,6 +23,7 @@ var (
|
||||
|
||||
var (
|
||||
ErrLoginTypeNotSupported = errors.New("不支持指定的登录类型")
|
||||
ErrUIDAndPassNotMatch = errors.New("用户与密码不匹配")
|
||||
)
|
||||
|
||||
type LoginInfo struct {
|
||||
|
||||
37
business/jxcallback/auth/localpass/localpass.go
Normal file
37
business/jxcallback/auth/localpass/localpass.go
Normal file
@@ -0,0 +1,37 @@
|
||||
package localpass
|
||||
|
||||
import (
|
||||
"crypto/md5"
|
||||
"fmt"
|
||||
|
||||
"git.rosy.net.cn/jx-callback/business/jxcallback/auth"
|
||||
"git.rosy.net.cn/jx-callback/business/model"
|
||||
"git.rosy.net.cn/jx-callback/globals/gormdb"
|
||||
)
|
||||
|
||||
const (
|
||||
LoginType = "localpass"
|
||||
)
|
||||
|
||||
type Auther struct {
|
||||
}
|
||||
|
||||
func init() {
|
||||
auth.RegisterAuther(LoginType, new(Auther))
|
||||
}
|
||||
|
||||
func (a *Auther) Login(uname, password string) (err error) {
|
||||
user := &model.JxBackendUser{}
|
||||
db := gormdb.GetDB()
|
||||
if err = db.Where("uname = ?", uname).First(user).Error; err == nil {
|
||||
if fmt.Sprintf("%x", md5.Sum([]byte(password))) == user.UPass {
|
||||
return nil
|
||||
}
|
||||
err = auth.ErrUIDAndPassNotMatch
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
func (a *Auther) Logout(openid string) error {
|
||||
return nil
|
||||
}
|
||||
@@ -8,8 +8,10 @@ import (
|
||||
"git.rosy.net.cn/baseapi/platformapi/weixinsnsapi"
|
||||
"git.rosy.net.cn/baseapi/utils"
|
||||
"git.rosy.net.cn/jx-callback/business/jxcallback/auth"
|
||||
"git.rosy.net.cn/jx-callback/business/model"
|
||||
"git.rosy.net.cn/jx-callback/globals"
|
||||
"git.rosy.net.cn/jx-callback/globals/api"
|
||||
"git.rosy.net.cn/jx-callback/globals/gormdb"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -55,14 +57,20 @@ func GetUserInfo(code string, state string) (token *UserInfoExt, err error) {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
func (a *Auther) Login(openid, password string) error {
|
||||
func (a *Auther) Login(openid, password string) (err error) {
|
||||
if value := globals.Cacher.Get(openid); value != nil {
|
||||
if password == value.(string) {
|
||||
globals.Cacher.Del(openid)
|
||||
return nil
|
||||
wxUser := &model.WeiXins{}
|
||||
db := gormdb.GetDB()
|
||||
if err = db.Where("openid = ?", openid).First(wxUser).Error; err == nil {
|
||||
globals.Cacher.Del(openid)
|
||||
return nil
|
||||
}
|
||||
}
|
||||
} else {
|
||||
err = ErrLoginFailed
|
||||
}
|
||||
return ErrLoginFailed
|
||||
return err
|
||||
}
|
||||
|
||||
func (a *Auther) Logout(openid string) error {
|
||||
|
||||
Reference in New Issue
Block a user