|
|
|
|
package handler
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"server/call"
|
|
|
|
|
"server/common"
|
|
|
|
|
"server/config"
|
|
|
|
|
"server/db"
|
|
|
|
|
"server/modules/web/app"
|
|
|
|
|
"server/modules/web/values"
|
|
|
|
|
"server/util"
|
|
|
|
|
"time"
|
|
|
|
|
|
|
|
|
|
"github.com/liangdas/mqant/log"
|
|
|
|
|
|
|
|
|
|
"github.com/gin-gonic/gin"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
func onLogin(user *common.PlayerDBInfo, a *app.Gin, isNew bool) {
|
|
|
|
|
if user.Status != common.AccountStatusNormal || call.BlackListAndKick(user.Id, &common.BlackList{DeviceID: user.DeviceId, Phone: user.Mobile}) {
|
|
|
|
|
a.Code = values.CodeAccountLimit
|
|
|
|
|
log.Debug("uid:%v limit login", user.Id)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
channel := call.GetChannelByID(user.ChannelID)
|
|
|
|
|
gateURL := ""
|
|
|
|
|
if config.GetBase().Release && channel != nil && channel.URL != "" {
|
|
|
|
|
// gateURL = "gate." + channel.URL + config.GetConfig().Gate.WSPort
|
|
|
|
|
gateURL = "gate." + channel.URL
|
|
|
|
|
}
|
|
|
|
|
if gateURL == "" {
|
|
|
|
|
next, err := call.GetCaller().GetApp().Options().Selector.Select("gate")
|
|
|
|
|
if err != nil {
|
|
|
|
|
a.Code = values.CodeRetry
|
|
|
|
|
log.Error("err:%v", err)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
n, err := next()
|
|
|
|
|
if err != nil {
|
|
|
|
|
a.Code = values.CodeRetry
|
|
|
|
|
log.Error("err:%v", err)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
gateURL = n.Metadata["addr"]
|
|
|
|
|
}
|
|
|
|
|
// log.Debug("scheme:%v", a.Context.GetHeader("X-Forwarded-Proto"))
|
|
|
|
|
// if a.Context.Request.URL.Scheme == "https" {
|
|
|
|
|
gateURL = "wss://" + gateURL + ":26615"
|
|
|
|
|
// } else {
|
|
|
|
|
// gateURL = "ws://" + gateURL
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
uid := user.Id
|
|
|
|
|
token := ""
|
|
|
|
|
p := db.Redis().GetUserData(uid)
|
|
|
|
|
if p == nil {
|
|
|
|
|
token = util.RandomToken(uid)
|
|
|
|
|
if err := db.Redis().SetToken(uid, token); err != nil {
|
|
|
|
|
log.Error("err:%v", err)
|
|
|
|
|
a.Code = values.CodeRetry
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
user.Token = token
|
|
|
|
|
} else {
|
|
|
|
|
token = p.Token
|
|
|
|
|
user.Token = p.Token
|
|
|
|
|
db.Redis().AddUserExpire(uid, token)
|
|
|
|
|
}
|
|
|
|
|
user.Platform = a.DeviceType
|
|
|
|
|
|
|
|
|
|
if err := db.Redis().UpdateUserData(*user); err != nil {
|
|
|
|
|
log.Error("err:%v", err)
|
|
|
|
|
a.Code = values.CodeRetry
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ps := new(common.PlayerStatus)
|
|
|
|
|
// if err := db.Redis().HGetAll(common.GetRedisKeyPlayerStatus(uid), ps); err != nil && err != redis.Nil {
|
|
|
|
|
// log.Error("err:%v", err)
|
|
|
|
|
// a.Code = values.CodeRetry
|
|
|
|
|
// return
|
|
|
|
|
// }
|
|
|
|
|
resp := values.LoginResp{GateAddr: gateURL, UID: uid, Token: token}
|
|
|
|
|
// cid := user.ChannelID
|
|
|
|
|
a.Data = resp
|
|
|
|
|
ip := a.GetRemoteIP()
|
|
|
|
|
cid := user.ChannelID
|
|
|
|
|
birth := user.Birth
|
|
|
|
|
deviceType := user.Platform
|
|
|
|
|
country := user.Country
|
|
|
|
|
util.Go(func() {
|
|
|
|
|
update := map[string]interface{}{"ip": ip, "platform": deviceType, "last_login": time.Now().Unix()}
|
|
|
|
|
if country == "" {
|
|
|
|
|
update["country"] = call.GetCountry(ip)
|
|
|
|
|
}
|
|
|
|
|
if err := db.Mysql().Update(&common.PlayerDBInfo{Id: uid}, update); err != nil {
|
|
|
|
|
log.Error("err:%v", err)
|
|
|
|
|
}
|
|
|
|
|
call.InsertLoginRecord(uid, cid, ip, birth, deviceType)
|
|
|
|
|
|
|
|
|
|
// if db.Mysql().CountTable(common.PlayerRechargeTableName, fmt.Sprintf("uid = %d", uid)) == 0 {
|
|
|
|
|
// db.Mysql().C().Table(common.PlayerRechargeTableName).Create(&common.PlayerCurrency{UID: uid, ChannelID: cid})
|
|
|
|
|
// }
|
|
|
|
|
})
|
|
|
|
|
log.Debug("resp:%+v", resp)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func GuestLogin(c *gin.Context) {
|
|
|
|
|
a := app.NewApp(c)
|
|
|
|
|
defer func() {
|
|
|
|
|
a.Response()
|
|
|
|
|
}()
|
|
|
|
|
req := new(values.GuestLoginReq)
|
|
|
|
|
if !a.S(req) {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
log.Debug("data:%+v guest login", *req)
|
|
|
|
|
openID := common.GetAccountPre(common.AccountTypeGuest) + a.UUID
|
|
|
|
|
user, isNew := a.QueryUser(values.CommonLogin{AccountType: common.AccountTypeGuest, OpenID: openID, Nick: req.Nick, DeviceID: a.UUID,
|
|
|
|
|
Adid: req.Adid, Gpsadid: req.GPSAdid, Share: req.Share,
|
|
|
|
|
Fbc: a.Context.GetHeader("fbc"), Fbp: a.Context.GetHeader("fbp"), UserAgent: a.Context.GetHeader("User-Agent")})
|
|
|
|
|
if a.Code != values.CodeOK {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
onLogin(user, a, isNew)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func GetPhoneCode(c *gin.Context) {
|
|
|
|
|
a := app.NewApp(c)
|
|
|
|
|
defer func() {
|
|
|
|
|
if a.Code == values.CodePhoneCodeBusy {
|
|
|
|
|
a.Msg = "Too many requests,please try later."
|
|
|
|
|
} else if a.Code != values.CodeOK {
|
|
|
|
|
a.Msg = "OTP error"
|
|
|
|
|
}
|
|
|
|
|
a.Response()
|
|
|
|
|
}()
|
|
|
|
|
req := new(values.PhoneCodeReq)
|
|
|
|
|
if !a.S(req) {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
cid := a.Channel
|
|
|
|
|
if cid == 0 {
|
|
|
|
|
a.Code = values.CodeParam
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
if call.IsBlackListPlayer(&common.BlackList{Phone: req.Phone}) {
|
|
|
|
|
a.Code = values.CodeRetry
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
log.Debug("GetPhoneCode:%+v", *req)
|
|
|
|
|
code := values.RandomPhoneCode()
|
|
|
|
|
if !db.Redis().SetNX(common.GetRedisKeyCodeCD(req.Phone), code, common.RedisExpireCodeCD) {
|
|
|
|
|
a.Code = values.CodePhoneCodeBusy
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
if err := db.Redis().SetData(common.GetRedisKeyCode(req.Phone), code, common.RedisExpireCode); err != nil {
|
|
|
|
|
log.Error("err:%v", err)
|
|
|
|
|
a.Code = values.CodeRetry
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
if config.GetBase().Release {
|
|
|
|
|
if err := values.APISmsReq(req.Phone, code); err != nil {
|
|
|
|
|
log.Error("err:%v", err)
|
|
|
|
|
a.Code = values.CodeRetry
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
a.Data = code
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func VerifyCode(c *gin.Context) {
|
|
|
|
|
a := app.NewApp(c)
|
|
|
|
|
defer func() {
|
|
|
|
|
a.Response()
|
|
|
|
|
}()
|
|
|
|
|
req := new(values.PhoneCodeLoginReq)
|
|
|
|
|
if !a.S(req) {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
log.Debug("VerifyCode %+v", *req)
|
|
|
|
|
if !a.VerifyCode(req.Phone, req.Code) {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func PhoneRegist(c *gin.Context) {
|
|
|
|
|
a := app.NewApp(c)
|
|
|
|
|
defer func() {
|
|
|
|
|
a.Response()
|
|
|
|
|
}()
|
|
|
|
|
req := new(values.PhoneRegistReq)
|
|
|
|
|
if !a.S(req) {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
log.Debug("PhoneRegistReq login %+v", *req)
|
|
|
|
|
if a.Channel == 0 {
|
|
|
|
|
a.Code = values.CodeParam
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
if db.Mysql().Exist(&common.PlayerDBInfo{ChannelID: a.Channel, Mobile: req.Phone}) {
|
|
|
|
|
a.Code = values.CodeAccountAlreadyExist
|
|
|
|
|
a.Msg = "The phone number is already linked to another customer."
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
openID := common.GetAccountPre(common.AccountTypePhone) + req.Phone
|
|
|
|
|
user, isNew := a.QueryUser(values.CommonLogin{AccountType: common.AccountTypePhone, OpenID: openID, DeviceID: a.UUID,
|
|
|
|
|
Adid: req.Adid, Gpsadid: req.GPSAdid, Phone: req.Phone, Share: req.Share, Pass: req.Pass,
|
|
|
|
|
Fbc: a.Context.GetHeader("fbc"), Fbp: a.Context.GetHeader("fbp"), UserAgent: a.Context.GetHeader("User-Agent")})
|
|
|
|
|
if a.Code != values.CodeOK {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
onLogin(user, a, isNew)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func PhoneLogin(c *gin.Context) {
|
|
|
|
|
a := app.NewApp(c)
|
|
|
|
|
defer func() {
|
|
|
|
|
a.Response()
|
|
|
|
|
}()
|
|
|
|
|
req := new(values.PhoneLoginReq)
|
|
|
|
|
if !a.S(req) {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
log.Debug("PhoneLoginReq login %+v", *req)
|
|
|
|
|
if a.Channel == 0 {
|
|
|
|
|
a.Code = values.CodeParam
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
user := &common.PlayerDBInfo{ChannelID: a.Channel, Mobile: req.Phone}
|
|
|
|
|
db.Mysql().Get(user)
|
|
|
|
|
if user.Id == 0 {
|
|
|
|
|
a.Code = values.CodeAccountNotExist
|
|
|
|
|
a.Msg = "The phone number does not exist."
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
if req.Pass != user.Pass {
|
|
|
|
|
a.Code = values.CodeAccountPass
|
|
|
|
|
a.Msg = "Incorrect password."
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
onLogin(user, a, false)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func PhoneResetPass(c *gin.Context) {
|
|
|
|
|
a := app.NewApp(c)
|
|
|
|
|
defer func() {
|
|
|
|
|
a.Response()
|
|
|
|
|
}()
|
|
|
|
|
req := new(values.PhoneResetPassReq)
|
|
|
|
|
if !a.S(req) {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
log.Debug("PhoneResetPassReq %+v", *req)
|
|
|
|
|
if !db.Mysql().Exist(&common.PlayerDBInfo{ChannelID: a.Channel, Mobile: req.Phone}) {
|
|
|
|
|
a.Code = values.CodeParam
|
|
|
|
|
a.Msg = "phone not exist"
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
if !a.VerifyCode(req.Phone, req.Code) {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
if a.Channel == 0 {
|
|
|
|
|
a.Code = values.CodeParam
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
if err := db.Mysql().Update(&common.PlayerDBInfo{ChannelID: a.Channel, Mobile: req.Phone}, map[string]interface{}{"pass": req.NewPass}); err != nil {
|
|
|
|
|
a.Code = values.CodeRetry
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func PhoneCodeLogin(c *gin.Context) {
|
|
|
|
|
a := app.NewApp(c)
|
|
|
|
|
defer func() {
|
|
|
|
|
a.Response()
|
|
|
|
|
}()
|
|
|
|
|
req := new(values.PhoneCodeLoginReq)
|
|
|
|
|
if !a.S(req) {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
log.Debug("phoneCode login %+v", *req)
|
|
|
|
|
if !a.VerifyCode(req.Phone, req.Code) {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
if a.Channel == 0 {
|
|
|
|
|
a.Code = values.CodeParam
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
openID := common.GetAccountPre(common.AccountTypePhone) + req.Phone
|
|
|
|
|
user, isNew := a.QueryUser(values.CommonLogin{AccountType: common.AccountTypePhone, OpenID: openID, DeviceID: a.UUID,
|
|
|
|
|
Adid: req.Adid, Gpsadid: req.GPSAdid, Phone: req.Phone, Share: req.Share,
|
|
|
|
|
Fbc: a.Context.GetHeader("fbc"), Fbp: a.Context.GetHeader("fbp"), UserAgent: a.Context.GetHeader("User-Agent")})
|
|
|
|
|
if a.Code != values.CodeOK {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
onLogin(user, a, isNew)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func BindingAccount(c *gin.Context) {
|
|
|
|
|
a := app.NewApp(c)
|
|
|
|
|
defer func() {
|
|
|
|
|
a.Response()
|
|
|
|
|
}()
|
|
|
|
|
req := new(values.PhoneCodeLoginReq)
|
|
|
|
|
if !a.S(req) {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
log.Debug("BindingAccount %+v", *req)
|
|
|
|
|
if !a.VerifyCode(req.Phone, req.Code) {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
cid := a.Channel
|
|
|
|
|
if cid == 0 {
|
|
|
|
|
a.Code = values.CodeParam
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
p := &common.PlayerDBInfo{Mobile: req.Phone}
|
|
|
|
|
db.Mysql().Get(p)
|
|
|
|
|
if p.Id > 0 {
|
|
|
|
|
a.Code = values.CodePhoneAlreadyBind
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
ret, _ := call.GetUserXInfo(a.UID, "mobile")
|
|
|
|
|
if ret.Mobile != "" {
|
|
|
|
|
a.Code = values.CodeAccountAlreadyBind
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
if err := call.UpdateUserXInfo(&common.PlayerDBInfo{Id: a.UID}, map[string]interface{}{"mobile": req.Phone}); err != nil {
|
|
|
|
|
log.Error("err:%v", err)
|
|
|
|
|
a.Code = values.CodeRetry
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
reward := call.GetConfigPlatform().BindPhoneGift
|
|
|
|
|
if reward > 0 {
|
|
|
|
|
call.UpdateCurrencyPro(&common.UpdateCurrency{
|
|
|
|
|
CurrencyBalance: &common.CurrencyBalance{
|
|
|
|
|
UID: a.UID,
|
|
|
|
|
Event: common.CurrencyEventBindPhone,
|
|
|
|
|
Type: common.CurrencyINR,
|
|
|
|
|
Value: reward,
|
|
|
|
|
NeedBet: call.GetConfigCurrencyResourceNeedBet(common.CurrencyResourceBonus, reward),
|
|
|
|
|
},
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func GPLogin(c *gin.Context) {
|
|
|
|
|
a := app.NewApp(c)
|
|
|
|
|
defer func() {
|
|
|
|
|
a.Response()
|
|
|
|
|
}()
|
|
|
|
|
req := new(values.GPLoginReq)
|
|
|
|
|
if !a.S(req) {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
openID := config.GetBase().Google.Prefix + req.ID
|
|
|
|
|
user, isNew := a.QueryUser(values.CommonLogin{AccountType: common.AccountTypeGoogleplay, OpenID: openID, DeviceID: a.UUID,
|
|
|
|
|
Nick: req.Name, Avatar: req.Avatar, Adid: req.Adid, Gpsadid: req.GPSAdid, Share: req.Share,
|
|
|
|
|
Fbc: a.Context.GetHeader("fbc"), Fbp: a.Context.GetHeader("fbp"), UserAgent: a.Context.GetHeader("User-Agent")})
|
|
|
|
|
if a.Code != values.CodeOK {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
onLogin(user, a, isNew)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func FBLogin(c *gin.Context) {
|
|
|
|
|
a := app.NewApp(c)
|
|
|
|
|
defer func() {
|
|
|
|
|
a.Response()
|
|
|
|
|
}()
|
|
|
|
|
req := new(values.FBLoginReq)
|
|
|
|
|
if !a.S(req) {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
openID := config.GetBase().FaceBook.Prefix + req.ID
|
|
|
|
|
user, isNew := a.QueryUser(values.CommonLogin{AccountType: common.AccountTypeFacebook, OpenID: openID, DeviceID: a.UUID,
|
|
|
|
|
Nick: req.Name, Avatar: req.Avatar, Adid: req.Adid, Gpsadid: req.GPSAdid, Share: req.Share,
|
|
|
|
|
Fbc: a.Context.GetHeader("fbc"), Fbp: a.Context.GetHeader("fbp"), UserAgent: a.Context.GetHeader("User-Agent")})
|
|
|
|
|
if a.Code != values.CodeOK {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
onLogin(user, a, isNew)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TokenLogin(c *gin.Context) {
|
|
|
|
|
a := app.NewApp(c)
|
|
|
|
|
defer func() {
|
|
|
|
|
a.Response()
|
|
|
|
|
}()
|
|
|
|
|
req := new(values.TokenLoginReq)
|
|
|
|
|
if !a.S(req) {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
uid, _ := db.Redis().GetInt(common.GetRedisKeyToken(req.Token))
|
|
|
|
|
if uid == 0 {
|
|
|
|
|
a.Code = values.CodeToken
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
user := new(common.PlayerDBInfo)
|
|
|
|
|
user.Id = uid
|
|
|
|
|
if err := db.Mysql().Get(user); err != nil {
|
|
|
|
|
log.Error("err:%v", err)
|
|
|
|
|
a.Code = values.CodeRetry
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
user.ADID = req.Adid
|
|
|
|
|
user.GPSADID = req.GPSAdid
|
|
|
|
|
onLogin(user, a, false)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func GetEmailCode(c *gin.Context) {
|
|
|
|
|
a := app.NewApp(c)
|
|
|
|
|
defer func() {
|
|
|
|
|
if a.Code == values.CodeReqBusy {
|
|
|
|
|
a.Msg = "Too many requests,please try later."
|
|
|
|
|
} else if a.Code != values.CodeOK {
|
|
|
|
|
a.Msg = "Email code error"
|
|
|
|
|
}
|
|
|
|
|
a.Response()
|
|
|
|
|
}()
|
|
|
|
|
req := new(values.EmailCodeReq)
|
|
|
|
|
if !a.S(req) {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
cid := a.Channel
|
|
|
|
|
if cid == 0 {
|
|
|
|
|
a.Code = values.CodeParam
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
if call.IsBlackListPlayer(&common.BlackList{Email: req.Email}) {
|
|
|
|
|
a.Code = values.CodeRetry
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
log.Debug("GetEmailCode:%+v", *req)
|
|
|
|
|
code := values.RandomPhoneCode()
|
|
|
|
|
if !db.Redis().SetNX(common.GetRedisKeyCodeCD(req.Email), code, common.RedisExpireCodeCD) {
|
|
|
|
|
a.Code = values.CodePhoneCodeBusy
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
if err := db.Redis().SetData(common.GetRedisKeyCode(req.Email), code, common.RedisExpireCode); err != nil {
|
|
|
|
|
log.Error("err:%v", err)
|
|
|
|
|
a.Code = values.CodeRetry
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
if !config.GetBase().Release {
|
|
|
|
|
a.Data = code
|
|
|
|
|
} else {
|
|
|
|
|
values.BukaMailRequest(req.Email, code, a.Lang)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func EmailRegist(c *gin.Context) {
|
|
|
|
|
a := app.NewApp(c)
|
|
|
|
|
defer func() {
|
|
|
|
|
a.Response()
|
|
|
|
|
}()
|
|
|
|
|
req := new(values.EmailRegistReq)
|
|
|
|
|
if !a.S(req) {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
log.Debug("emailCode regist %+v", *req)
|
|
|
|
|
if !a.VerifyCode(req.Email, req.Code) {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
if a.Channel == 0 {
|
|
|
|
|
a.Code = values.CodeParam
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
openID := common.GetAccountPre(common.AccountTypeEmail) + req.Email
|
|
|
|
|
// if db.Mysql().Exist(&common.PlayerDBInfo{Openid: &openID}) {
|
|
|
|
|
// a.Code = values.CodeAccountAlreadyExist
|
|
|
|
|
// a.Msg = "email registered"
|
|
|
|
|
// return
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
user, isNew := a.QueryUser(values.CommonLogin{AccountType: common.AccountTypeEmail, OpenID: openID, DeviceID: a.UUID,
|
|
|
|
|
Adid: req.Adid, Gpsadid: req.GPSAdid, AccountName: req.Email, Pass: req.Pass, Share: req.Share,
|
|
|
|
|
Fbc: a.Context.GetHeader("fbc"), Fbp: a.Context.GetHeader("fbp"), UserAgent: a.Context.GetHeader("User-Agent")})
|
|
|
|
|
if a.Code != values.CodeOK {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if !isNew {
|
|
|
|
|
a.Code = values.CodeAccountAlreadyExist
|
|
|
|
|
a.Msg = "email registered"
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
onLogin(user, a, isNew)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func EmailLogin(c *gin.Context) {
|
|
|
|
|
a := app.NewApp(c)
|
|
|
|
|
defer func() {
|
|
|
|
|
a.Response()
|
|
|
|
|
}()
|
|
|
|
|
req := new(values.EmailLoginReq)
|
|
|
|
|
if !a.S(req) {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
log.Debug("emailCode login %+v", *req)
|
|
|
|
|
if a.Channel == 0 {
|
|
|
|
|
a.Code = values.CodeParam
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
user := &common.PlayerDBInfo{ChannelID: a.Channel, AccountName: req.Email}
|
|
|
|
|
db.Mysql().Get(user)
|
|
|
|
|
if user.Id == 0 {
|
|
|
|
|
a.Code = values.CodeAccountNotExist
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
if req.Pass != user.Pass {
|
|
|
|
|
a.Code = values.CodeAccountPass
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
onLogin(user, a, false)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func EmailResetPass(c *gin.Context) {
|
|
|
|
|
a := app.NewApp(c)
|
|
|
|
|
defer func() {
|
|
|
|
|
a.Response()
|
|
|
|
|
}()
|
|
|
|
|
req := new(values.EmailResetPassReq)
|
|
|
|
|
if !a.S(req) {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
log.Debug("EmailResetPass %+v", *req)
|
|
|
|
|
if !db.Mysql().Exist(&common.PlayerDBInfo{ChannelID: a.Channel, AccountName: req.Email}) {
|
|
|
|
|
a.Code = values.CodeParam
|
|
|
|
|
a.Msg = "Email not exist."
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
if !a.VerifyCode(req.Email, req.Code) {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
if a.Channel == 0 {
|
|
|
|
|
a.Code = values.CodeParam
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
if err := db.Mysql().Update(&common.PlayerDBInfo{ChannelID: a.Channel, AccountName: req.Email}, map[string]interface{}{"pass": req.NewPass}); err != nil {
|
|
|
|
|
a.Code = values.CodeRetry
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func AccountRegist(c *gin.Context) {
|
|
|
|
|
a := app.NewApp(c)
|
|
|
|
|
defer func() {
|
|
|
|
|
a.Response()
|
|
|
|
|
}()
|
|
|
|
|
req := new(values.AccountRegistReq)
|
|
|
|
|
if !a.S(req) {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
log.Debug("AccountRegistReq %+v", *req)
|
|
|
|
|
if a.Channel == 0 {
|
|
|
|
|
a.Code = values.CodeParam
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
openID := common.GetAccountPre(common.AccountTypeAccount) + req.Name
|
|
|
|
|
// if db.Mysql().Exist(&common.PlayerDBInfo{Openid: &openID}) {
|
|
|
|
|
// a.Code = values.CodeAccountAlreadyExist
|
|
|
|
|
// a.Msg = "email registered"
|
|
|
|
|
// return
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
user, isNew := a.QueryUser(values.CommonLogin{AccountType: common.AccountTypeAccount, OpenID: openID, DeviceID: a.UUID,
|
|
|
|
|
AccountName: req.Name, Pass: req.Pass, Share: req.Share,
|
|
|
|
|
Fbc: a.Context.GetHeader("fbc"), Fbp: a.Context.GetHeader("fbp"), UserAgent: a.Context.GetHeader("User-Agent")})
|
|
|
|
|
if a.Code != values.CodeOK {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if !isNew {
|
|
|
|
|
a.Code = values.CodeAccountAlreadyExist
|
|
|
|
|
a.Msg = "Account registered."
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
onLogin(user, a, isNew)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func AccountLogin(c *gin.Context) {
|
|
|
|
|
a := app.NewApp(c)
|
|
|
|
|
defer func() {
|
|
|
|
|
a.Response()
|
|
|
|
|
}()
|
|
|
|
|
req := new(values.AccountLoginReq)
|
|
|
|
|
if !a.S(req) {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
log.Debug("AccountLogin %+v", *req)
|
|
|
|
|
if a.Channel == 0 {
|
|
|
|
|
a.Code = values.CodeParam
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
user := &common.PlayerDBInfo{ChannelID: a.Channel, AccountName: req.Name}
|
|
|
|
|
db.Mysql().Get(user)
|
|
|
|
|
if user.Id == 0 {
|
|
|
|
|
a.Code = values.CodeAccountNotExist
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
if req.Pass != user.Pass {
|
|
|
|
|
a.Code = values.CodeAccountPass
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
onLogin(user, a, false)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func AccountResetPass(c *gin.Context) {
|
|
|
|
|
a := app.NewApp(c)
|
|
|
|
|
defer func() {
|
|
|
|
|
a.Response()
|
|
|
|
|
}()
|
|
|
|
|
req := new(values.AccountResetPassReq)
|
|
|
|
|
if !a.S(req) {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
log.Debug("EmailResetPass %+v", *req)
|
|
|
|
|
p := &common.PlayerDBInfo{ChannelID: a.Channel, AccountName: req.Name}
|
|
|
|
|
db.Mysql().Get(p)
|
|
|
|
|
if p.Id == 0 {
|
|
|
|
|
a.Code = values.CodeParam
|
|
|
|
|
a.Msg = "Account not exist."
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
if p.Pass != req.OldPass {
|
|
|
|
|
a.Code = values.CodeParam
|
|
|
|
|
a.Msg = "Password invalid."
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
if a.Channel == 0 {
|
|
|
|
|
a.Code = values.CodeParam
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
if err := db.Mysql().Update(&common.PlayerDBInfo{ChannelID: a.Channel, AccountName: req.Name}, map[string]interface{}{"pass": req.NewPass}); err != nil {
|
|
|
|
|
a.Code = values.CodeRetry
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
}
|