登录相关处理

This commit is contained in:
2024-04-09 18:17:08 +08:00
parent 578d7ecdf9
commit 74b790b542
17 changed files with 544 additions and 24 deletions

View File

@@ -1,12 +1,16 @@
package actions
import (
"log"
"github.com/gin-gonic/gin"
"github.com/iapologizewhenimwrong/Vestmore_GO/utils/auth"
"github.com/iapologizewhenimwrong/Vestmore_GO/utils/basic"
"github.com/iapologizewhenimwrong/Vestmore_GO/utils/email"
"github.com/iapologizewhenimwrong/Vestmore_GO/utils/encryption_decryption"
"github.com/iapologizewhenimwrong/Vestmore_GO/utils/log"
)
var CompanyKey = "vestmore-bjwl"
// @Action base/getToken
// Base_GetToken
// action: string;
@@ -58,6 +62,12 @@ func AccountForgetSmsCode(ctx *gin.Context, param *AccountForgetSmsCodeParam, re
log.Println()
}
type RegisterValidEmailCode struct {
Code string
Email string
AppMarket int
}
// @Action account/registerEmailCode
// AccountRegisterEmailCode
// randstr: string;
@@ -68,7 +78,30 @@ func AccountForgetSmsCode(ctx *gin.Context, param *AccountForgetSmsCodeParam, re
// timestamp: int64;
// token: string;
func AccountRegisterEmailCode(ctx *gin.Context, param *AccountRegisterEmailCodeParam, resp *basic.Response) {
log.Println(param)
if !email.IsEmailValid(param.Email) {
resp.Error(basic.ErrEmailFormat)
return
}
gcm := encryption_decryption.NewSecretGCM[RegisterValidEmailCode](CompanyKey)
code := auth.GenerateVerificationCode()
codetoken := &RegisterValidEmailCode{
Code: code,
Email: param.Email,
AppMarket: param.AppMarket,
}
tokenstr, err := gcm.Encrypt(codetoken)
if err != nil {
resp.Error(basic.ErrEncGcm)
return
}
resp.Success(map[string]any{
"token": tokenstr,
})
}
// @Action member/alterPassword

View File

@@ -1,28 +1,27 @@
package actions
import (
"log"
"github.com/gin-gonic/gin"
"github.com/iapologizewhenimwrong/Vestmore_GO/utils/basic"
"github.com/iapologizewhenimwrong/Vestmore_GO/utils/log"
)
var HandlersFuncRoutes map[string]gin.HandlerFunc = make(map[string]gin.HandlerFunc)
func init() {
// func AccountForgetSmsCode(ctx gin.Context, param AccountForgetSmsCodeParam, resp *basic.Response)
// func AccountForgetSmsCode(ctx *gin.Context, param *AccountForgetSmsCodeParam, resp *basic.Response)
HandlersFuncRoutes["account/forgetSmsCode"] = AccountForgetSmsCodeHandler
// func AccountLoginWithEmailPassword(ctx gin.Context, param AccountLoginWithEmailPasswordParam, resp *basic.Response)
// func AccountLoginWithEmailPassword(ctx *gin.Context, param *AccountLoginWithEmailPasswordParam, resp *basic.Response)
HandlersFuncRoutes["account/loginWithEmailPassword"] = AccountLoginWithEmailPasswordHandler
// func AccountLoginWithTelephonePassword(ctx gin.Context, param AccountLoginWithTelephonePasswordParam, resp *basic.Response)
// func AccountLoginWithTelephonePassword(ctx *gin.Context, param *AccountLoginWithTelephonePasswordParam, resp *basic.Response)
HandlersFuncRoutes["account/loginWithTelephonePassword"] = AccountLoginWithTelephonePasswordHandler
// func AccountRegisterEmailCode(ctx gin.Context, param AccountRegisterEmailCodeParam, resp *basic.Response)
// func AccountRegisterEmailCode(ctx *gin.Context, param *AccountRegisterEmailCodeParam, resp *basic.Response)
HandlersFuncRoutes["account/registerEmailCode"] = AccountRegisterEmailCodeHandler
// func AccountRegisterSmsCode(ctx gin.Context, param AccountRegisterSmsCodeParam, resp *basic.Response)
// func AccountRegisterSmsCode(ctx *gin.Context, param *AccountRegisterSmsCodeParam, resp *basic.Response)
HandlersFuncRoutes["account/registerSmsCode"] = AccountRegisterSmsCodeHandler
// func BaseGetToken(ctx gin.Context, param BaseGetTokenParam, resp *basic.Response)
// func BaseGetToken(ctx *gin.Context, param *BaseGetTokenParam, resp *basic.Response)
HandlersFuncRoutes["base/getToken"] = BaseGetTokenHandler
// func MemberAlterPassword(ctx gin.Context, param MemberAlterPasswordParam, resp *basic.Response)
// func MemberAlterPassword(ctx *gin.Context, param *MemberAlterPasswordParam, resp *basic.Response)
HandlersFuncRoutes["member/alterPassword"] = MemberAlterPasswordHandler
}
@@ -34,7 +33,7 @@ type AccountForgetSmsCodeParam struct {
}
func AccountForgetSmsCodeHandler(ctx *gin.Context) {
resp := &basic.Response{}
resp := &basic.Response{IsSuccess: true}
defer ctx.JSON(200, resp)
param := &AccountForgetSmsCodeParam{}
@@ -62,7 +61,7 @@ type AccountLoginWithEmailPasswordParam struct {
}
func AccountLoginWithEmailPasswordHandler(ctx *gin.Context) {
resp := &basic.Response{}
resp := &basic.Response{IsSuccess: true}
defer ctx.JSON(200, resp)
param := &AccountLoginWithEmailPasswordParam{}
@@ -88,7 +87,7 @@ type AccountLoginWithTelephonePasswordParam struct {
}
func AccountLoginWithTelephonePasswordHandler(ctx *gin.Context) {
resp := &basic.Response{}
resp := &basic.Response{IsSuccess: true}
defer ctx.JSON(200, resp)
param := &AccountLoginWithTelephonePasswordParam{}
@@ -113,7 +112,7 @@ type AccountRegisterEmailCodeParam struct {
}
func AccountRegisterEmailCodeHandler(ctx *gin.Context) {
resp := &basic.Response{}
resp := &basic.Response{IsSuccess: true}
defer ctx.JSON(200, resp)
param := &AccountRegisterEmailCodeParam{}
@@ -135,7 +134,7 @@ type AccountRegisterSmsCodeParam struct {
}
func AccountRegisterSmsCodeHandler(ctx *gin.Context) {
resp := &basic.Response{}
resp := &basic.Response{IsSuccess: true}
defer ctx.JSON(200, resp)
param := &AccountRegisterSmsCodeParam{}
@@ -157,7 +156,7 @@ type BaseGetTokenParam struct {
}
func BaseGetTokenHandler(ctx *gin.Context) {
resp := &basic.Response{}
resp := &basic.Response{IsSuccess: true}
defer ctx.JSON(200, resp)
param := &BaseGetTokenParam{}
@@ -180,7 +179,7 @@ type MemberAlterPasswordParam struct {
}
func MemberAlterPasswordHandler(ctx *gin.Context) {
resp := &basic.Response{}
resp := &basic.Response{IsSuccess: true}
defer ctx.JSON(200, resp)
param := &MemberAlterPasswordParam{}

View File

@@ -1,2 +0,0 @@
package handlers

View File

@@ -3,6 +3,7 @@ package actions
import (
"github.com/gin-gonic/gin"
"github.com/iapologizewhenimwrong/Vestmore_GO/utils/basic"
"github.com/iapologizewhenimwrong/Vestmore_GO/utils/log"
)
var HandlersFuncRoutes map[string]gin.HandlerFunc = make(map[string]gin.HandlerFunc)
@@ -22,7 +23,7 @@ type {{.ParamStruct.ParamStructName}} struct {
}
func {{.FuncName}}Handler(ctx *gin.Context) {
resp := &basic.Response{}
resp := &basic.Response{IsSuccess: true}
defer ctx.JSON(200, resp)
param := &{{.ParamStruct.ParamStructName}}{}