|
|
@@ -0,0 +1,154 @@
|
|
|
+package service
|
|
|
+
|
|
|
+import (
|
|
|
+ //"fmt"
|
|
|
+ //"server/dao/gorm"
|
|
|
+ //"server/dao/short_msg"
|
|
|
+ //"server/dao/wx"
|
|
|
+ //"server/errors"
|
|
|
+ //"server/function"
|
|
|
+ //"server/model"
|
|
|
+ //"server/utils"
|
|
|
+ //"strconv"
|
|
|
+ //"time"
|
|
|
+
|
|
|
+ "github.com/mojocn/base64Captcha"
|
|
|
+)
|
|
|
+
|
|
|
+var store = base64Captcha.DefaultMemStore
|
|
|
+
|
|
|
+type Auth struct {
|
|
|
+ base
|
|
|
+}
|
|
|
+
|
|
|
+//
|
|
|
+//func (a Auth) SignOut(session *model.Session) (logInfo string) {
|
|
|
+// user := a.getUser(session)
|
|
|
+// function.Session{}.Delete(session)
|
|
|
+// logInfo = fmt.Sprintf("用户[%s]退出", user.GetShowName())
|
|
|
+// return
|
|
|
+//}
|
|
|
+//func (a Auth) SignIn(
|
|
|
+// verifyName string,
|
|
|
+// password string,
|
|
|
+// channel model.LoginChannel,
|
|
|
+// picId string,
|
|
|
+// picCode string,
|
|
|
+// ip string) (sess *model.Session, logInfo string) {
|
|
|
+// var user *model.User
|
|
|
+//
|
|
|
+// defer func() {
|
|
|
+// if p := recover(); p == nil {
|
|
|
+// logInfo = fmt.Sprintf("用户[%s]在%s登录成功", user.GetShowName(), channel)
|
|
|
+// } else {
|
|
|
+// panic(p)
|
|
|
+// }
|
|
|
+// }()
|
|
|
+//
|
|
|
+// if !store.Verify(picId, picCode, true) {
|
|
|
+// panic(errors.ErrPicVerifyCode)
|
|
|
+// }
|
|
|
+//
|
|
|
+// dao := gorm.UserDAO{}
|
|
|
+// shopDao := gorm.ShopDAO{}
|
|
|
+// user = dao.GetUserByVerifyName(verifyName)
|
|
|
+// user.CheckStatus()
|
|
|
+// shop, _ := shopDao.ShopDetailOne(user.ShopId)
|
|
|
+// shop.CheckShopStatus()
|
|
|
+//
|
|
|
+// if !dao.PasswordCorrect(user.Id, password) {
|
|
|
+// panic(errors.ErrPassword)
|
|
|
+// }
|
|
|
+// sess = function.Auth{}.LoginUser(user, channel, "", ip)
|
|
|
+//
|
|
|
+// return
|
|
|
+//}
|
|
|
+
|
|
|
+func (Auth) GenVerifyPic(config *base64Captcha.DriverString) (id string, pic string) {
|
|
|
+ var (
|
|
|
+ err error
|
|
|
+ )
|
|
|
+
|
|
|
+ driver := config.ConvertFonts()
|
|
|
+
|
|
|
+ c := base64Captcha.NewCaptcha(driver, store)
|
|
|
+ id, pic, err = c.Generate()
|
|
|
+ if err != nil {
|
|
|
+ panic(err)
|
|
|
+ }
|
|
|
+
|
|
|
+ return id, pic
|
|
|
+}
|
|
|
+
|
|
|
+// 手机号发送短信验证码
|
|
|
+func (a Auth) GenVFCode(codeTypeInt int, name string, ip string,
|
|
|
+ picId string,
|
|
|
+ picCode string) {
|
|
|
+ //if !store.Verify(picId, picCode, true) {
|
|
|
+ // panic(errors.ErrPicVerifyCode)
|
|
|
+ //}
|
|
|
+ //_ = dao.User{}.GetUserByPhone(name)
|
|
|
+ //codeType := model.VFCodeCodeTypeFromInt(codeTypeInt)
|
|
|
+ //vfcodeDao := dao.VFCode{}
|
|
|
+ //nameLastSend := vfcodeDao.NameLastSendTime(codeType, name)
|
|
|
+ //ipLastSend := vfcodeDao.IpLastSendTime(ip)
|
|
|
+ //
|
|
|
+ //// 手机号发送间隔
|
|
|
+ //const NameSendInterval = time.Second * 60
|
|
|
+ //// ip 发送间隔
|
|
|
+ //const IpSendInterval = time.Second * 1
|
|
|
+ //
|
|
|
+ //if time.Now().Sub(nameLastSend) < NameSendInterval {
|
|
|
+ // panic(errors.ErrSendTooFast)
|
|
|
+ //}
|
|
|
+ //if time.Now().Sub(ipLastSend) < IpSendInterval {
|
|
|
+ // panic(errors.ErrSendTooFast)
|
|
|
+ //}
|
|
|
+ //
|
|
|
+ //code := strconv.Itoa(utils.RandomInt(6))
|
|
|
+ //
|
|
|
+ //smDAO := short_msg.NewShortMsg()
|
|
|
+ //smDAO.SendVFCode(name, code, codeType)
|
|
|
+ //
|
|
|
+ //vfcodeDao.Save(codeType, name, code, time.Now().Add(time.Minute*3), ip)
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
+//func (a Auth) PhoneSignIn(phone string, code string, channel model.LoginChannel, ip string) (
|
|
|
+// sess *model.Session, logInfo string) {
|
|
|
+//
|
|
|
+// gorm.VFCodeDAO{}.CheckVFCode(model.VFCodeCodeTypeLogin, phone, code)
|
|
|
+//
|
|
|
+// user := gorm.UserDAO{}.GetUserByPhone(phone)
|
|
|
+// user.CheckStatus()
|
|
|
+//
|
|
|
+// sess = function.Auth{}.WxLoginUser(user, channel, "", ip, phone, user.Phone)
|
|
|
+// logInfo = fmt.Sprintf("用户[%s]通过手机验证码登录", user.Name)
|
|
|
+// return
|
|
|
+//}
|
|
|
+
|
|
|
+//func (a Auth) PassEdit(sess *model.Session, oldpass string, newpass string) (
|
|
|
+// logInfo string, err error) {
|
|
|
+// user := a.getUser(sess)
|
|
|
+// userDAO := gorm.UserDAO{}
|
|
|
+// if !userDAO.PasswordCorrect(user.Id, oldpass) {
|
|
|
+// err = errors.ErrNamePwdIncorrect
|
|
|
+// return
|
|
|
+// }
|
|
|
+// err = userDAO.ShopManagerPassEdit(user, newpass)
|
|
|
+// if err != nil {
|
|
|
+// return
|
|
|
+// }
|
|
|
+// logInfo = fmt.Sprintf("用户[%s]修改密码", user.Name)
|
|
|
+// return
|
|
|
+//}
|
|
|
+//
|
|
|
+//func (a Auth) CheckPhone(phone string) (
|
|
|
+// md5 string) {
|
|
|
+//
|
|
|
+// user := gorm.UserDAO{}.CheckPhone(phone)
|
|
|
+// user.CheckStatus()
|
|
|
+//
|
|
|
+// md5 = user.UserMd5
|
|
|
+// return
|
|
|
+//}
|