- mini program login
This commit is contained in:
@@ -1,11 +1,15 @@
|
||||
package mobile
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"math/rand"
|
||||
"time"
|
||||
|
||||
"git.rosy.net.cn/baseapi/utils"
|
||||
"git.rosy.net.cn/jx-callback/business/jxcallback/auth"
|
||||
"git.rosy.net.cn/jx-callback/business/model/dao"
|
||||
"git.rosy.net.cn/jx-callback/business/model/legacymodel"
|
||||
"git.rosy.net.cn/jx-callback/globals"
|
||||
"git.rosy.net.cn/jx-callback/globals/api"
|
||||
"github.com/KenmyZhang/aliyun-communicate"
|
||||
@@ -15,6 +19,22 @@ const (
|
||||
DefVerifyCodeDuration = 5 * time.Minute
|
||||
)
|
||||
|
||||
const (
|
||||
LoginType = "mobile"
|
||||
)
|
||||
|
||||
type Auther struct {
|
||||
}
|
||||
|
||||
var (
|
||||
auther *Auther
|
||||
)
|
||||
|
||||
func init() {
|
||||
auther = new(Auther)
|
||||
auth.RegisterAuther(LoginType, auther)
|
||||
}
|
||||
|
||||
func SendVerifyCode(mobileNumber string) error {
|
||||
code := fmt.Sprintf("%06d", rand.Intn(1000000))
|
||||
globals.SugarLogger.Debugf("SendVerifyCode mobileNumber:%s, code:%s", mobileNumber, code)
|
||||
@@ -42,3 +62,22 @@ func VerifyCode(mobileNumber, code string) bool {
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func (a *Auther) Login(mobileNum, verifyCode string) (userID string, err error) {
|
||||
if VerifyCode(mobileNum, verifyCode) {
|
||||
user := &legacymodel.WeiXins{
|
||||
Tel: mobileNum,
|
||||
}
|
||||
db := dao.GetDB()
|
||||
if err = dao.GetEntity(db, user, "Tel"); err != nil {
|
||||
err = auth.ConvertErr2NoUser(err, mobileNum)
|
||||
}
|
||||
} else {
|
||||
err = errors.New("验证错误")
|
||||
}
|
||||
return "", err
|
||||
}
|
||||
|
||||
func (a *Auther) Logout(loginInfo *auth.LoginInfo) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user