删除历史无用的代码
This commit is contained in:
@@ -1,110 +0,0 @@
|
||||
package auth
|
||||
|
||||
// const (
|
||||
// DefTokenDuration = 7 * 24 * time.Hour // 7天
|
||||
// )
|
||||
|
||||
// type IAuther interface {
|
||||
// Login(id, secret string) (userID, loginType string, err error)
|
||||
// Logout(loginInfo *LoginInfo) error
|
||||
// }
|
||||
|
||||
// var (
|
||||
// authers map[string]IAuther
|
||||
// )
|
||||
|
||||
// var (
|
||||
// ErrUserNotExist = errors.New("用户不存在,请联系运营创建")
|
||||
// ErrLoginTypeNotSupported = errors.New("不支持指定的登录类型")
|
||||
// ErrUIDAndPassNotMatch = errors.New("用户与密码不匹配")
|
||||
// ErrAPINeedRealLogin = errors.New("此API要求真正登录")
|
||||
// ErrIllegalLoginType = errors.New("不支持的登录类型")
|
||||
// )
|
||||
|
||||
// type LoginInfo struct {
|
||||
// ID string
|
||||
// LoginType string
|
||||
// ExpiresIn int64
|
||||
// Token string
|
||||
// }
|
||||
|
||||
// func init() {
|
||||
// authers = make(map[string]IAuther)
|
||||
// }
|
||||
|
||||
// func RegisterAuther(loginType string, handler IAuther) {
|
||||
// authers[loginType] = handler
|
||||
// }
|
||||
|
||||
// func CreateLoginInfo(id, loginType string) (loginInfo *LoginInfo) {
|
||||
// token := utils.GetUUID()
|
||||
// loginInfo = &LoginInfo{
|
||||
// ID: id,
|
||||
// LoginType: loginType,
|
||||
// ExpiresIn: time.Now().Add(DefTokenDuration).Unix(),
|
||||
// Token: token,
|
||||
// }
|
||||
// globals.SugarLogger.Debugf("CreateLoginInfo id:%s, loginType:%s, loginInfo:%s", id, loginType, utils.Format4Output(loginInfo, true))
|
||||
// api.Cacher.Set(token, loginInfo, DefTokenDuration)
|
||||
// return loginInfo
|
||||
// }
|
||||
|
||||
// func Login(id, loginType, secret string) (loginInfo *LoginInfo, err error) {
|
||||
// globals.SugarLogger.Debugf("Login id:%s, loginType:%s, secret:%s", id, loginType, secret)
|
||||
// if handler := authers[loginType]; handler != nil {
|
||||
// userID, loginType2, err2 := handler.Login(id, secret)
|
||||
// if err = err2; err == nil {
|
||||
// if userID != "" {
|
||||
// globals.SugarLogger.Debugf("Login id:%s, loginType:%s, id changed to:%s", id, loginType, userID)
|
||||
// id = userID
|
||||
// }
|
||||
// if loginType2 != "" {
|
||||
// loginType = loginType2
|
||||
// }
|
||||
// return CreateLoginInfo(id, loginType), nil
|
||||
// }
|
||||
// err = ConvertErr2NoUser(err, "")
|
||||
// } else {
|
||||
// err = ErrLoginTypeNotSupported
|
||||
// }
|
||||
// return nil, err
|
||||
// }
|
||||
|
||||
// func Logout(token string) (err error) {
|
||||
// globals.SugarLogger.Debugf("Logout token:%s", token)
|
||||
// loginInfo := new(LoginInfo)
|
||||
// if err = api.Cacher.GetAs(token, loginInfo); err == nil {
|
||||
// if handler := authers[loginInfo.LoginType]; handler != nil {
|
||||
// err = handler.Logout(loginInfo)
|
||||
// }
|
||||
// api.Cacher.Del(token)
|
||||
// }
|
||||
// return err
|
||||
// }
|
||||
|
||||
// func GetUserInfo(token string) (loginInfo *LoginInfo, err error) {
|
||||
// loginInfo = new(LoginInfo)
|
||||
// if err = api.Cacher.GetAs(token, loginInfo); err == nil {
|
||||
// return loginInfo, nil
|
||||
// }
|
||||
// return nil, model.ErrTokenIsInvalid
|
||||
// }
|
||||
|
||||
// func ConvertErr2NoUser(err error, mobileNum string) error {
|
||||
// if dao.IsNoRowsError(err) {
|
||||
// err = ErrUserNotExist
|
||||
// }
|
||||
// return err
|
||||
// }
|
||||
|
||||
// func (a *LoginInfo) GetAuthID() string {
|
||||
// return a.ID
|
||||
// }
|
||||
|
||||
// func (a *LoginInfo) GetAuthType() string {
|
||||
// return a.LoginType
|
||||
// }
|
||||
|
||||
// func (a *LoginInfo) GetUserTag() string {
|
||||
// return a.ID
|
||||
// }
|
||||
@@ -1,90 +0,0 @@
|
||||
package mobile
|
||||
|
||||
// const (
|
||||
// DefVerifyCodeDuration = 5 * time.Minute
|
||||
// TestMobile = "91112345678"
|
||||
// TestVerifyCode = "123456"
|
||||
// )
|
||||
|
||||
// var (
|
||||
// warningMap = map[string]int{
|
||||
// "isv.AMOUNT_NOT_ENOUGH": 1,
|
||||
// "isv.ACCOUNT_ABNORMAL": 1,
|
||||
// "isv.OUT_OF_SERVICE": 1,
|
||||
// "isv.DAY_LIMIT_CONTROL": 1,
|
||||
// }
|
||||
// )
|
||||
|
||||
// const (
|
||||
// LoginType = "mobile"
|
||||
// )
|
||||
|
||||
// var (
|
||||
// ErrVerifyCodeIsWrong = errors.New("验证码错")
|
||||
// )
|
||||
|
||||
// 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)
|
||||
|
||||
// smsClient := aliyunsmsclient.New("http://dysmsapi.aliyuncs.com/")
|
||||
// response, err := smsClient.Execute(globals.AliKey, globals.AliSecret, mobileNumber, "京西菜市", "SMS_175583158", string(utils.MustMarshal(map[string]interface{}{
|
||||
// "code": code,
|
||||
// })))
|
||||
// api.Cacher.Set(mobileNumber, code, DefVerifyCodeDuration)
|
||||
// if err == nil && response.Code == aliyunsmsclient.ResponseCodeOk {
|
||||
// } else {
|
||||
// if err == nil {
|
||||
// if warningMap[response.Code] == 1 {
|
||||
// globals.SugarLogger.Warnf("SendVerifyCode mobileNumber:%s failed with response:%s", mobileNumber, utils.Format4Output(response, false))
|
||||
// } else {
|
||||
// globals.SugarLogger.Infof("SendVerifyCode mobileNumber:%s failed with response:%s", mobileNumber, utils.Format4Output(response, false))
|
||||
// }
|
||||
// err = fmt.Errorf("发送短信出错:%s", response.Message)
|
||||
// } else {
|
||||
// globals.SugarLogger.Warnf("SendVerifyCode mobileNumber:%s failed with error:%v", mobileNumber, err)
|
||||
// }
|
||||
// }
|
||||
// return err
|
||||
// }
|
||||
|
||||
// func VerifyCode(mobileNumber, code string) (err error) {
|
||||
// globals.SugarLogger.Debugf("VerifyCode mobileNumber:%s, code:%s", mobileNumber, code)
|
||||
|
||||
// err = ErrVerifyCodeIsWrong
|
||||
// if mobileNumber == TestMobile && code == TestVerifyCode {
|
||||
// err = nil
|
||||
// } else {
|
||||
// if value := api.Cacher.Get(mobileNumber); value != nil {
|
||||
// if code == value.(string) {
|
||||
// api.Cacher.Del(mobileNumber)
|
||||
// err = nil
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// return err
|
||||
// }
|
||||
|
||||
// func (a *Auther) Login(mobileNum, verifyCode string) (userID, LoginType string, err error) {
|
||||
// if err = VerifyCode(mobileNum, verifyCode); err == nil {
|
||||
// _, err = dao.GetWeiXinUserByIDs(dao.GetDB(), mobileNum, "", "", "")
|
||||
// err = auth.ConvertErr2NoUser(err, mobileNum)
|
||||
// }
|
||||
// return "", "", err
|
||||
// }
|
||||
|
||||
// func (a *Auther) Logout(loginInfo *auth.LoginInfo) error {
|
||||
// return nil
|
||||
// }
|
||||
@@ -1,8 +0,0 @@
|
||||
package mobile
|
||||
|
||||
// func TestSendVerifyCode(t *testing.T) {
|
||||
// err := SendVerifyCode("18180948107")
|
||||
// if err != nil {
|
||||
// t.Fatal(err)
|
||||
// }
|
||||
// }
|
||||
@@ -1,249 +0,0 @@
|
||||
package weixin
|
||||
|
||||
// const (
|
||||
// LoginType = "weixinsns"
|
||||
// LoginTypeMiniProgram = "weixinmini"
|
||||
// DefTempPasswordDuration = 20 * time.Minute // 登录时间限制在5分钟内
|
||||
// )
|
||||
|
||||
// const (
|
||||
// CacheKeySeparator = "/"
|
||||
// MiniVerifyCodePrefix = "MiniVerifyCode"
|
||||
// SessionKeyPrefix = "SessionKey"
|
||||
// )
|
||||
|
||||
// var (
|
||||
// StrStateIsWrong = "state:%s状态不对"
|
||||
// )
|
||||
|
||||
// var (
|
||||
// auther *Auther
|
||||
// AutherMini *AutherMiniProgram
|
||||
// )
|
||||
|
||||
// var (
|
||||
// ErrExceptionalLogin = errors.New("登录异常,超时,请重走绑定流程")
|
||||
// )
|
||||
|
||||
// type Auther struct {
|
||||
// }
|
||||
|
||||
// type AutherMiniProgram struct {
|
||||
// }
|
||||
|
||||
// type UserInfoExt struct {
|
||||
// weixinapi.SNSUserInfo
|
||||
// TempPassword string `json:"tempPassword"` // 一段时间有效的登录密码
|
||||
// LoginInfo *auth.LoginInfo `json:"loginInfo"`
|
||||
// }
|
||||
|
||||
// func init() {
|
||||
// auther = new(Auther)
|
||||
// auth.RegisterAuther(LoginType, auther)
|
||||
|
||||
// AutherMini = new(AutherMiniProgram)
|
||||
// auth.RegisterAuther(LoginTypeMiniProgram, AutherMini)
|
||||
// }
|
||||
|
||||
// func cacheSNSInfo(wxUserinfo *weixinapi.SNSUserInfo, password string, duration time.Duration) {
|
||||
// api.Cacher.Set(wxUserinfo.OpenID, password, duration)
|
||||
// api.Cacher.Set(wxUserinfo.OpenID+".sns", wxUserinfo, duration)
|
||||
// }
|
||||
|
||||
// func getSNSInfoFromCache(openID string) (wxUserinfo *weixinapi.SNSUserInfo, password string) {
|
||||
// password, _ = api.Cacher.Get(openID).(string)
|
||||
// wxUserinfo = new(weixinapi.SNSUserInfo)
|
||||
// if err := api.Cacher.GetAs(openID+".sns", wxUserinfo); err != nil {
|
||||
// wxUserinfo = nil
|
||||
// }
|
||||
// return wxUserinfo, password
|
||||
// }
|
||||
|
||||
// func GetWeiXinUserInfo(code string, state string) (userInfo *UserInfoExt, err error) {
|
||||
// globals.SugarLogger.Debugf("GetUserInfo code:%s", code)
|
||||
// if state == "" {
|
||||
// token, err2 := api.WeixinAPI.SNSRetrieveToken(code)
|
||||
// if err = err2; err == nil {
|
||||
// wxUserinfo, err2 := api.WeixinAPI.SNSGetUserInfo(token.AccessToken, token.OpenID)
|
||||
// if err = err2; err == nil {
|
||||
// userInfo = &UserInfoExt{
|
||||
// SNSUserInfo: *wxUserinfo,
|
||||
// TempPassword: utils.GetUUID(),
|
||||
// }
|
||||
// globals.SugarLogger.Debugf("GetUserInfo code:%s, userInfo:%s", code, utils.Format4Output(userInfo, true))
|
||||
// cacheSNSInfo(wxUserinfo, userInfo.TempPassword, DefTempPasswordDuration)
|
||||
// user, err2 := dao.GetWeiXinUserByIDs(dao.GetDB(), "", wxUserinfo.UnionID, wxUserinfo.OpenID, "")
|
||||
// if err = err2; err == nil {
|
||||
// userInfo.LoginInfo = auth.CreateLoginInfo(user.Tel, mobile.LoginType)
|
||||
// } else if !dao.IsNoRowsError(err) { // 非用户不存在错误,报错
|
||||
// return nil, err
|
||||
// }
|
||||
// return userInfo, nil
|
||||
// }
|
||||
// }
|
||||
// } else {
|
||||
// err = fmt.Errorf(StrStateIsWrong, state)
|
||||
// }
|
||||
// return nil, err
|
||||
// }
|
||||
|
||||
// // 此函数需要调整
|
||||
// func (a *Auther) Login(openid, password string) (userID, LoginType string, err error) {
|
||||
// globals.SugarLogger.Debugf("weixinsns Login openid:%s, password:%s", openid, password)
|
||||
// _, cachedPwd := getSNSInfoFromCache(openid)
|
||||
// if cachedPwd != "" && password == cachedPwd {
|
||||
// api.Cacher.Del(openid)
|
||||
// return "", "", nil
|
||||
// }
|
||||
// return "", "", ErrExceptionalLogin
|
||||
// }
|
||||
|
||||
// func (a *Auther) Logout(loginInfo *auth.LoginInfo) error {
|
||||
// return nil
|
||||
// }
|
||||
|
||||
// func BindMobile(token, mobileNum, code, nickname string) (err error) {
|
||||
// globals.SugarLogger.Debugf("BindMobile token:%s, mobileNum:%s, code:%s, nickname:%s", token, mobileNum, code, nickname)
|
||||
|
||||
// loginInfo := new(auth.LoginInfo)
|
||||
// if err = api.Cacher.GetAs(token, loginInfo); err == nil {
|
||||
// if err = mobile.VerifyCode(mobileNum, code); err == nil {
|
||||
// wxUserinfo, _ := getSNSInfoFromCache(loginInfo.ID)
|
||||
// if wxUserinfo == nil {
|
||||
// return fmt.Errorf("绑定超时,请重新绑定")
|
||||
// }
|
||||
// if nickname == "" {
|
||||
// nickname = wxUserinfo.NickName
|
||||
// }
|
||||
// err = auth.ConvertErr2NoUser(dao.UpdateWeiXinUser(dao.GetDB(), mobileNum, nickname, wxUserinfo.UnionID, wxUserinfo.OpenID, ""), mobileNum)
|
||||
// }
|
||||
// }
|
||||
// jxutils.HandleUserWXRemark(nil, mobileNum, false)
|
||||
// return err
|
||||
// }
|
||||
|
||||
// // 绑定手机加登录
|
||||
// func BindMobile2(openid, secret, mobileNum, verifyCode, nickname string) (loginInfo *auth.LoginInfo, err error) {
|
||||
// globals.SugarLogger.Debugf("BindMobile2 openid:%s, secret:%s, mobileNum:%s, verifyCode:%s, nickname:%s", openid, secret, mobileNum, verifyCode, nickname)
|
||||
|
||||
// err = ErrExceptionalLogin
|
||||
// if value := api.Cacher.Get(openid); value != nil {
|
||||
// wxUserinfo, cachedSecret := getSNSInfoFromCache(openid)
|
||||
// if wxUserinfo == nil {
|
||||
// return nil, fmt.Errorf("绑定超时,请重新绑定")
|
||||
// }
|
||||
// if secret == cachedSecret {
|
||||
// if err = mobile.VerifyCode(mobileNum, verifyCode); err == nil {
|
||||
// api.Cacher.Del(openid)
|
||||
// err = nil
|
||||
// if nickname == "" {
|
||||
// nickname = wxUserinfo.NickName
|
||||
// }
|
||||
// if err = dao.UpdateWeiXinUser(dao.GetDB(), mobileNum, nickname, wxUserinfo.UnionID, wxUserinfo.OpenID, ""); err == nil {
|
||||
// loginInfo = auth.CreateLoginInfo(mobileNum, mobile.LoginType)
|
||||
// } else {
|
||||
// err = auth.ConvertErr2NoUser(err, mobileNum)
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// jxutils.HandleUserWXRemark(nil, mobileNum, false)
|
||||
// return loginInfo, err
|
||||
// }
|
||||
|
||||
// // 此函数已废弃
|
||||
// // 对于小程序来说,
|
||||
// // 1,用户必须先在后台创建(手机号标识)
|
||||
// // 2,用户必须先绑定微信
|
||||
// // 先以短信方式登录:
|
||||
// // SendMobileVerifyCode
|
||||
// // Login use type mobile
|
||||
// // MiniBindWeiXin
|
||||
// // 3,用户以CODE来登录(Login use type weixinmini)
|
||||
// // Login
|
||||
|
||||
// func (a *AutherMiniProgram) BindWeiXin(ctx *jxcontext.Context, code, nickName string) (err error) {
|
||||
// globals.SugarLogger.Debugf("AutherMiniProgram BindWeiXin code:%s, nickName:%s", code, nickName)
|
||||
// loginInfo := ctx.GetLoginInfo()
|
||||
// if loginInfo == nil || loginInfo.GetAuthType() != mobile.LoginType {
|
||||
// return fmt.Errorf("调用AutherMiniProgram BindWeiXin时,必须以手机验证方式登录")
|
||||
// }
|
||||
// sessionInfo, err := weixin2.ProxySNSCode2Session(code)
|
||||
// if err != nil {
|
||||
// return err
|
||||
// }
|
||||
// err = dao.UpdateWeiXinUser(dao.GetDB(), loginInfo.GetAuthID(), nickName, sessionInfo.UnionID, "", sessionInfo.OpenID)
|
||||
// return auth.ConvertErr2NoUser(err, "")
|
||||
// }
|
||||
|
||||
// // 绑定小程序
|
||||
// func (a *AutherMiniProgram) BindMiniProgram(ctx *jxcontext.Context, code string) (err error) {
|
||||
// globals.SugarLogger.Debugf("BindMiniProgram code:%s", code)
|
||||
// if ctx.GetLoginType() != mobile.LoginType {
|
||||
// return errors.New("登录方式应该为手机")
|
||||
// }
|
||||
// sessionInfo, err := weixin2.ProxySNSCode2Session(code)
|
||||
// if err != nil {
|
||||
// return err
|
||||
// }
|
||||
// db := dao.GetDB()
|
||||
// user, err := dao.GetWeiXinUserByIDs(db, ctx.GetLoginID(), "", "", "")
|
||||
// if err != nil {
|
||||
// return err
|
||||
// }
|
||||
// // if user.OpenIDUnion != sessionInfo.UnionID {
|
||||
// // return errors.New("绑定用户不匹配")
|
||||
// // }
|
||||
// err = auth.ConvertErr2NoUser(dao.UpdateWeiXinUser(db, user.Tel, "", sessionInfo.UnionID, "", sessionInfo.OpenID), user.Tel)
|
||||
// return err
|
||||
// }
|
||||
|
||||
// func (a *AutherMiniProgram) Login(mobileNum, code string) (userID, LoginType string, err error) {
|
||||
// globals.SugarLogger.Debugf("AutherMiniProgram Login mobileNum:%s, code:%s", mobileNum, code)
|
||||
// sessionInfo, err := weixin2.ProxySNSCode2Session(code)
|
||||
// if err != nil {
|
||||
// return "", "", err
|
||||
// }
|
||||
// globals.SugarLogger.Debugf("AutherMiniProgram Login code:%s, unionID:%s, openID:%s", code, sessionInfo.UnionID, sessionInfo.OpenID)
|
||||
// db := dao.GetDB()
|
||||
// user, err := dao.GetWeiXinUserByIDs(db, "", sessionInfo.UnionID, "", sessionInfo.OpenID)
|
||||
// if err != nil {
|
||||
// return "", "", auth.ConvertErr2NoUser(err, mobileNum)
|
||||
// }
|
||||
// if user.OpenIDMini != sessionInfo.OpenID {
|
||||
// user.OpenIDMini = sessionInfo.OpenID
|
||||
// dao.UpdateEntity(db, user, "OpenIDMini")
|
||||
// }
|
||||
// globals.SugarLogger.Debugf("AutherMiniProgram Login user.Tel:%s, code:%s, openID:%s", user.Tel, code, sessionInfo.OpenID)
|
||||
// if mobileNum != user.Tel {
|
||||
|
||||
// }
|
||||
// api.Cacher.Set(composeSessionKeyCacheKey(user.Tel), sessionInfo.SessionKey, auth.DefTokenDuration)
|
||||
// return user.Tel, mobile.LoginType, err
|
||||
// }
|
||||
|
||||
// func (a *AutherMiniProgram) Logout(loginInfo *auth.LoginInfo) error {
|
||||
// globals.SugarLogger.Debugf("AutherMiniProgram Logout openid:%s", utils.Format4Output(loginInfo, false))
|
||||
// return api.Cacher.Del(composeSessionKeyCacheKey(loginInfo.GetAuthID()))
|
||||
// }
|
||||
|
||||
// func (a *AutherMiniProgram) DecryptData(ctx *jxcontext.Context, encryptedData, iv string) (decryptedDataBase64 string, err error) {
|
||||
// globals.SugarLogger.Debugf("AutherMiniProgram DecryptData encryptedData:%s, iv:%s", encryptedData, iv)
|
||||
// var sessionKey string
|
||||
// if err = api.Cacher.GetAs(composeSessionKeyCacheKey(ctx.GetLoginInfo().GetAuthID()), &sessionKey); err != nil {
|
||||
// return "", err
|
||||
// }
|
||||
// decryptedData, err := weixin2.ProxySNSDecodeMiniProgramData(encryptedData, sessionKey, iv)
|
||||
// if err != nil {
|
||||
// return "", err
|
||||
// }
|
||||
// return base64.StdEncoding.EncodeToString(decryptedData), nil
|
||||
// }
|
||||
|
||||
// func composeMiniVerifiyCacheKey(key string) string {
|
||||
// return MiniVerifyCodePrefix + CacheKeySeparator + key
|
||||
// }
|
||||
|
||||
// func composeSessionKeyCacheKey(key string) string {
|
||||
// return SessionKeyPrefix + CacheKeySeparator + key
|
||||
// }
|
||||
Reference in New Issue
Block a user