|
|
@@ -1,6 +1,8 @@
|
|
|
package permit_controller
|
|
|
|
|
|
import (
|
|
|
+ "crypto/md5"
|
|
|
+ "encoding/hex"
|
|
|
"fmt"
|
|
|
"fohow.com/libs/lib_redis"
|
|
|
"strconv"
|
|
|
@@ -24,7 +26,7 @@ import (
|
|
|
// "fohow.com/apps/models/order_model"
|
|
|
// "fohow.com/apps/models/product_model"
|
|
|
// "fohow.com/apps/models/shop_model"
|
|
|
- // "fohow.com/apps/models/sms_model"
|
|
|
+ "fohow.com/apps/models/sms_model"
|
|
|
"fohow.com/apps/models/user_model"
|
|
|
// "fohow.com/apps/models/wx_gongzhonghao_model"
|
|
|
"fohow.com/cache"
|
|
|
@@ -735,250 +737,43 @@ func (self *PermitController) Logout() {
|
|
|
self.ReturnError(200, apps.HasLogout, "", nil)
|
|
|
}
|
|
|
|
|
|
-// // 微信开放平台登录
|
|
|
-// func (self *PermitController) WxOpenLogin() {
|
|
|
-// cb := self.GetString("cb")
|
|
|
-// u := strings.Split(uuid.NewV4().String(), "-")[0]
|
|
|
-// state := fmt.Sprintf("loginCb[%s]", u)
|
|
|
-// cache.Cache.Put(state, cb, 60*time.Second)
|
|
|
-// appId := beego.AppConfig.String("WxOpenAppId")
|
|
|
-// redirectURI := fmt.Sprintf("%s/login/open/after",
|
|
|
-// beego.AppConfig.String("ApiHost"))
|
|
|
-// url := wx_open.AuthCodeURL(appId, redirectURI, "snsapi_login", state)
|
|
|
-// self.Redirect(url, 302)
|
|
|
-// return
|
|
|
-// }
|
|
|
-
|
|
|
-// //微信开放平台登录
|
|
|
-// func (self *PermitController) AfterWxOpenLogin() {
|
|
|
-// scope := "snsapi_login"
|
|
|
-// code := self.GetString("code")
|
|
|
-// state := self.GetString("state")
|
|
|
-// a := beego.AppConfig.String("WxOpenAppId")
|
|
|
-// s := beego.AppConfig.String("WxOpenAppSecret")
|
|
|
-// redirectURI := fmt.Sprintf("%s/after_wx_open_login",
|
|
|
-// beego.AppConfig.String("ApiHost"))
|
|
|
-// token, err := wx_open.AuthExchangeToken(code, a, s, redirectURI, scope)
|
|
|
-// if err != nil {
|
|
|
-// self.ReturnError(403, apps.NetworkBusy, "", nil)
|
|
|
-// }
|
|
|
-// openOpenid := token.OpenId
|
|
|
-// unionId := token.UnionId
|
|
|
-// // 这里不能取缓存数据,因为UserId这个字段在外部有可能已被赋值
|
|
|
-// wxUser := user_model.GetWxUserByUnionid(unionId, false)
|
|
|
-// if wxUser == nil {
|
|
|
-// info, err := wx_open.AuthUserInfo(token.AccessToken, redirectURI, scope, openOpenid, a, s)
|
|
|
-// if err == nil {
|
|
|
-// ip := self.Ctx.Input.IP()
|
|
|
-// wxUser = new(user_model.WxUser).Create("", openOpenid, token.UnionId, info.Nickname,
|
|
|
-// info.City, info.Country, info.Province, ip, int64(info.Sex), 1, time.Now().Unix())
|
|
|
-// //上传头像至alioss
|
|
|
-// go wxUser.UploadHead(info.HeadImageURL)
|
|
|
-// }
|
|
|
-// } else {
|
|
|
-// if wxUser.OpenOpenid != openOpenid {
|
|
|
-// wxUser.OpenOpenid = openOpenid
|
|
|
-// go wxUser.UpdateField("OpenOpenid")
|
|
|
-// }
|
|
|
-// }
|
|
|
-// self.SetSession(apps.SessionWxUserKey, wxUser.Id)
|
|
|
-// // 如果微信用户已绑定手机,则找出userId,并且赋值给session[userId]
|
|
|
-// if wxUser.UserId > 0 {
|
|
|
-// self.SetSession(apps.SessionUserKey, wxUser.UserId)
|
|
|
-// }
|
|
|
-// if cbUrl, ok := cache.Cache.Get(state).(string); ok {
|
|
|
-// if cbUrl == "" {
|
|
|
-// if wxUser.UserId <= 0 {
|
|
|
-// self.Redirect(fmt.Sprintf("%s/user/binding/state", beego.AppConfig.String("WWWHost")), 302)
|
|
|
-// return
|
|
|
-
|
|
|
-// }
|
|
|
-// self.Redirect(beego.AppConfig.String("WWWHost"), 302)
|
|
|
-// return
|
|
|
-// }
|
|
|
-// self.Redirect(cbUrl, 302)
|
|
|
-// return
|
|
|
-// } else {
|
|
|
-// self.Redirect(beego.AppConfig.String("WWWHost"), 302)
|
|
|
-// return
|
|
|
-// }
|
|
|
-// self.ReturnError(403, apps.NetworkBusy, "", nil)
|
|
|
-// }
|
|
|
-
|
|
|
-// //PC端手机号码登录
|
|
|
-// func (self *PermitController) TelLogin() {
|
|
|
-// //防止用户先登录微信user,未绑定手机,同时又使用tel登录,默认清除wxuser的session
|
|
|
-// self.DelSession(apps.SessionWxUserKey)
|
|
|
-
|
|
|
-// tel := self.GetString("tel")
|
|
|
-// pwd := self.GetString("pwd")
|
|
|
-
|
|
|
-// user := user_model.GetByTel(tel, false)
|
|
|
-// signUpURL := fmt.Sprintf("%s/v1/signup", beego.AppConfig.String("ApiHost"))
|
|
|
-// if user == nil {
|
|
|
-// self.ReturnError(403, apps.UserNotExist, signUpURL, nil)
|
|
|
-// }
|
|
|
-// md5Ctx := md5.New()
|
|
|
-// md5Ctx.Write([]byte(pwd))
|
|
|
-// cipherStr := md5Ctx.Sum(nil)
|
|
|
-// md5Pwd := hex.EncodeToString(cipherStr)
|
|
|
-
|
|
|
-// if user.Pwd != md5Pwd {
|
|
|
-// self.ReturnError(403, apps.LoginPasswordError, "", nil)
|
|
|
-// }
|
|
|
-// self.SetSession(apps.SessionUserKey, user.Id)
|
|
|
-// // 找出微信用户
|
|
|
-// wxUser := user_model.GetWxUserByUserId(user.Id, false)
|
|
|
-// if wxUser != nil {
|
|
|
-// self.SetSession(apps.SessionWxUserKey, wxUser.Id)
|
|
|
-// }
|
|
|
-// // self.Data["json"] = "ok"
|
|
|
-// self.ServeJSON()
|
|
|
-// }
|
|
|
-
|
|
|
-// //使用key登录,key通过GenerateLoginKey生成
|
|
|
-// func (self *PermitController) KeyLogin() {
|
|
|
-// //不支持微信端
|
|
|
-// if self.IsWxClient() {
|
|
|
-// self.ReturnError(403, apps.NoExist, "", nil)
|
|
|
-// }
|
|
|
-// key := self.Ctx.Input.Param(":key")
|
|
|
-// uId, _ := self.GetInt64("user_id")
|
|
|
-
|
|
|
-// if key == "" || uId == 0 {
|
|
|
-// self.ReturnError(403, apps.ParamsRequired, "", nil)
|
|
|
-// }
|
|
|
-
|
|
|
-// k := cache.GetKey(cache.WapAutoLoginKey, uId)
|
|
|
-// //校验key
|
|
|
-// if s, ok := cache.Cache.Get(k).(string); ok {
|
|
|
-// // beego.BeeLogger.Warn("11111111, k:%s, s: %s, key: %s, uId: %d", k, s, key, uId)
|
|
|
-// if s == key {
|
|
|
-// // self.DelSession(apps.SessionUserKey)
|
|
|
-// self.SetSession(apps.SessionUserKey, uId)
|
|
|
-// //销毁缓存
|
|
|
-// cache.Cache.Delete(k)
|
|
|
-// } else {
|
|
|
-// self.ReturnError(403, apps.NoExist, "", nil)
|
|
|
-// }
|
|
|
-// } else {
|
|
|
-// self.ReturnError(403, apps.NoExist, "", nil)
|
|
|
-// }
|
|
|
-
|
|
|
-// // self.Data["json"] = "ok"
|
|
|
-// self.ServeJSON()
|
|
|
-// }
|
|
|
-
|
|
|
-// //PC端注册
|
|
|
-// func (self *PermitController) SignUp() {
|
|
|
-// code := self.GetString("code")
|
|
|
-// tel := self.GetString("tel")
|
|
|
-// k := fmt.Sprintf("%s%s", sms_model.SIGN_UP, tel)
|
|
|
-// if cacheCode, ok := cache.Cache.Get(k).(string); ok {
|
|
|
-// if code != cacheCode {
|
|
|
-// self.ReturnError(403, apps.TelCodesError, "", nil)
|
|
|
-// }
|
|
|
-// } else {
|
|
|
-// //验证码过期
|
|
|
-// self.ReturnError(403, apps.TelCodesExpired, "", nil)
|
|
|
-// }
|
|
|
-
|
|
|
-// user := user_model.GetByTel(tel, false)
|
|
|
-// if user == nil {
|
|
|
-// loginPwd := tool.Get8Uuid()
|
|
|
-// md5Ctx := md5.New()
|
|
|
-// md5Ctx.Write([]byte(loginPwd))
|
|
|
-// cipherStr := md5Ctx.Sum(nil)
|
|
|
-// md5Pwd := hex.EncodeToString(cipherStr)
|
|
|
-// ip := self.Ctx.Input.IP()
|
|
|
-// user = user_model.Create(tel, md5Pwd, ip)
|
|
|
-// // 注册渠道处理
|
|
|
-// cId, _ := strconv.ParseInt(self.Ctx.GetCookie("sign_up_channel"), 10, 64)
|
|
|
-// channel := user_model.GetSignUpChannelById(cId, true)
|
|
|
-// if channel != nil {
|
|
|
-// user.SignupChannelId = cId
|
|
|
-// user.Save()
|
|
|
-// // wpsvip注册的用户,因为真功夫项目的,需要通知赠送稻米
|
|
|
-// if cId == 8 {
|
|
|
-// key1 := beego.AppConfig.String("CookieWpsVipUId")
|
|
|
-// key2 := beego.AppConfig.String("CookieWpsVipExtra")
|
|
|
-// wpsUserId, _ := strconv.ParseInt(self.Ctx.GetCookie(key1), 10, 64)
|
|
|
-// extra := self.Ctx.GetCookie(key2)
|
|
|
-// go wps.Reward(wpsUserId, extra, wps.OT_ZGF_ZHUC)
|
|
|
-// go wps_user_model.CreateWpsUser(wpsUserId, user.Id, 0, extra)
|
|
|
-// }
|
|
|
-// }
|
|
|
-// sign, template, action := sms_model.GetAliMsgContent(sms_model.LOGIN_PWD)
|
|
|
-// go sms_model.SendSmsWithAli([]string{tel}, sign, template, action, loginPwd)
|
|
|
-// } else {
|
|
|
-// self.ReturnError(403, apps.PhoneExist, "", nil)
|
|
|
-// }
|
|
|
-
|
|
|
-// self.SetSession(apps.SessionUserKey, user.Id)
|
|
|
-// //如果是体验金专题页面点击过来的,也送
|
|
|
-// key := beego.AppConfig.String("TYJName")
|
|
|
-// c := self.Ctx.GetCookie(key)
|
|
|
-
|
|
|
-// if c != "" {
|
|
|
-// id, err := strconv.ParseInt(c, 10, 64)
|
|
|
-// if err == nil {
|
|
|
-// trialInfo := trial_coin_model.GetTrialCoinById(id, true)
|
|
|
-// if trialInfo != nil && trialInfo.Deadline.Unix() >= time.Now().Unix() {
|
|
|
-// new(trial_coin_model.TrialCoinOrder).Create(user.Id, trialInfo.Id, trialInfo.Amount)
|
|
|
-// }
|
|
|
-// }
|
|
|
-// }
|
|
|
-
|
|
|
-// self.Data["json"] = user_model.User{Tel: tel}
|
|
|
-// self.ServeJSON()
|
|
|
-// }
|
|
|
-
|
|
|
-// //忘记密码
|
|
|
-// func (self *PermitController) ResetPwd() {
|
|
|
-// code := self.GetString("code")
|
|
|
-// tel := self.GetString("tel")
|
|
|
-// pwd := self.GetString("pwd")
|
|
|
-// confirmedPwd := self.GetString("confirmed_pwd")
|
|
|
-// if pwd != confirmedPwd {
|
|
|
-// self.ReturnError(403, apps.PasswordError, "", nil)
|
|
|
-// }
|
|
|
+//忘记密码
|
|
|
+func (self *PermitController) ResetPwd() {
|
|
|
+ code := self.GetString("code")
|
|
|
+ tel := self.GetString("tel")
|
|
|
+ pwd := self.GetString("pwd")
|
|
|
+ confirmedPwd := self.GetString("confirmed_pwd")
|
|
|
+ if pwd != confirmedPwd {
|
|
|
+ self.ReturnError(403, apps.PasswordError, "", nil)
|
|
|
+ }
|
|
|
|
|
|
-// lengthPwd := len(pwd)
|
|
|
-// if lengthPwd < 6 || lengthPwd > 20 {
|
|
|
-// self.ReturnError(403, apps.PasswordLengthError, "", nil)
|
|
|
-// }
|
|
|
+ lengthPwd := len(pwd)
|
|
|
+ if lengthPwd < 6 || lengthPwd > 20 {
|
|
|
+ self.ReturnError(403, apps.PasswordLengthError, "", nil)
|
|
|
+ }
|
|
|
|
|
|
-// k := fmt.Sprintf("%s%s", sms_model.RESET_PWD, tel)
|
|
|
-// if cacheCode, ok := cache.Cache.Get(k).(string); ok {
|
|
|
-// if code != cacheCode {
|
|
|
-// self.ReturnError(403, apps.TelCodesError, "", nil)
|
|
|
-// }
|
|
|
-// } else {
|
|
|
-// //验证码过期
|
|
|
-// self.ReturnError(403, apps.TelCodesExpired, "", nil)
|
|
|
-// }
|
|
|
-// md5Ctx := md5.New()
|
|
|
-// md5Ctx.Write([]byte(pwd))
|
|
|
-// cipherStr := md5Ctx.Sum(nil)
|
|
|
-// md5Pwd := hex.EncodeToString(cipherStr)
|
|
|
-
|
|
|
-// user := user_model.GetByTel(tel, false)
|
|
|
-// if user == nil {
|
|
|
-// self.ReturnError(403, apps.UserNotExist, "", nil)
|
|
|
-// } else {
|
|
|
-// user.Pwd = md5Pwd
|
|
|
-// user.Save()
|
|
|
-// }
|
|
|
+ k := fmt.Sprintf("%s%s", sms_model.RESET_PWD, tel)
|
|
|
+ if cacheCode, ok := cache.Cache.Get(k).(string); ok {
|
|
|
+ if code != cacheCode {
|
|
|
+ self.ReturnError(403, apps.TelCodesError, "", nil)
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ //验证码过期
|
|
|
+ self.ReturnError(403, apps.TelCodesExpired, "", nil)
|
|
|
+ }
|
|
|
+ md5Ctx := md5.New()
|
|
|
+ md5Ctx.Write([]byte(pwd))
|
|
|
+ cipherStr := md5Ctx.Sum(nil)
|
|
|
+ md5Pwd := hex.EncodeToString(cipherStr)
|
|
|
|
|
|
-// self.Data["json"] = user_model.User{Tel: tel}
|
|
|
-// self.ServeJSON()
|
|
|
-// }
|
|
|
+ user := user_model.GetByTel(tel, false)
|
|
|
+ if user == nil {
|
|
|
+ self.ReturnError(403, apps.UserNotExist, "", nil)
|
|
|
+ } else {
|
|
|
+ user.Pwd = md5Pwd
|
|
|
+ user.Save()
|
|
|
+ }
|
|
|
|
|
|
-// func createXkUser(uid, openid string) {
|
|
|
-// if uid == "" || openid == "" {
|
|
|
-// return
|
|
|
-// }
|
|
|
-// url := fmt.Sprintf("http://api.xikego.com/v1/createwxuser/superd5c/%s/%s", uid, openid)
|
|
|
-// tool.PostJSON(url, nil)
|
|
|
-// return
|
|
|
-// }
|
|
|
+ self.Data["json"] = user_model.User{Tel: tel}
|
|
|
+ self.ServeJSON()
|
|
|
+}
|