You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
259 lines
8.3 KiB
259 lines
8.3 KiB
2 months ago
|
package processor
|
||
|
|
||
|
import (
|
||
|
"github.com/gin-gonic/gin"
|
||
|
"net/http"
|
||
|
"strconv"
|
||
|
"wss-pool/internal"
|
||
|
"wss-pool/internal/data/mysqlbusiness"
|
||
|
"wss-pool/logging/applogger"
|
||
|
"wss-pool/pkg/model"
|
||
|
"wss-pool/pkg/msg"
|
||
|
)
|
||
|
|
||
|
/*
|
||
|
MsgSend
|
||
|
1、Users can only submit once within 1 minute
|
||
|
2、The verification code will not expire within five minutes
|
||
|
*/
|
||
|
func MsgSend(c *gin.Context) {
|
||
|
var tmp model.LoginPost
|
||
|
if err := c.BindJSON(&tmp); err != nil {
|
||
|
c.JSON(http.StatusOK, internal.GinResult(http.StatusBadRequest, internal.ResultStr, internal.ParameterError))
|
||
|
return
|
||
|
}
|
||
|
phoneNumber := tmp.PhoneNumber
|
||
|
if len(phoneNumber) <= 0 {
|
||
|
c.JSON(http.StatusOK, internal.GinResult(http.StatusBadRequest, internal.ResultStr, internal.PhoneError))
|
||
|
return
|
||
|
}
|
||
|
|
||
|
msgCode, err := msg.RunSendSms(phoneNumber)
|
||
|
if err != nil {
|
||
|
applogger.Error("msg RunSendSms info err: %v", err)
|
||
|
c.JSON(http.StatusOK, internal.GinResult(http.StatusBadRequest, err.Error(), internal.QueryError))
|
||
|
return
|
||
|
}
|
||
|
|
||
|
c.JSON(http.StatusOK, internal.GinResult(http.StatusOK, msgCode, internal.QuerySuccess))
|
||
|
}
|
||
|
|
||
|
// MobileLogin 用户手机号登录
|
||
|
func MobileLogin(c *gin.Context) {
|
||
|
var tmp model.LoginPost
|
||
|
if err := c.BindJSON(&tmp); err != nil {
|
||
|
c.JSON(http.StatusOK, internal.GinResult(http.StatusBadRequest, internal.ResultStr, internal.ParameterError))
|
||
|
return
|
||
|
}
|
||
|
phoneNumber := tmp.PhoneNumber
|
||
|
password := tmp.Password
|
||
|
|
||
|
if len(phoneNumber) <= 0 {
|
||
|
c.JSON(http.StatusOK, internal.GinResult(http.StatusBadRequest, internal.ResultStr, internal.PhoneError))
|
||
|
return
|
||
|
}
|
||
|
if len(password) <= 0 {
|
||
|
c.JSON(http.StatusOK, internal.GinResult(http.StatusBadRequest, internal.ResultStr, internal.PassWordError))
|
||
|
return
|
||
|
}
|
||
|
|
||
|
check, err := mysqlbusiness.GetBoUsersByPhoneAndPassWord(phoneNumber, password)
|
||
|
if err != nil {
|
||
|
c.JSON(http.StatusOK, internal.GinResult(http.StatusBadRequest, internal.ResultStr, check))
|
||
|
return
|
||
|
}
|
||
|
|
||
|
c.JSON(http.StatusOK, internal.GinResult(http.StatusOK, check, internal.TokenError))
|
||
|
}
|
||
|
|
||
|
// ForgetPassWord 手机验证码修改密码
|
||
|
func PhoneNumberByPassWord(c *gin.Context) {
|
||
|
var tmp model.LoginPost
|
||
|
if err := c.BindJSON(&tmp); err != nil {
|
||
|
c.JSON(http.StatusOK, internal.GinResult(http.StatusBadRequest, internal.ResultStr, internal.ParameterError))
|
||
|
return
|
||
|
}
|
||
|
check := tmp.Check
|
||
|
phoneNumber := tmp.PhoneNumber
|
||
|
//code := tmp.Code
|
||
|
password := tmp.Password
|
||
|
|
||
|
if len(check) == 0 {
|
||
|
c.JSON(http.StatusOK, internal.GinResult(http.StatusBadRequest, internal.ResultStr, internal.ParameterError))
|
||
|
return
|
||
|
}
|
||
|
if len(phoneNumber) <= 0 {
|
||
|
c.JSON(http.StatusOK, internal.GinResult(http.StatusBadRequest, internal.ResultStr, internal.PhoneError))
|
||
|
return
|
||
|
}
|
||
|
if len(password) <= 0 {
|
||
|
c.JSON(http.StatusOK, internal.GinResult(http.StatusBadRequest, internal.ResultStr, internal.PassWordError))
|
||
|
return
|
||
|
}
|
||
|
|
||
|
//if len(code) <= 0 {
|
||
|
// c.JSON(http.StatusOK, internal.GinResult(http.StatusBadRequest, internal.ResultStr, internal.CodeError))
|
||
|
// return
|
||
|
//}
|
||
|
//codeData, err := redis.Get_Cache_Data(phoneNumber)
|
||
|
//if err != nil {
|
||
|
// c.JSON(http.StatusOK, internal.GinResult(http.StatusBadRequest, internal.ResultStr, internal.CodeError))
|
||
|
// return
|
||
|
//}
|
||
|
//if codeData != code {
|
||
|
// c.JSON(http.StatusOK, internal.GinResult(http.StatusBadRequest, internal.ResultStr, internal.CodeError))
|
||
|
// return
|
||
|
//}
|
||
|
|
||
|
dataMsg, err := mysqlbusiness.UpdateBoUsersById(phoneNumber, password)
|
||
|
if err != nil {
|
||
|
c.JSON(http.StatusOK, internal.GinResult(http.StatusBadRequest, internal.ResultStr, dataMsg))
|
||
|
return
|
||
|
}
|
||
|
|
||
|
c.JSON(http.StatusOK, internal.GinResult(http.StatusOK, internal.ResultStr, dataMsg))
|
||
|
}
|
||
|
|
||
|
// Registration 手机号注册|验证码|密码|邀请码
|
||
|
func Registration(c *gin.Context) {
|
||
|
var tmp model.LoginPost
|
||
|
if err := c.BindJSON(&tmp); err != nil {
|
||
|
c.JSON(http.StatusOK, internal.GinResult(http.StatusBadRequest, internal.ResultStr, internal.ParameterError))
|
||
|
return
|
||
|
}
|
||
|
|
||
|
phoneNumber := tmp.PhoneNumber
|
||
|
//code := tmp.Code
|
||
|
password := tmp.Password
|
||
|
invitationCode := tmp.InvitationCode
|
||
|
|
||
|
if len(phoneNumber) <= 0 {
|
||
|
c.JSON(http.StatusOK, internal.GinResult(http.StatusBadRequest, internal.ResultStr, internal.PhoneError))
|
||
|
return
|
||
|
}
|
||
|
if len(password) <= 0 {
|
||
|
c.JSON(http.StatusOK, internal.GinResult(http.StatusBadRequest, internal.ResultStr, internal.PassWordError))
|
||
|
return
|
||
|
}
|
||
|
//if len(code) <= 0 {
|
||
|
// c.JSON(http.StatusOK, internal.GinResult(http.StatusBadRequest, internal.ResultStr, internal.CodeError))
|
||
|
// return
|
||
|
//}
|
||
|
|
||
|
//codeData, err := redis.Get_Cache_Data(phoneNumber)
|
||
|
//if err != nil {
|
||
|
// c.JSON(http.StatusOK, internal.GinResult(http.StatusBadRequest, internal.ResultStr,internal.CodeError))
|
||
|
// return
|
||
|
//}
|
||
|
|
||
|
//if codeData != code {
|
||
|
// c.JSON(http.StatusOK, internal.GinResult(http.StatusBadRequest, internal.ResultStr, internal.CodeError))
|
||
|
// return
|
||
|
//}
|
||
|
|
||
|
// Check if the user exists
|
||
|
user, err := mysqlbusiness.GetBoUsersByPhoneNumber(phoneNumber)
|
||
|
if err != nil || len(user) > 0 {
|
||
|
c.JSON(http.StatusOK, internal.GinResult(http.StatusBadRequest, internal.ResultStr, user))
|
||
|
return
|
||
|
}
|
||
|
|
||
|
dataMsg, err := mysqlbusiness.SaveBoUsers(phoneNumber, password, invitationCode)
|
||
|
if err != nil {
|
||
|
c.JSON(http.StatusOK, internal.GinResult(http.StatusBadRequest, internal.ResultStr, dataMsg))
|
||
|
return
|
||
|
}
|
||
|
|
||
|
//TODO: 注册创建用户账号、创建数字币账号、写入设备、注册写用户信息缓存、写入缓存
|
||
|
|
||
|
c.JSON(http.StatusOK, internal.GinResult(http.StatusOK, internal.ResultStr, dataMsg))
|
||
|
}
|
||
|
|
||
|
// ForgetPassWore 忘记密码-通过手机重新设置密码
|
||
|
func ForgetPassWore(c *gin.Context) {
|
||
|
var tmp model.LoginPost
|
||
|
if err := c.BindJSON(&tmp); err != nil {
|
||
|
c.JSON(http.StatusOK, internal.GinResult(http.StatusBadRequest, internal.ResultStr, internal.ParameterError))
|
||
|
return
|
||
|
}
|
||
|
phoneNumber := tmp.PhoneNumber
|
||
|
//code := tmp.Code
|
||
|
password := tmp.Password
|
||
|
|
||
|
if len(phoneNumber) <= 0 {
|
||
|
c.JSON(http.StatusOK, internal.GinResult(http.StatusBadRequest, internal.ResultStr, internal.PhoneError))
|
||
|
return
|
||
|
}
|
||
|
if len(password) <= 0 {
|
||
|
c.JSON(http.StatusOK, internal.GinResult(http.StatusBadRequest, internal.ResultStr, internal.PassWordError))
|
||
|
return
|
||
|
}
|
||
|
//if len(code) <= 0 {
|
||
|
// c.JSON(http.StatusOK, internal.GinResult(http.StatusBadRequest, internal.ResultStr, internal.CodeError))
|
||
|
// return
|
||
|
//}
|
||
|
|
||
|
//codeData, err := redis.Get_Cache_Data(phoneNumber)
|
||
|
//if err != nil {
|
||
|
// c.JSON(http.StatusOK, internal.GinResult(http.StatusBadRequest, internal.ResultStr, "internal.CodeError))
|
||
|
// return
|
||
|
//}
|
||
|
|
||
|
//if codeData != code {
|
||
|
// c.JSON(http.StatusOK, internal.GinResult(http.StatusBadRequest, internal.ResultStr, internal.CodeError))
|
||
|
// return
|
||
|
//}
|
||
|
|
||
|
dataMsg, err := mysqlbusiness.UpdateBoUsersPassWordByPhoneNumber(phoneNumber, password)
|
||
|
if err != nil {
|
||
|
c.JSON(http.StatusOK, internal.GinResult(http.StatusBadRequest, internal.ResultStr, dataMsg))
|
||
|
return
|
||
|
}
|
||
|
|
||
|
c.JSON(http.StatusOK, internal.GinResult(http.StatusOK, internal.ResultStr, dataMsg))
|
||
|
}
|
||
|
|
||
|
// SetPhoneNumber 设置手机号
|
||
|
func SetPhoneNumber(c *gin.Context) {
|
||
|
var tmp model.LoginPost
|
||
|
if err := c.BindJSON(&tmp); err != nil {
|
||
|
c.JSON(http.StatusOK, internal.GinResult(http.StatusBadRequest, internal.ResultStr, internal.ParameterError))
|
||
|
return
|
||
|
}
|
||
|
//code :=tmp.Code
|
||
|
phoneNumber := tmp.PhoneNumber
|
||
|
id, err := strconv.Atoi(tmp.Id)
|
||
|
if err != nil {
|
||
|
c.JSON(http.StatusOK, internal.GinResult(http.StatusBadRequest, internal.ResultStr, internal.ParameterError))
|
||
|
return
|
||
|
}
|
||
|
if len(phoneNumber) <= 0 {
|
||
|
c.JSON(http.StatusOK, internal.GinResult(http.StatusBadRequest, internal.ResultStr, internal.PhoneError))
|
||
|
return
|
||
|
}
|
||
|
if id <= 0 {
|
||
|
c.JSON(http.StatusOK, internal.GinResult(http.StatusBadRequest, internal.ResultStr, internal.UserIdError))
|
||
|
return
|
||
|
}
|
||
|
//if len(code) <= 0 {
|
||
|
// c.JSON(http.StatusOK, internal.GinResult(http.StatusBadRequest, internal.ResultStr, internal.CodeError))
|
||
|
// return
|
||
|
//}
|
||
|
//codeData, err := redis.Get_Cache_Data(phoneNumber)
|
||
|
//if err != nil {
|
||
|
// c.JSON(http.StatusOK, internal.GinResult(http.StatusBadRequest, internal.ResultStr, internal.CodeError))
|
||
|
// return
|
||
|
//}
|
||
|
//if codeData != code {
|
||
|
// c.JSON(http.StatusOK, internal.GinResult(http.StatusBadRequest, internal.ResultStr, internal.CodeError))
|
||
|
// return
|
||
|
//}
|
||
|
|
||
|
dateMsg, err := mysqlbusiness.UpdateBoUsersPhoneNumberById(phoneNumber, int64(id))
|
||
|
if err != nil {
|
||
|
c.JSON(http.StatusOK, internal.GinResult(http.StatusBadRequest, internal.ResultStr, dateMsg))
|
||
|
return
|
||
|
}
|
||
|
c.JSON(http.StatusOK, internal.GinResult(http.StatusOK, internal.ResultStr, dateMsg))
|
||
|
}
|