add:注册登录
This commit is contained in:
parent
4a9fd1f687
commit
1bf34de4a7
@ -32,8 +32,6 @@ golang-build:
|
||||
|
||||
docker-package:
|
||||
stage: package
|
||||
services:
|
||||
- name: docker:23.0.1-dind
|
||||
script:
|
||||
- |
|
||||
docker info
|
||||
|
60
apps/user.go
60
apps/user.go
@ -12,21 +12,71 @@ import (
|
||||
)
|
||||
|
||||
func InitUserGroup(g *echo.Group) {
|
||||
g.POST("ai/login", func(c echo.Context) error {
|
||||
req := new(dto.ThirdLoginReq)
|
||||
|
||||
//注册
|
||||
g.POST("user/register", func(c echo.Context) error {
|
||||
req := new(dto.ThirdRegisterReq)
|
||||
if err := c.Bind(req); err != nil {
|
||||
return c.JSON(500, err)
|
||||
return c.JSON(http.StatusOK, utils.Error(err))
|
||||
}
|
||||
|
||||
ctx := context.WithValue(context.Background(), constant.DBKey, repository.Db)
|
||||
|
||||
err := service.Login.Register(ctx, *req)
|
||||
if err != nil {
|
||||
return c.JSON(http.StatusOK, utils.Error(err))
|
||||
}
|
||||
|
||||
return c.JSON(http.StatusOK, utils.Ok(true))
|
||||
})
|
||||
|
||||
//登录
|
||||
g.POST("user/login", func(c echo.Context) error {
|
||||
req := new(dto.ThirdLoginReq)
|
||||
if err := c.Bind(req); err != nil {
|
||||
return c.JSON(http.StatusOK, utils.Error(err))
|
||||
}
|
||||
|
||||
req.BizId = constant.BizIdAI.Val()
|
||||
ctx := context.WithValue(context.Background(), constant.DBKey, repository.Db)
|
||||
|
||||
token, err := service.Login.Login(ctx, *req)
|
||||
if err != nil {
|
||||
return c.JSON(500, err)
|
||||
return c.JSON(http.StatusOK, utils.Error(err))
|
||||
}
|
||||
|
||||
return c.JSON(http.StatusOK, utils.Ok(token))
|
||||
})
|
||||
|
||||
//发送 重置密码 验证码
|
||||
g.POST("user/sendResetPwdCode", func(c echo.Context) error {
|
||||
req := new(dto.SendResetPwdCodeReq)
|
||||
if err := c.Bind(req); err != nil {
|
||||
return c.JSON(http.StatusOK, utils.Error(err))
|
||||
}
|
||||
|
||||
err := service.Login.SendResetPwdCode(context.Background(), req.Account)
|
||||
if err != nil {
|
||||
return c.JSON(http.StatusOK, utils.Error(err))
|
||||
}
|
||||
|
||||
return c.JSON(http.StatusOK, utils.Ok(true))
|
||||
})
|
||||
|
||||
//重置密码
|
||||
g.POST("user/resetPwd", func(c echo.Context) error {
|
||||
req := new(dto.ThirdResetPwdReq)
|
||||
if err := c.Bind(req); err != nil {
|
||||
return c.JSON(http.StatusOK, utils.Error(err))
|
||||
}
|
||||
|
||||
ctx := context.WithValue(context.Background(), constant.DBKey, repository.Db)
|
||||
|
||||
err := service.Login.ResetPwd(ctx, *req)
|
||||
if err != nil {
|
||||
return c.JSON(http.StatusOK, utils.Error(err))
|
||||
}
|
||||
|
||||
return c.JSON(http.StatusOK, utils.Ok(true))
|
||||
})
|
||||
|
||||
}
|
||||
|
@ -6,7 +6,7 @@ fbServer:
|
||||
fbConsul:
|
||||
address: https://consul.mylomen.com
|
||||
datacenter: dg01
|
||||
token: 447b9c88-8983-f525-d118-f83a1383ad86
|
||||
token: 4b29ca6c-3233-4c70-7bb1-a3f4c2a18281
|
||||
|
||||
# rpc
|
||||
rpc:
|
||||
@ -15,11 +15,12 @@ rpc:
|
||||
# mysql
|
||||
mysql:
|
||||
logSql: true
|
||||
dsn: root:zym520!@tcp(43.133.218.116:10119)/user_center?charset=utf8mb4&parseTime=True&loc=Local
|
||||
maxIdleConn: 10
|
||||
maxOpenConn: 10
|
||||
dsn: uc:zELLqwk2hBp8QyJgEtH5YGc6WKMS3dXP@tcp(43.133.218.116:10119)/user_center?charset=utf8mb4&parseTime=True&loc=Local
|
||||
maxIdleConn: 4
|
||||
maxOpenConn: 4
|
||||
connMaxLifetime: 3000
|
||||
|
||||
|
||||
# redis
|
||||
redis:
|
||||
db: 1
|
||||
|
@ -6,7 +6,7 @@ fbServer:
|
||||
fbConsul:
|
||||
address: 10.0.0.5:8500
|
||||
datacenter: dg01
|
||||
token: 447b9c88-8983-f525-d118-f83a1383ad86
|
||||
token: 4b29ca6c-3233-4c70-7bb1-a3f4c2a18281
|
||||
|
||||
# rpc
|
||||
rpc:
|
||||
@ -15,9 +15,9 @@ rpc:
|
||||
# mysql
|
||||
mysql:
|
||||
logSql: false
|
||||
dsn: root:zym520!@tcp(10.0.0.5:10119)/user_center?charset=utf8mb4&parseTime=True&loc=Local
|
||||
dsn: uc:zELLqwk2hBp8QyJgEtH5YGc6WKMS3dXP@tcp(10.0.0.5:10119)/user_center?charset=utf8mb4&parseTime=True&loc=Local
|
||||
maxIdleConn: 4
|
||||
maxOpenConn: 8
|
||||
maxOpenConn: 4
|
||||
connMaxLifetime: 3000
|
||||
|
||||
# redis
|
||||
|
@ -2,4 +2,6 @@ package constant
|
||||
|
||||
const (
|
||||
THIRD_LOGIN_TOKEN = "third:login:token:"
|
||||
|
||||
G_RESET_PWD_CODE = "g:reset:pwd:email:"
|
||||
)
|
||||
|
@ -1,17 +1,34 @@
|
||||
package dto
|
||||
|
||||
type ThirdLoginReq struct {
|
||||
CorpID uint64 `json:"corpId"` // 企业id
|
||||
BizId uint64 `json:"bizId"` // 业务id
|
||||
type ThirdRegisterReq struct {
|
||||
Account string `json:"account"` // 帐号
|
||||
|
||||
Password string `json:"password"` // 密码
|
||||
|
||||
Name string `json:"name"` // 昵称
|
||||
|
||||
Icon string `json:"icon"` // 头像
|
||||
}
|
||||
|
||||
type SendResetPwdCodeReq struct {
|
||||
Account string `json:"account"` // 帐号
|
||||
}
|
||||
|
||||
type ThirdResetPwdReq struct {
|
||||
Account string `json:"account"` // 帐号
|
||||
|
||||
Password string `json:"password"` // 密码
|
||||
|
||||
Code string `json:"code"` // 验证码
|
||||
}
|
||||
|
||||
type ThirdLoginReq struct {
|
||||
Account string `json:"account"` // 帐号
|
||||
|
||||
Password string `json:"password"` // 密码
|
||||
}
|
||||
|
||||
type ThirdUserLoginToken struct {
|
||||
CorpId uint64 `json:"corp_id"`
|
||||
BizId uint64 `json:"biz_id"`
|
||||
Uid uint64 `json:"uid"`
|
||||
AccessToken string `json:"accessToken"`
|
||||
}
|
||||
|
34
common/email/email_tool.go
Normal file
34
common/email/email_tool.go
Normal file
@ -0,0 +1,34 @@
|
||||
package email
|
||||
|
||||
import (
|
||||
"ai-gateway/common/logs"
|
||||
"gopkg.in/gomail.v2"
|
||||
)
|
||||
|
||||
func sendNoticeEmail(subject, content string, address ...string) error {
|
||||
gm := gomail.NewMessage()
|
||||
gm.SetHeader("From", "<support@notice.mylomen.com>")
|
||||
if len(address) == 1 {
|
||||
gm.SetHeader("To", address[0])
|
||||
} else {
|
||||
gm.SetHeader("To", address...)
|
||||
}
|
||||
|
||||
gm.SetHeader("Subject", subject)
|
||||
gm.SetBody("text/html", content)
|
||||
d := gomail.NewDialer(
|
||||
"email-smtp.us-east-2.amazonaws.com",
|
||||
465,
|
||||
"AKIA6ILZQBMNF4T7HLJV",
|
||||
"BH5TmE3FdgYs8tepWQZW5LLvbryQ+sWJde7+sAm++0/E",
|
||||
)
|
||||
|
||||
err := d.DialAndSend(gm)
|
||||
if err != nil {
|
||||
logs.NewLog("").Errorf("html邮件 发送异常 subject: %s address: %s err: %+v", subject, address[0], err)
|
||||
return err
|
||||
}
|
||||
|
||||
logs.NewLog("").Infof("html邮件 发送成功 subject: %s address: %s", subject, address[0])
|
||||
return nil
|
||||
}
|
11
common/email/email_tool_test.go
Normal file
11
common/email/email_tool_test.go
Normal file
@ -0,0 +1,11 @@
|
||||
package email
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestSendDiscountCodeEmail(t *testing.T) {
|
||||
err := sendNoticeEmail("我是测试标题", "我是测试内容", "mylomen.shao@freebrio.com")
|
||||
fmt.Println(err)
|
||||
}
|
237
common/email/send_reset_pwd_code.go
Normal file
237
common/email/send_reset_pwd_code.go
Normal file
@ -0,0 +1,237 @@
|
||||
package email
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
)
|
||||
|
||||
const mylomen_code_email_template = `<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>code</title>
|
||||
<style>
|
||||
@font-face{
|
||||
font-family:Montserrat-Bold;
|
||||
src: url('https://cdn.shopifycdn.net/s/files/1/0592/3766/2905/files/Montserrat-Bold.otf?v=1678861979');
|
||||
}
|
||||
@font-face{
|
||||
font-family:Montserrat-Medium;
|
||||
src: url('https://cdn.shopify.com/s/files/1/0592/3766/2905/files/Montserrat-Medium.otf?v=1680083530');
|
||||
}
|
||||
@font-face{
|
||||
font-family:DINCond-Bold;
|
||||
src: url('https://cdn.shopify.com/s/files/1/0592/3766/2905/files/DINCond-Bold_e86b57e0-624c-475b-b6ed-00d5538b9a0e.otf?v=1680260215');
|
||||
}
|
||||
*{
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
}
|
||||
.code{
|
||||
background: #F3F3F7;
|
||||
}
|
||||
.code_con{
|
||||
width: 600px;
|
||||
height: 100vh;
|
||||
margin: auto;
|
||||
}
|
||||
.navigation_bar{
|
||||
width: 100%%;
|
||||
height: 8px;
|
||||
background: #A1F200;
|
||||
}
|
||||
.icon{
|
||||
width: 120px;
|
||||
margin: auto;
|
||||
padding-top: 14px;
|
||||
}
|
||||
.icon img{
|
||||
width: 100%%;
|
||||
}
|
||||
.freebeat_img{
|
||||
width: 100px;
|
||||
margin: auto;
|
||||
padding-top: 61px;
|
||||
}
|
||||
.freebeat_img img{
|
||||
width: 100%%;
|
||||
}
|
||||
.verification{
|
||||
margin:60px 25px 0 25px;
|
||||
background: #FFFFFF;
|
||||
border-radius: 20px 20px 20px 20px;
|
||||
}
|
||||
.verification .title{
|
||||
font-size: 20px;
|
||||
font-family: Montserrat-Bold, Montserrat;
|
||||
font-weight: bold;
|
||||
color: #121212;
|
||||
line-height: 20px;
|
||||
text-align: center;
|
||||
padding-top: 34px;
|
||||
}
|
||||
.verification .num{
|
||||
margin:30px 85px;
|
||||
background: #F7F7F7;
|
||||
border-radius: 14px 14px 14px 14px;
|
||||
}
|
||||
.verification .num p{
|
||||
font-size: 60px;
|
||||
font-family: DINCond-Bold-Regular, DINCond-Bold;
|
||||
font-weight: 400;
|
||||
color: #121212;
|
||||
line-height: 60px;
|
||||
padding: 20px 0;
|
||||
text-align: center;
|
||||
}
|
||||
.verification .desc{
|
||||
font-size: 14px;
|
||||
font-family: Montserrat-Medium, Montserrat;
|
||||
font-weight: 500;
|
||||
color: #121212;
|
||||
line-height: 18px;
|
||||
text-align: center;
|
||||
padding: 0 138px 30px 138px;
|
||||
opacity: 0.5;
|
||||
}
|
||||
.important{
|
||||
margin-top: 40px;
|
||||
margin-left: 25px;
|
||||
}
|
||||
.important .title{
|
||||
font-size: 18px;
|
||||
font-family: Montserrat-Bold, Montserrat;
|
||||
font-weight: bold;
|
||||
color: #121212;
|
||||
line-height: 18px;
|
||||
margin-bottom: 14px;
|
||||
}
|
||||
.important .desc{
|
||||
font-size: 14px;
|
||||
font-family: Montserrat-Medium, Montserrat;
|
||||
font-weight: 500;
|
||||
color: #000000;
|
||||
line-height: 20px;
|
||||
}
|
||||
.bottom{
|
||||
width: 100%%;
|
||||
height: 48px;
|
||||
background: #FFFFFF;
|
||||
margin-top: 63px;
|
||||
}
|
||||
.bottom .con{
|
||||
padding: 18px 162px;
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
}
|
||||
.bottom .con a{
|
||||
font-size: 12px;
|
||||
font-family: Montserrat-Medium, Montserrat;
|
||||
font-weight: 500;
|
||||
color: #121212;
|
||||
line-height: 12px;
|
||||
opacity: 0.8;
|
||||
text-decoration: underline;
|
||||
}
|
||||
@media screen and (max-width: 640px){
|
||||
.code_con{
|
||||
width: 100%%;
|
||||
}
|
||||
.navigation_bar{
|
||||
height: 5px;
|
||||
}
|
||||
.icon{
|
||||
width: 75px;
|
||||
padding-top: 9px;
|
||||
}
|
||||
.freebeat_img{
|
||||
width: 63px;
|
||||
padding-top: 38px;
|
||||
}
|
||||
.verification{
|
||||
margin:38px 16px 0 16px;
|
||||
border-radius: 13px 13px 13px 13px;
|
||||
}
|
||||
.verification .title{
|
||||
font-size: 13px;
|
||||
line-height: 13px;
|
||||
padding-top: 21px;
|
||||
}
|
||||
.verification .num{
|
||||
margin:19px 53px;
|
||||
border-radius: 9px 9px 9px 9px;
|
||||
}
|
||||
.verification .num p{
|
||||
font-size: 38px;
|
||||
line-height: 38px;
|
||||
padding: 13px 0;
|
||||
}
|
||||
.verification .desc{
|
||||
font-size: 9px;
|
||||
line-height: 11px;
|
||||
padding: 0 86px 19px 86px;
|
||||
}
|
||||
.important{
|
||||
margin-top: 25px;
|
||||
margin-left: 16px;
|
||||
}
|
||||
.important .title{
|
||||
font-size: 11px;
|
||||
line-height: 11px;
|
||||
margin-bottom: 9px;
|
||||
}
|
||||
.important .desc{
|
||||
font-size: 9px;
|
||||
line-height: 13px;
|
||||
}
|
||||
.bottom{
|
||||
height: 30px;
|
||||
margin-top: 39px;
|
||||
}
|
||||
.bottom .con{
|
||||
padding: 11px 80px;
|
||||
}
|
||||
.bottom .con a{
|
||||
font-size: 8px;
|
||||
line-height: 8px;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="code">
|
||||
<div class="code_con">
|
||||
<div class="navigation_bar"></div>
|
||||
<div class="verification">
|
||||
<div class="title">Your verification code to reset your password</div>
|
||||
<div class="num"><p>%s</p></div>
|
||||
<div class="desc">Please complete the account verification process in one hours!</div>
|
||||
</div>
|
||||
<div class="important">
|
||||
<div class="title">IMPORTANT:</div>
|
||||
<div class="desc">
|
||||
Please do not share this email with anyone!<br>
|
||||
This email was automatically generated, please do not reply.<br>
|
||||
If you do not know why you have received this email, please discard it.
|
||||
</div>
|
||||
</div>
|
||||
<div class="bottom">
|
||||
<div class="con">
|
||||
<a href="https://mylomen.com//#/privacyPolicy">Privacy Policy</a>
|
||||
<a href="https://mylomen.com//#/serviceTerms">Terms of Service</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
</html>`
|
||||
|
||||
func SendEmailVerifyCodeByEmail(code string, address ...string) error {
|
||||
content := fmt.Sprintf(mylomen_code_email_template, strings.TrimSpace(code))
|
||||
return sendNoticeEmail(
|
||||
"🎉 Your verification code to reset your password",
|
||||
content,
|
||||
address...)
|
||||
}
|
@ -25,8 +25,6 @@ func UserAuth(next echo.HandlerFunc) echo.HandlerFunc {
|
||||
}
|
||||
|
||||
//存入数据
|
||||
c.Set(constant.CorpId, loginResult.CorpId)
|
||||
c.Set(constant.BizId, loginResult.BizId)
|
||||
c.Set(constant.UID, loginResult.Uid)
|
||||
|
||||
return next(c)
|
||||
|
5
common/limit/init.go
Normal file
5
common/limit/init.go
Normal file
@ -0,0 +1,5 @@
|
||||
package limit
|
||||
|
||||
func init() {
|
||||
|
||||
}
|
49
common/utils/randomUtil.go
Normal file
49
common/utils/randomUtil.go
Normal file
@ -0,0 +1,49 @@
|
||||
package utils
|
||||
|
||||
import (
|
||||
tRand "crypto/rand"
|
||||
"math/big"
|
||||
"math/rand"
|
||||
"time"
|
||||
)
|
||||
|
||||
var defaultLetters = []rune("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789")
|
||||
|
||||
// GetPseudoRandomCode 伪随机数(性能高)
|
||||
func GetPseudoRandomCode(n int, allowedChars ...[]rune) string {
|
||||
//rand.Seed(time.Now().UnixNano())
|
||||
rand.New(rand.NewSource(time.Now().UnixNano()))
|
||||
|
||||
var letters []rune
|
||||
|
||||
if len(allowedChars) == 0 {
|
||||
letters = defaultLetters
|
||||
} else {
|
||||
letters = allowedChars[0]
|
||||
}
|
||||
|
||||
b := make([]rune, n)
|
||||
for i := range b {
|
||||
b[i] = letters[rand.Intn(len(letters))]
|
||||
}
|
||||
|
||||
return string(b)
|
||||
}
|
||||
|
||||
// GetTrueRandomCode 真随机数 (在linux上已经有一个实现就是/dev/urandom,crypto/rand 就是从这个地方读“真随机”数字返回,但性能比较慢)
|
||||
func GetTrueRandomCode(n int, allowedChars ...[]rune) string {
|
||||
var letters []rune
|
||||
if len(allowedChars) == 0 {
|
||||
letters = defaultLetters
|
||||
} else {
|
||||
letters = allowedChars[0]
|
||||
}
|
||||
|
||||
b := make([]rune, n)
|
||||
for i := range b {
|
||||
n, _ := tRand.Int(tRand.Reader, big.NewInt(int64(len(letters))))
|
||||
b[i] = letters[n.Int64()]
|
||||
}
|
||||
|
||||
return string(b)
|
||||
}
|
11
common/utils/randomUtil_test.go
Normal file
11
common/utils/randomUtil_test.go
Normal file
@ -0,0 +1,11 @@
|
||||
package utils
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestRandom1(t *testing.T) {
|
||||
fmt.Println(GetPseudoRandomCode(6))
|
||||
fmt.Println(GetTrueRandomCode(6))
|
||||
}
|
2
go.mod
2
go.mod
@ -13,6 +13,7 @@ require (
|
||||
github.com/robfig/cron/v3 v3.0.1
|
||||
github.com/spf13/viper v1.18.2
|
||||
go.uber.org/zap v1.27.0
|
||||
gopkg.in/gomail.v2 v2.0.0-20160411212932-81ebce5c23df
|
||||
gorm.io/driver/mysql v1.5.4
|
||||
gorm.io/gorm v1.25.7
|
||||
)
|
||||
@ -114,6 +115,7 @@ require (
|
||||
google.golang.org/genproto/googleapis/rpc v0.0.0-20231120223509-83a465c0220f // indirect
|
||||
google.golang.org/grpc v1.59.0 // indirect
|
||||
google.golang.org/protobuf v1.31.0 // indirect
|
||||
gopkg.in/alexcesaro/quotedprintable.v3 v3.0.0-20150716171945-2caba252f4dc // indirect
|
||||
gopkg.in/go-playground/assert.v1 v1.2.1 // indirect
|
||||
gopkg.in/ini.v1 v1.67.0 // indirect
|
||||
gopkg.in/yaml.v3 v3.0.1 // indirect
|
||||
|
4
go.sum
4
go.sum
@ -497,11 +497,15 @@ google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQ
|
||||
google.golang.org/protobuf v1.31.0 h1:g0LDEJHgrBl9N9r17Ru3sqWhkIx2NB67okBHPwC7hs8=
|
||||
google.golang.org/protobuf v1.31.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
|
||||
gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw=
|
||||
gopkg.in/alexcesaro/quotedprintable.v3 v3.0.0-20150716171945-2caba252f4dc h1:2gGKlE2+asNV9m7xrywl36YYNnBG5ZQ0r/BOOxqPpmk=
|
||||
gopkg.in/alexcesaro/quotedprintable.v3 v3.0.0-20150716171945-2caba252f4dc/go.mod h1:m7x9LTH6d71AHyAX77c9yqWCCa3UKHcVEj9y7hAtKDk=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 h1:YR8cESwS4TdDjEe65xsg0ogRM/Nc3DYOhEAlW+xobZo=
|
||||
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/go-playground/assert.v1 v1.2.1 h1:xoYuJVE7KT85PYWrN730RguIQO0ePzVRfFMXadIrXTM=
|
||||
gopkg.in/go-playground/assert.v1 v1.2.1/go.mod h1:9RXL0bg/zibRAgZUYszZSwO/z8Y/a8bDuhia5mkpMnE=
|
||||
gopkg.in/gomail.v2 v2.0.0-20160411212932-81ebce5c23df h1:n7WqCuqOuCbNr617RXOY0AWRXxgwEyPp2z+p0+hgMuE=
|
||||
gopkg.in/gomail.v2 v2.0.0-20160411212932-81ebce5c23df/go.mod h1:LRQQ+SO6ZHR7tOkpBDuZnXENFzX8qRjMDMyPD6BRkCw=
|
||||
gopkg.in/ini.v1 v1.67.0 h1:Dgnx+6+nfE+IfzjUEISNeydPJh9AXNNsWbGP9KzCsOA=
|
||||
gopkg.in/ini.v1 v1.67.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k=
|
||||
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 h1:uRGJdciOHaEIrze2W8Q3AKkepLTh2hOroT7a+7czfdQ=
|
||||
|
16
infrastructure/repository/g_account.go
Normal file
16
infrastructure/repository/g_account.go
Normal file
@ -0,0 +1,16 @@
|
||||
package repository
|
||||
|
||||
import "context"
|
||||
|
||||
type gUserRepository interface {
|
||||
//FindByAccount 根据 account 查询用户
|
||||
FindByAccount(ctx context.Context, account string) *AccountDO
|
||||
|
||||
//Create 创建用户
|
||||
Create(ctx context.Context, data *AccountDO) error
|
||||
|
||||
//UpdateById 根据ID更新用户
|
||||
UpdateById(ctx context.Context, data *AccountDO) error
|
||||
}
|
||||
|
||||
var GUser gUserRepository = new(gUserRepositoryImpl)
|
79
infrastructure/repository/g_account_repository.go
Normal file
79
infrastructure/repository/g_account_repository.go
Normal file
@ -0,0 +1,79 @@
|
||||
package repository
|
||||
|
||||
import (
|
||||
"context"
|
||||
"gorm.io/gorm"
|
||||
"gorm.io/gorm/clause"
|
||||
"time"
|
||||
)
|
||||
|
||||
// AccountDO 游戏帐号表
|
||||
type AccountDO struct {
|
||||
Id uint64 `gorm:"column:id;type:bigint(20) unsigned;primary_key;AUTO_INCREMENT" json:"id"`
|
||||
Email string `gorm:"column:email;type:varchar(64);comment:帐号;NOT NULL" json:"email"`
|
||||
Pwd string `gorm:"column:pwd;type:varchar(128);comment:密码;NOT NULL" json:"pwd"`
|
||||
Name string `gorm:"column:name;type:varchar(64);comment:用户名" json:"name"`
|
||||
Avatar string `gorm:"column:avatar;type:varchar(128);comment:头像" json:"avatar"`
|
||||
Gender uint `gorm:"column:gender;type:tinyint(4) unsigned;comment:性别。0:未知 ;1:男;2:女; 3:其他" json:"gender"`
|
||||
Phone string `gorm:"column:phone;type:varchar(32);comment:手机号码" json:"phone"`
|
||||
Status uint `gorm:"column:status;type:tinyint(4) unsigned;default:1;comment:是否有效。0:否;1:是;NOT NULL" json:"status"`
|
||||
RegisterSource string `gorm:"column:register_source;type:varchar(16);comment:注册来源" json:"register_source"`
|
||||
LastIp string `gorm:"column:last_ip;type:varchar(32);comment:最近登录的ip" json:"last_ip"`
|
||||
Deleted uint `gorm:"column:deleted;type:tinyint(4) unsigned;default:0;comment:逻辑删除。 0:未删除;1:已删除;NOT NULL" json:"deleted"`
|
||||
CreateTime time.Time `gorm:"column:create_time;type:timestamp;default:CURRENT_TIMESTAMP;comment:创建时间;NOT NULL" json:"create_time"`
|
||||
UpdateTime time.Time `gorm:"column:update_time;type:timestamp;default:CURRENT_TIMESTAMP;comment:更新时间;NOT NULL" json:"update_time"`
|
||||
}
|
||||
|
||||
func (m *AccountDO) TableName() string {
|
||||
return "g_account"
|
||||
}
|
||||
|
||||
type gUserRepositoryImpl struct {
|
||||
}
|
||||
|
||||
// FindByAccount 根据 account 和 pwd 查询用户
|
||||
func (gUserRepositoryImpl) FindByAccount(ctx context.Context, account string) *AccountDO {
|
||||
db, ok := ctx.Value("db").(*gorm.DB)
|
||||
if !ok {
|
||||
db = Db
|
||||
}
|
||||
|
||||
var model AccountDO
|
||||
sqlErr := db.Model(&model).Where("email=?", account).First(&model).Error
|
||||
|
||||
if sqlErr != nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
return &model
|
||||
}
|
||||
|
||||
// Create 创建用户
|
||||
func (gUserRepositoryImpl) Create(ctx context.Context, data *AccountDO) error {
|
||||
db, ok := ctx.Value("db").(*gorm.DB)
|
||||
if !ok {
|
||||
db = Db
|
||||
}
|
||||
|
||||
data.Deleted = 0
|
||||
|
||||
return db.Clauses(clause.OnConflict{
|
||||
Columns: []clause.Column{{Name: "email"}},
|
||||
DoUpdates: clause.AssignmentColumns([]string{"deleted"}),
|
||||
}).Create(data).Error
|
||||
}
|
||||
|
||||
// UpdateById 根据ID更新用户
|
||||
func (gUserRepositoryImpl) UpdateById(ctx context.Context, data *AccountDO) error {
|
||||
db, ok := ctx.Value("db").(*gorm.DB)
|
||||
if !ok {
|
||||
db = Db
|
||||
}
|
||||
|
||||
sqlErr := db.Model(data).Where("id=?", data.Id).Updates(data).Error
|
||||
|
||||
if sqlErr != nil {
|
||||
return sqlErr
|
||||
}
|
||||
return nil
|
||||
}
|
15
infrastructure/repository/g_login_token.go
Normal file
15
infrastructure/repository/g_login_token.go
Normal file
@ -0,0 +1,15 @@
|
||||
package repository
|
||||
|
||||
import "context"
|
||||
|
||||
type thirdUserTokenRepository interface {
|
||||
FindByToken(ctx context.Context, token string) *GLoginToken
|
||||
|
||||
FindByUid(ctx context.Context, uid uint64) *GLoginToken
|
||||
|
||||
SaveUserLoginToken(ctx context.Context, data *GLoginToken) error
|
||||
|
||||
UpdateUserLoginToken(ctx context.Context, data *GLoginToken) error
|
||||
}
|
||||
|
||||
var GUserToken thirdUserTokenRepository = new(thirdUserTokenRepositoryImpl)
|
@ -7,32 +7,31 @@ import (
|
||||
"time"
|
||||
)
|
||||
|
||||
// FThirdUserTokenDO 第三方用户token表
|
||||
type FThirdUserTokenDO struct {
|
||||
Id uint64 `gorm:"column:id;type:bigint(20) unsigned;primary_key;AUTO_INCREMENT" json:"id"`
|
||||
CorpId uint64 `gorm:"column:corp_id;type:bigint(20) unsigned;comment:企业id;NOT NULL" json:"corp_id"`
|
||||
BizId uint64 `gorm:"column:biz_id;type:bigint(20);comment:业务id。 " json:"biz_id"`
|
||||
CorpUid uint64 `gorm:"column:corp_uid;type:bigint(20) unsigned;comment:企业uid;NOT NULL" json:"corp_uid"`
|
||||
// GLoginToken 全局用户登录token表
|
||||
type GLoginToken struct {
|
||||
Id uint64 `gorm:"column:id;type:bigint(20) unsigned;primary_key;AUTO_INCREMENT;comment:主键" json:"id"`
|
||||
Uid uint64 `gorm:"column:uid;type:bigint(20) unsigned;default:0;comment:uid;NOT NULL" json:"uid"`
|
||||
Platform string `gorm:"column:platform;type:varchar(8);default:web;comment:平台类型;NOT NULL" json:"platform"`
|
||||
AccessToken string `gorm:"column:access_token;type:varchar(64);comment:访问token" json:"access_token"`
|
||||
ExpireTime int64 `gorm:"column:expire_time;type:bigint(20) unsigned;comment:超时时间;NOT NULL" json:"expire_time"`
|
||||
CreateTime time.Time `gorm:"column:create_time;type:timestamp;default:CURRENT_TIMESTAMP;comment:创建时间;NOT NULL" json:"create_time"`
|
||||
UpdateTime time.Time `gorm:"column:update_time;type:timestamp;default:CURRENT_TIMESTAMP;comment:更新时间;NOT NULL" json:"update_time"`
|
||||
}
|
||||
|
||||
func (m *FThirdUserTokenDO) TableName() string {
|
||||
return "f_third_user_token"
|
||||
func (m *GLoginToken) TableName() string {
|
||||
return "g_login_token"
|
||||
}
|
||||
|
||||
type thirdUserTokenRepositoryImpl struct {
|
||||
}
|
||||
|
||||
func (thirdUserTokenRepositoryImpl) FindByToken(ctx context.Context, token string) *FThirdUserTokenDO {
|
||||
func (thirdUserTokenRepositoryImpl) FindByToken(ctx context.Context, token string) *GLoginToken {
|
||||
db, ok := ctx.Value("db").(*gorm.DB)
|
||||
if !ok {
|
||||
db = Db
|
||||
}
|
||||
|
||||
var model FThirdUserTokenDO
|
||||
var model GLoginToken
|
||||
sqlErr := db.Model(&model).Where("access_token=?", token).First(&model).Error
|
||||
|
||||
if sqlErr != nil {
|
||||
@ -41,14 +40,15 @@ func (thirdUserTokenRepositoryImpl) FindByToken(ctx context.Context, token strin
|
||||
|
||||
return &model
|
||||
}
|
||||
func (thirdUserTokenRepositoryImpl) FindByBizAndCorpId(ctx context.Context, bizId, corpUid uint64) *FThirdUserTokenDO {
|
||||
|
||||
func (thirdUserTokenRepositoryImpl) FindByUid(ctx context.Context, uid uint64) *GLoginToken {
|
||||
db, ok := ctx.Value("db").(*gorm.DB)
|
||||
if !ok {
|
||||
db = Db
|
||||
}
|
||||
|
||||
var model FThirdUserTokenDO
|
||||
sqlErr := db.Model(&model).Where("biz_id=? and corp_uid=?", bizId, corpUid).First(&model).Error
|
||||
var model GLoginToken
|
||||
sqlErr := db.Model(&model).Where("uid=? and platform=web", uid).First(&model).Error
|
||||
|
||||
if sqlErr != nil {
|
||||
return nil
|
||||
@ -57,19 +57,19 @@ func (thirdUserTokenRepositoryImpl) FindByBizAndCorpId(ctx context.Context, bizI
|
||||
return &model
|
||||
}
|
||||
|
||||
func (thirdUserTokenRepositoryImpl) SaveUserLoginToken(ctx context.Context, data *FThirdUserTokenDO) error {
|
||||
func (thirdUserTokenRepositoryImpl) SaveUserLoginToken(ctx context.Context, data *GLoginToken) error {
|
||||
db, ok := ctx.Value("db").(*gorm.DB)
|
||||
if !ok {
|
||||
db = Db
|
||||
}
|
||||
|
||||
return db.Clauses(clause.OnConflict{
|
||||
Columns: []clause.Column{{Name: "corp_uid"}, {Name: "biz_id"}},
|
||||
Columns: []clause.Column{{Name: "uid"}, {Name: "platform"}},
|
||||
DoUpdates: clause.AssignmentColumns([]string{"access_token", "expire_time"}),
|
||||
}).Create(data).Error
|
||||
}
|
||||
|
||||
func (thirdUserTokenRepositoryImpl) UpdateUserLoginToken(ctx context.Context, data *FThirdUserTokenDO) error {
|
||||
func (thirdUserTokenRepositoryImpl) UpdateUserLoginToken(ctx context.Context, data *GLoginToken) error {
|
||||
db, ok := ctx.Value("db").(*gorm.DB)
|
||||
if !ok {
|
||||
db = Db
|
@ -1,15 +0,0 @@
|
||||
package repository
|
||||
|
||||
import "context"
|
||||
|
||||
type thirdAgentCorpRepository interface {
|
||||
QueryPage(ctx context.Context, page, size int) *[]FThirdAgentCorpRelationDO
|
||||
FindById(ctx context.Context, id uint64) *FThirdAgentCorpRelationDO
|
||||
Count(ctx context.Context) int64
|
||||
|
||||
Create(ctx context.Context, data *FThirdAgentCorpRelationDO) error
|
||||
UpdateById(ctx context.Context, data FThirdAgentCorpRelationDO) error
|
||||
deleteById(ctx context.Context, id uint64, operator string) error
|
||||
}
|
||||
|
||||
var ThirdAgentCorp thirdAgentCorpRepository = new(thirdAgentCorpRepositoryImpl)
|
@ -1,119 +0,0 @@
|
||||
package repository
|
||||
|
||||
import (
|
||||
"ai-gateway/common/utils"
|
||||
"context"
|
||||
"gorm.io/gorm"
|
||||
"time"
|
||||
)
|
||||
|
||||
// FThirdAgentCorpRelationDO 第三方 代理&企业 关系表
|
||||
type FThirdAgentCorpRelationDO struct {
|
||||
Id uint64 `gorm:"column:id;type:bigint(20) unsigned;primary_key;AUTO_INCREMENT" json:"id"`
|
||||
AgentId uint64 `gorm:"column:agent_id;type:bigint(20) unsigned;comment:代理id;NOT NULL" json:"agent_id"`
|
||||
CorpId uint64 `gorm:"column:corp_id;type:bigint(20) unsigned;comment:企业id;NOT NULL" json:"corp_id"`
|
||||
BizId int64 `gorm:"column:biz_id;type:bigint(20);comment:业务id。 " json:"biz_id"`
|
||||
QualityLimit uint64 `gorm:"column:quality_limit;type:bigint(20) unsigned;default:0;comment:数量限制;NOT NULL" json:"quality_limit"`
|
||||
StartTime uint64 `gorm:"column:start_time;type:bigint(20) unsigned;comment:开始时间;NOT NULL" json:"start_time"`
|
||||
EndTime uint64 `gorm:"column:end_time;type:bigint(20) unsigned;comment:结束时间;NOT NULL" json:"end_time"`
|
||||
Deleted uint `gorm:"column:deleted;type:tinyint(1) unsigned;default:0;comment:逻辑删除。 0:未删除;1:已删除;NOT NULL" json:"deleted"`
|
||||
CreateTime time.Time `gorm:"column:create_time;type:timestamp;default:CURRENT_TIMESTAMP;comment:创建时间;NOT NULL" json:"create_time"`
|
||||
UpdateTime time.Time `gorm:"column:update_time;type:timestamp;default:CURRENT_TIMESTAMP;comment:更新时间;NOT NULL" json:"update_time"`
|
||||
}
|
||||
|
||||
func (m *FThirdAgentCorpRelationDO) TableName() string {
|
||||
return "f_third_agent_corp_relation"
|
||||
}
|
||||
|
||||
type thirdAgentCorpRepositoryImpl struct {
|
||||
}
|
||||
|
||||
func (thirdAgentCorpRepositoryImpl) QueryPage(ctx context.Context, page, size int) *[]FThirdAgentCorpRelationDO {
|
||||
db, ok := ctx.Value("db").(*gorm.DB)
|
||||
if !ok {
|
||||
db = Db
|
||||
}
|
||||
|
||||
offset := (page - 1) * size
|
||||
offset = utils.If(offset >= 0, offset, 0)
|
||||
var dataList []FThirdAgentCorpRelationDO
|
||||
sqlErr := db.Model(&FThirdAgentCorpRelationDO{}).Order("id DESC").Limit(size).Offset(offset).Find(&dataList).Error
|
||||
if sqlErr != nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
if len(dataList) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
return &dataList
|
||||
|
||||
}
|
||||
|
||||
func (thirdAgentCorpRepositoryImpl) FindById(ctx context.Context, id uint64) *FThirdAgentCorpRelationDO {
|
||||
db, ok := ctx.Value("db").(*gorm.DB)
|
||||
if !ok {
|
||||
db = Db
|
||||
}
|
||||
|
||||
var model FThirdAgentCorpRelationDO
|
||||
sqlErr := db.Where("id=?", id).First(&model).Error
|
||||
if sqlErr != nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
return &model
|
||||
}
|
||||
|
||||
func (thirdAgentCorpRepositoryImpl) Count(ctx context.Context) int64 {
|
||||
db, ok := ctx.Value("db").(*gorm.DB)
|
||||
if !ok {
|
||||
db = Db
|
||||
}
|
||||
|
||||
var total int64
|
||||
sqlErr := db.Model(&FThirdAgentCorpRelationDO{}).Select("count(*)").First(&total).Error
|
||||
if sqlErr != nil {
|
||||
return 0
|
||||
}
|
||||
|
||||
return total
|
||||
}
|
||||
|
||||
func (thirdAgentCorpRepositoryImpl) Create(ctx context.Context, data *FThirdAgentCorpRelationDO) error {
|
||||
db, ok := ctx.Value("db").(*gorm.DB)
|
||||
if !ok {
|
||||
db = Db
|
||||
}
|
||||
|
||||
//保存数据
|
||||
return db.Create(data).Error
|
||||
}
|
||||
|
||||
func (thirdAgentCorpRepositoryImpl) UpdateById(ctx context.Context, data FThirdAgentCorpRelationDO) error {
|
||||
db, ok := ctx.Value("db").(*gorm.DB)
|
||||
if !ok {
|
||||
db = Db
|
||||
}
|
||||
|
||||
//更新数据
|
||||
return db.Updates(&data).Error
|
||||
}
|
||||
|
||||
func (thirdAgentCorpRepositoryImpl) deleteById(ctx context.Context, id uint64, operator string) error {
|
||||
db, ok := ctx.Value("db").(*gorm.DB)
|
||||
if !ok {
|
||||
db = Db
|
||||
}
|
||||
|
||||
data := FThirdAgentCorpRelationDO{}
|
||||
sqlErr := db.Model(&data).
|
||||
Select("deleted").
|
||||
Where("id=?", id).
|
||||
Updates(FThirdAgentCorpRelationDO{Deleted: 1}).Error
|
||||
if sqlErr != nil {
|
||||
return sqlErr
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
@ -1,17 +0,0 @@
|
||||
package repository
|
||||
|
||||
import "context"
|
||||
|
||||
type thirdAgentInfoRepository interface {
|
||||
QueryPage(ctx context.Context, page, size int) *[]FThirdAgentInfoDO
|
||||
FindById(ctx context.Context, id uint64) *FThirdAgentInfoDO
|
||||
Count(ctx context.Context) int64
|
||||
|
||||
Create(ctx context.Context, data *FThirdAgentInfoDO) error
|
||||
UpdateById(ctx context.Context, data FThirdAgentInfoDO) error
|
||||
UpdateStatusById(ctx context.Context, id uint64, status int, operator string) error
|
||||
|
||||
deleteById(ctx context.Context, id uint64, operator string) error
|
||||
}
|
||||
|
||||
var ThirdAgentInfo thirdAgentInfoRepository = new(thirdAgentInfoRepositoryImpl)
|
@ -1,139 +0,0 @@
|
||||
package repository
|
||||
|
||||
import (
|
||||
"ai-gateway/common/utils"
|
||||
"context"
|
||||
"gorm.io/gorm"
|
||||
"time"
|
||||
)
|
||||
|
||||
// FThirdAgentInfoDO 三方代理 信息表
|
||||
type FThirdAgentInfoDO struct {
|
||||
Id uint64 `gorm:"column:id;type:bigint(20) unsigned;primary_key;AUTO_INCREMENT" json:"id"`
|
||||
Sn string `gorm:"column:sn;type:varchar(64);comment:sn" json:"sn"`
|
||||
Name string `gorm:"column:name;type:varchar(64);comment:名称" json:"name"`
|
||||
Account string `gorm:"column:account;type:varchar(64);comment:帐号" json:"account"`
|
||||
Pwd string `gorm:"column:pwd;type:varchar(128);comment:密码" json:"pwd"`
|
||||
Iphone string `gorm:"column:iphone;type:varchar(32);comment:联系方式" json:"iphone"`
|
||||
Email string `gorm:"column:email;type:varchar(64);comment:email" json:"email"`
|
||||
Remark string `gorm:"column:remark;type:varchar(64);comment:备注" json:"remark"`
|
||||
Status int `gorm:"column:status;type:tinyint(1) unsigned;default:1;comment:是否有效。0:否;1:是;NOT NULL" json:"status"`
|
||||
Deleted uint `gorm:"column:deleted;type:tinyint(1) unsigned;default:0;comment:逻辑删除。 0:未删除;1:已删除;NOT NULL" json:"deleted"`
|
||||
CreateTime time.Time `gorm:"column:create_time;type:timestamp;default:CURRENT_TIMESTAMP;comment:创建时间;NOT NULL" json:"create_time"`
|
||||
UpdateTime time.Time `gorm:"column:update_time;type:timestamp;default:CURRENT_TIMESTAMP;comment:更新时间;NOT NULL" json:"update_time"`
|
||||
}
|
||||
|
||||
func (m *FThirdAgentInfoDO) TableName() string {
|
||||
return "f_third_agent_info"
|
||||
}
|
||||
|
||||
type thirdAgentInfoRepositoryImpl struct {
|
||||
}
|
||||
|
||||
func (thirdAgentInfoRepositoryImpl) QueryPage(ctx context.Context, page, size int) *[]FThirdAgentInfoDO {
|
||||
db, ok := ctx.Value("db").(*gorm.DB)
|
||||
if !ok {
|
||||
db = Db
|
||||
}
|
||||
offset := (page - 1) * size
|
||||
offset = utils.If(offset >= 0, offset, 0)
|
||||
var dataList []FThirdAgentInfoDO
|
||||
sqlErr := db.Model(&FThirdAgentInfoDO{}).Order("id DESC").Limit(size).Offset(offset).Find(&dataList).Error
|
||||
if sqlErr != nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
if len(dataList) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
return &dataList
|
||||
|
||||
}
|
||||
|
||||
func (thirdAgentInfoRepositoryImpl) FindById(ctx context.Context, id uint64) *FThirdAgentInfoDO {
|
||||
db, ok := ctx.Value("db").(*gorm.DB)
|
||||
if !ok {
|
||||
db = Db
|
||||
}
|
||||
|
||||
var model FThirdAgentInfoDO
|
||||
sqlErr := db.Where("id=?", id).First(&model).Error
|
||||
if sqlErr != nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
return &model
|
||||
}
|
||||
|
||||
func (thirdAgentInfoRepositoryImpl) Count(ctx context.Context) int64 {
|
||||
db, ok := ctx.Value("db").(*gorm.DB)
|
||||
if !ok {
|
||||
db = Db
|
||||
}
|
||||
|
||||
var total int64
|
||||
sqlErr := db.Model(&FThirdAgentInfoDO{}).Select("count(*)").First(&total).Error
|
||||
if sqlErr != nil {
|
||||
return 0
|
||||
}
|
||||
|
||||
return total
|
||||
}
|
||||
|
||||
func (thirdAgentInfoRepositoryImpl) Create(ctx context.Context, data *FThirdAgentInfoDO) error {
|
||||
db, ok := ctx.Value("db").(*gorm.DB)
|
||||
if !ok {
|
||||
db = Db
|
||||
}
|
||||
|
||||
//保存数据
|
||||
return db.Create(data).Error
|
||||
}
|
||||
|
||||
func (thirdAgentInfoRepositoryImpl) UpdateById(ctx context.Context, data FThirdAgentInfoDO) error {
|
||||
db, ok := ctx.Value("db").(*gorm.DB)
|
||||
if !ok {
|
||||
db = Db
|
||||
}
|
||||
|
||||
//更新数据
|
||||
return db.Updates(&data).Error
|
||||
|
||||
}
|
||||
|
||||
func (thirdAgentInfoRepositoryImpl) UpdateStatusById(ctx context.Context, id uint64, status int, operator string) error {
|
||||
db, ok := ctx.Value("db").(*gorm.DB)
|
||||
if !ok {
|
||||
db = Db
|
||||
}
|
||||
|
||||
data := FThirdAgentInfoDO{}
|
||||
sqlErr := db.Model(&data).
|
||||
Select("status").
|
||||
Where("id=?", id).
|
||||
Updates(FThirdAgentInfoDO{Status: status}).Error
|
||||
if sqlErr != nil {
|
||||
return sqlErr
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (thirdAgentInfoRepositoryImpl) deleteById(ctx context.Context, id uint64, operator string) error {
|
||||
db, ok := ctx.Value("db").(*gorm.DB)
|
||||
if !ok {
|
||||
db = Db
|
||||
}
|
||||
|
||||
data := FThirdAgentInfoDO{}
|
||||
sqlErr := db.Model(&data).
|
||||
Select("deleted").
|
||||
Where("id=?", id).
|
||||
Updates(FThirdAgentInfoDO{Deleted: 1}).Error
|
||||
if sqlErr != nil {
|
||||
return sqlErr
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
@ -1,16 +0,0 @@
|
||||
package repository
|
||||
|
||||
import "context"
|
||||
|
||||
type thirdCorpInfoRepository interface {
|
||||
QueryPage(ctx context.Context, page, size int) *[]FThirdCorpInfoDO
|
||||
FindById(ctx context.Context, id uint64) *FThirdCorpInfoDO
|
||||
Count(ctx context.Context) int64
|
||||
|
||||
Create(ctx context.Context, data *FThirdCorpInfoDO) error
|
||||
UpdateById(ctx context.Context, data FThirdCorpInfoDO) error
|
||||
UpdateStatusById(ctx context.Context, id uint64, state int, operator string) error
|
||||
deleteById(ctx context.Context, id uint64, operator string) error
|
||||
}
|
||||
|
||||
var ThirdCorpInfo thirdCorpInfoRepository = new(thirdCorpInfoRepositoryImpl)
|
@ -1,142 +0,0 @@
|
||||
package repository
|
||||
|
||||
import (
|
||||
"ai-gateway/common/logs"
|
||||
"ai-gateway/common/utils"
|
||||
"context"
|
||||
"gorm.io/gorm"
|
||||
"time"
|
||||
)
|
||||
|
||||
// FThirdCorpInfoDO 第三方企业 信息表
|
||||
type FThirdCorpInfoDO struct {
|
||||
Id uint64 `gorm:"column:id;type:bigint(20) unsigned;primary_key;AUTO_INCREMENT" json:"id"`
|
||||
Sn string `gorm:"column:sn;type:varchar(64);comment:sn" json:"sn"`
|
||||
SimpleName string `gorm:"column:simple_name;type:varchar(64);comment:企业简称" json:"simple_name"`
|
||||
Name string `gorm:"column:name;type:varchar(64);comment:名称" json:"name"`
|
||||
Iphone string `gorm:"column:iphone;type:varchar(32);comment:联系方式" json:"iphone"`
|
||||
Email string `gorm:"column:email;type:varchar(64);comment:email" json:"email"`
|
||||
Remark string `gorm:"column:remark;type:varchar(64);comment:备注" json:"remark"`
|
||||
Status int `gorm:"column:status;type:tinyint(1) unsigned;default:1;comment:是否有效。0:否;1:是;NOT NULL" json:"status"`
|
||||
Deleted uint `gorm:"column:deleted;type:tinyint(1) unsigned;default:0;comment:逻辑删除。 0:未删除;1:已删除;NOT NULL" json:"deleted"`
|
||||
CreateTime time.Time `gorm:"column:create_time;type:timestamp;default:CURRENT_TIMESTAMP;comment:创建时间;NOT NULL" json:"create_time"`
|
||||
UpdateTime time.Time `gorm:"column:update_time;type:timestamp;default:CURRENT_TIMESTAMP;comment:更新时间;NOT NULL" json:"update_time"`
|
||||
}
|
||||
|
||||
func (m *FThirdCorpInfoDO) TableName() string {
|
||||
return "f_third_corp_info"
|
||||
}
|
||||
|
||||
type thirdCorpInfoRepositoryImpl struct {
|
||||
}
|
||||
|
||||
func (thirdCorpInfoRepositoryImpl) QueryPage(ctx context.Context, page, size int) *[]FThirdCorpInfoDO {
|
||||
db, ok := ctx.Value("db").(*gorm.DB)
|
||||
if !ok {
|
||||
db = Db
|
||||
}
|
||||
|
||||
offset := (page - 1) * size
|
||||
offset = utils.If(offset >= 0, offset, 0)
|
||||
var dataList []FThirdCorpInfoDO
|
||||
sqlErr := db.Model(&FThirdCorpInfoDO{}).Order("id DESC").Limit(size).Offset(offset).Find(&dataList).Error
|
||||
if sqlErr != nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
if len(dataList) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
return &dataList
|
||||
|
||||
}
|
||||
|
||||
func (thirdCorpInfoRepositoryImpl) FindById(ctx context.Context, id uint64) *FThirdCorpInfoDO {
|
||||
db, ok := ctx.Value("db").(*gorm.DB)
|
||||
if !ok {
|
||||
db = Db
|
||||
}
|
||||
|
||||
var model FThirdCorpInfoDO
|
||||
sqlErr := db.Where("id=?", id).First(&model).Error
|
||||
if sqlErr != nil {
|
||||
logs.NewLog("").Errorf("FindById_sqlErr id:%d %+v", id, sqlErr)
|
||||
return nil
|
||||
}
|
||||
|
||||
return &model
|
||||
}
|
||||
|
||||
func (thirdCorpInfoRepositoryImpl) Count(ctx context.Context) int64 {
|
||||
db, ok := ctx.Value("db").(*gorm.DB)
|
||||
if !ok {
|
||||
db = Db
|
||||
}
|
||||
|
||||
var total int64
|
||||
sqlErr := db.Model(&FThirdCorpInfoDO{}).Select("count(*)").First(&total).Error
|
||||
if sqlErr != nil {
|
||||
logs.NewLog("").Errorf("Count_sqlErr %+v", sqlErr)
|
||||
return 0
|
||||
}
|
||||
|
||||
return total
|
||||
}
|
||||
|
||||
func (thirdCorpInfoRepositoryImpl) Create(ctx context.Context, data *FThirdCorpInfoDO) error {
|
||||
db, ok := ctx.Value("db").(*gorm.DB)
|
||||
if !ok {
|
||||
db = Db
|
||||
}
|
||||
|
||||
//保存数据
|
||||
return db.Create(data).Error
|
||||
}
|
||||
|
||||
func (thirdCorpInfoRepositoryImpl) UpdateById(ctx context.Context, data FThirdCorpInfoDO) error {
|
||||
db, ok := ctx.Value("db").(*gorm.DB)
|
||||
if !ok {
|
||||
db = Db
|
||||
}
|
||||
|
||||
//更新数据
|
||||
return db.Updates(&data).Error
|
||||
|
||||
}
|
||||
|
||||
func (thirdCorpInfoRepositoryImpl) UpdateStatusById(ctx context.Context, id uint64, status int, operator string) error {
|
||||
db, ok := ctx.Value("db").(*gorm.DB)
|
||||
if !ok {
|
||||
db = Db
|
||||
}
|
||||
|
||||
data := FThirdCorpInfoDO{}
|
||||
sqlErr := db.Model(&data).
|
||||
Select("status").
|
||||
Where("id=?", id).
|
||||
Updates(FThirdCorpInfoDO{Status: status}).Error
|
||||
if sqlErr != nil {
|
||||
return sqlErr
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (thirdCorpInfoRepositoryImpl) deleteById(ctx context.Context, id uint64, operator string) error {
|
||||
db, ok := ctx.Value("db").(*gorm.DB)
|
||||
if !ok {
|
||||
db = Db
|
||||
}
|
||||
|
||||
data := FThirdCorpInfoDO{}
|
||||
sqlErr := db.Model(&data).
|
||||
Select("deleted").
|
||||
Where("id=?", id).
|
||||
Updates(FThirdCorpInfoDO{Deleted: 1}).Error
|
||||
if sqlErr != nil {
|
||||
return sqlErr
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
@ -1,18 +0,0 @@
|
||||
package repository
|
||||
|
||||
import "context"
|
||||
|
||||
type thirdCorpUserAccountRepository interface {
|
||||
QueryPage(ctx context.Context, page, size int) *[]FThirdCorpUserAccountDO
|
||||
FindById(ctx context.Context, id uint64) *FThirdCorpUserAccountDO
|
||||
Count(ctx context.Context) int64
|
||||
|
||||
Create(ctx context.Context, data *FThirdCorpUserAccountDO) error
|
||||
UpdateById(ctx context.Context, data FThirdCorpUserAccountDO) error
|
||||
UpdateStatusById(ctx context.Context, id uint64, state int, operator string) error
|
||||
deleteById(ctx context.Context, id uint64, operator string) error
|
||||
|
||||
FindThirdAccountBy(ctx context.Context, bizId, corpId uint64, account string) *FThirdCorpUserAccountDO
|
||||
}
|
||||
|
||||
var ThirdCorpUserAccount thirdCorpUserAccountRepository = new(thirdCorpUserAccountRepositoryImpl)
|
@ -1,160 +0,0 @@
|
||||
package repository
|
||||
|
||||
import (
|
||||
"ai-gateway/common/logs"
|
||||
"ai-gateway/common/utils"
|
||||
"context"
|
||||
"gorm.io/gorm"
|
||||
"time"
|
||||
)
|
||||
|
||||
// FThirdCorpUserAccountDO 第三方 企业用户 帐号表
|
||||
type FThirdCorpUserAccountDO struct {
|
||||
Id uint64 `gorm:"column:id;type:bigint(20) unsigned;primary_key;AUTO_INCREMENT" json:"id"`
|
||||
Sn string `gorm:"column:sn;type:varchar(64);comment:sn" json:"sn"`
|
||||
CorpId uint64 `gorm:"column:corp_id;type:bigint(20) unsigned;comment:企业id;NOT NULL" json:"corp_id"`
|
||||
BizId int64 `gorm:"column:biz_id;type:bigint(20);comment:业务id。 " json:"biz_id"`
|
||||
Name string `gorm:"column:name;type:varchar(64);comment:名称" json:"name"`
|
||||
Admin uint `gorm:"column:admin;type:tinyint(1) unsigned;default:0;comment:是否管理员。0:否;1:是;NOT NULL" json:"admin"`
|
||||
Account string `gorm:"column:account;type:varchar(64);comment:帐号" json:"account"`
|
||||
Pwd string `gorm:"column:pwd;type:varchar(128);comment:密码" json:"pwd"`
|
||||
Status int `gorm:"column:status;type:tinyint(1) unsigned;default:1;comment:是否有效。0:否;1:是;NOT NULL" json:"status"`
|
||||
Deleted uint `gorm:"column:deleted;type:tinyint(1) unsigned;default:0;comment:逻辑删除。 0:未删除;1:已删除;NOT NULL" json:"deleted"`
|
||||
CreateTime time.Time `gorm:"column:create_time;type:timestamp;default:CURRENT_TIMESTAMP;comment:创建时间;NOT NULL" json:"create_time"`
|
||||
UpdateTime time.Time `gorm:"column:update_time;type:timestamp;default:CURRENT_TIMESTAMP;comment:更新时间;NOT NULL" json:"update_time"`
|
||||
}
|
||||
|
||||
func (m *FThirdCorpUserAccountDO) TableName() string {
|
||||
return "f_third_corp_user_account"
|
||||
}
|
||||
|
||||
type thirdCorpUserAccountRepositoryImpl struct {
|
||||
}
|
||||
|
||||
func (thirdCorpUserAccountRepositoryImpl) QueryPage(ctx context.Context, page, size int) *[]FThirdCorpUserAccountDO {
|
||||
db, ok := ctx.Value("db").(*gorm.DB)
|
||||
if !ok {
|
||||
db = Db
|
||||
}
|
||||
|
||||
offset := (page - 1) * size
|
||||
offset = utils.If(offset >= 0, offset, 0)
|
||||
var dataList []FThirdCorpUserAccountDO
|
||||
sqlErr := db.Model(&FThirdCorpUserAccountDO{}).Order("id DESC").Limit(size).Offset(offset).Find(&dataList).Error
|
||||
if sqlErr != nil {
|
||||
logs.NewLog("").Errorf("QueryPage_sqlErr page:%d %+v", page, sqlErr)
|
||||
return nil
|
||||
}
|
||||
|
||||
if len(dataList) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
return &dataList
|
||||
|
||||
}
|
||||
|
||||
func (thirdCorpUserAccountRepositoryImpl) FindById(ctx context.Context, id uint64) *FThirdCorpUserAccountDO {
|
||||
db, ok := ctx.Value("db").(*gorm.DB)
|
||||
if !ok {
|
||||
db = Db
|
||||
}
|
||||
|
||||
var model FThirdCorpUserAccountDO
|
||||
sqlErr := db.Where("id=?", id).First(&model).Error
|
||||
if sqlErr != nil {
|
||||
logs.NewLog("").Errorf("FindById_sqlErr id:%d %+v", id, sqlErr)
|
||||
return nil
|
||||
}
|
||||
|
||||
return &model
|
||||
}
|
||||
|
||||
func (thirdCorpUserAccountRepositoryImpl) Count(ctx context.Context) int64 {
|
||||
db, ok := ctx.Value("db").(*gorm.DB)
|
||||
if !ok {
|
||||
db = Db
|
||||
}
|
||||
|
||||
var total int64
|
||||
sqlErr := db.Model(&FThirdCorpUserAccountDO{}).Select("count(*)").First(&total).Error
|
||||
if sqlErr != nil {
|
||||
logs.NewLog("").Errorf("Count_sqlErr %+v", sqlErr)
|
||||
return 0
|
||||
}
|
||||
|
||||
return total
|
||||
}
|
||||
|
||||
func (thirdCorpUserAccountRepositoryImpl) Create(ctx context.Context, data *FThirdCorpUserAccountDO) error {
|
||||
db, ok := ctx.Value("db").(*gorm.DB)
|
||||
if !ok {
|
||||
db = Db
|
||||
}
|
||||
|
||||
//保存数据
|
||||
return db.Create(data).Error
|
||||
}
|
||||
|
||||
func (thirdCorpUserAccountRepositoryImpl) UpdateById(ctx context.Context, data FThirdCorpUserAccountDO) error {
|
||||
db, ok := ctx.Value("db").(*gorm.DB)
|
||||
if !ok {
|
||||
db = Db
|
||||
}
|
||||
|
||||
//更新数据
|
||||
return db.Updates(&data).Error
|
||||
|
||||
}
|
||||
|
||||
func (thirdCorpUserAccountRepositoryImpl) UpdateStatusById(ctx context.Context, id uint64, status int, operator string) error {
|
||||
db, ok := ctx.Value("db").(*gorm.DB)
|
||||
if !ok {
|
||||
db = Db
|
||||
}
|
||||
|
||||
data := FThirdCorpUserAccountDO{}
|
||||
sqlErr := db.Model(&data).
|
||||
Select("status").
|
||||
Where("id=?", id).
|
||||
Updates(FThirdCorpUserAccountDO{Status: status}).Error
|
||||
if sqlErr != nil {
|
||||
return sqlErr
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (thirdCorpUserAccountRepositoryImpl) deleteById(ctx context.Context, id uint64, operator string) error {
|
||||
db, ok := ctx.Value("db").(*gorm.DB)
|
||||
if !ok {
|
||||
db = Db
|
||||
}
|
||||
|
||||
data := FThirdCorpUserAccountDO{}
|
||||
sqlErr := db.Model(&data).
|
||||
Select("deleted").
|
||||
Where("id=?", id).
|
||||
Updates(FThirdCorpUserAccountDO{Deleted: 1}).Error
|
||||
if sqlErr != nil {
|
||||
return sqlErr
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (thirdCorpUserAccountRepositoryImpl) FindThirdAccountBy(ctx context.Context, bizId, corpId uint64, account string) *FThirdCorpUserAccountDO {
|
||||
db, ok := ctx.Value("db").(*gorm.DB)
|
||||
if !ok {
|
||||
db = Db
|
||||
}
|
||||
|
||||
var model FThirdCorpUserAccountDO
|
||||
sqlErr := db.Where("biz_id=? and corp_id=? And account=?", bizId, corpId, account).First(&model).Error
|
||||
if sqlErr != nil {
|
||||
logs.NewLog("").Errorf("FindThirdAccountBy_sqlErr corpId:%d account:%s %+v", corpId, account, sqlErr)
|
||||
return nil
|
||||
}
|
||||
|
||||
return &model
|
||||
}
|
@ -1,11 +0,0 @@
|
||||
package repository
|
||||
|
||||
import "context"
|
||||
|
||||
type thirdCorpUserLogRepository interface {
|
||||
QueryList(ctx context.Context, id uint64, size int) *[]FThirdCorpUserLogDO
|
||||
FindById(ctx context.Context, id uint64) *FThirdCorpUserLogDO
|
||||
Create(ctx context.Context, data *FThirdCorpUserLogDO) error
|
||||
}
|
||||
|
||||
var ThirdCorpUserLog thirdCorpUserLogRepository = new(thirdCorpUserLogRepositoryImpl)
|
@ -1,72 +0,0 @@
|
||||
package repository
|
||||
|
||||
import (
|
||||
"ai-gateway/common/logs"
|
||||
"context"
|
||||
"gorm.io/gorm"
|
||||
"time"
|
||||
)
|
||||
|
||||
// FThirdCorpUserLogDO 第三方 企业用户 日志表
|
||||
type FThirdCorpUserLogDO struct {
|
||||
Id uint64 `gorm:"column:id;type:bigint(20) unsigned;primary_key;AUTO_INCREMENT" json:"id"`
|
||||
CorpId uint64 `gorm:"column:corp_id;type:bigint(20) unsigned;comment:企业id;NOT NULL" json:"corp_id"`
|
||||
BizId int64 `gorm:"column:biz_id;type:bigint(20);comment:业务id。 " json:"biz_id"`
|
||||
CorpUid uint64 `gorm:"column:corp_uid;type:bigint(20) unsigned;comment:企业uid;NOT NULL" json:"corp_uid"`
|
||||
BizContext string `gorm:"column:biz_context;type:json;comment:业务内容 " json:"biz_context"`
|
||||
CreateTime time.Time `gorm:"column:create_time;type:timestamp;default:CURRENT_TIMESTAMP;comment:创建时间;NOT NULL" json:"create_time"`
|
||||
UpdateTime time.Time `gorm:"column:update_time;type:timestamp;default:CURRENT_TIMESTAMP;comment:更新时间;NOT NULL" json:"update_time"`
|
||||
}
|
||||
|
||||
func (m *FThirdCorpUserLogDO) TableName() string {
|
||||
return "f_third_corp_user_log"
|
||||
}
|
||||
|
||||
type thirdCorpUserLogRepositoryImpl struct {
|
||||
}
|
||||
|
||||
func (thirdCorpUserLogRepositoryImpl) QueryList(ctx context.Context, id uint64, size int) *[]FThirdCorpUserLogDO {
|
||||
db, ok := ctx.Value("db").(*gorm.DB)
|
||||
if !ok {
|
||||
db = Db
|
||||
}
|
||||
|
||||
var dataList []FThirdCorpUserLogDO
|
||||
sqlErr := db.Model(&FThirdCorpUserLogDO{}).Where("id>?", id).Order("id DESC").Limit(size).Find(&dataList).Error
|
||||
if sqlErr != nil {
|
||||
logs.NewLog("").Errorf("QueryList_sqlErr id:%d %+v", id, sqlErr)
|
||||
return nil
|
||||
}
|
||||
|
||||
if len(dataList) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
return &dataList
|
||||
}
|
||||
|
||||
func (thirdCorpUserLogRepositoryImpl) FindById(ctx context.Context, id uint64) *FThirdCorpUserLogDO {
|
||||
db, ok := ctx.Value("db").(*gorm.DB)
|
||||
if !ok {
|
||||
db = Db
|
||||
}
|
||||
|
||||
var model FThirdCorpUserLogDO
|
||||
sqlErr := db.Where("id=?", id).First(&model).Error
|
||||
if sqlErr != nil {
|
||||
logs.NewLog("").Errorf("FindById_sqlErr id:%d %+v", id, sqlErr)
|
||||
return nil
|
||||
}
|
||||
|
||||
return &model
|
||||
}
|
||||
|
||||
func (thirdCorpUserLogRepositoryImpl) Create(ctx context.Context, data *FThirdCorpUserLogDO) error {
|
||||
db, ok := ctx.Value("db").(*gorm.DB)
|
||||
if !ok {
|
||||
db = Db
|
||||
}
|
||||
|
||||
//保存数据
|
||||
return db.Create(data).Error
|
||||
}
|
@ -1,14 +0,0 @@
|
||||
package repository
|
||||
|
||||
import "context"
|
||||
|
||||
type thirdUserTokenRepository interface {
|
||||
FindByToken(ctx context.Context, token string) *FThirdUserTokenDO
|
||||
FindByBizAndCorpId(ctx context.Context, bizId, corpUid uint64) *FThirdUserTokenDO
|
||||
|
||||
SaveUserLoginToken(ctx context.Context, data *FThirdUserTokenDO) error
|
||||
|
||||
UpdateUserLoginToken(ctx context.Context, data *FThirdUserTokenDO) error
|
||||
}
|
||||
|
||||
var ThirdUserToken thirdUserTokenRepository = new(thirdUserTokenRepositoryImpl)
|
@ -3,6 +3,7 @@ package service
|
||||
import (
|
||||
"ai-gateway/common/constant"
|
||||
"ai-gateway/common/dto"
|
||||
"ai-gateway/common/email"
|
||||
"ai-gateway/common/utils"
|
||||
"ai-gateway/infrastructure/redis"
|
||||
"ai-gateway/infrastructure/repository"
|
||||
@ -13,6 +14,7 @@ import (
|
||||
"errors"
|
||||
"github.com/google/uuid"
|
||||
"github.com/labstack/echo/v4"
|
||||
"golang.org/x/time/rate"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
@ -22,12 +24,36 @@ type login struct {
|
||||
|
||||
var Login login
|
||||
|
||||
// 令牌桶大小为 100, 以每秒 10 个 Token 的速率向桶中放置 Token
|
||||
var limiter = rate.NewLimiter(10, 10)
|
||||
|
||||
// Register 注册
|
||||
func (l login) Register(ctx context.Context, req dto.ThirdRegisterReq) error {
|
||||
acUser := repository.GUser.FindByAccount(ctx, req.Account)
|
||||
if acUser != nil && acUser.Deleted == 0 {
|
||||
return errors.New("user exist")
|
||||
}
|
||||
|
||||
var user repository.AccountDO
|
||||
user.Name = req.Name
|
||||
user.Avatar = req.Icon
|
||||
|
||||
user.Email = req.Account
|
||||
//密码加密
|
||||
h := sha256.Sum256([]byte(req.Password))
|
||||
passHash := hex.EncodeToString(h[:])
|
||||
user.Pwd = passHash
|
||||
|
||||
repository.GUser.Create(ctx, &user)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (l login) Login(ctx context.Context, req dto.ThirdLoginReq) (string, error) {
|
||||
//1. 验证账号密码
|
||||
h := sha256.Sum256([]byte(req.Password))
|
||||
passHash := hex.EncodeToString(h[:])
|
||||
|
||||
acUser := repository.ThirdCorpUserAccount.FindThirdAccountBy(ctx, req.BizId, req.CorpID, req.Account)
|
||||
acUser := repository.GUser.FindByAccount(ctx, req.Account)
|
||||
if acUser == nil || acUser.Deleted == 1 {
|
||||
return "", errors.New("user not exist")
|
||||
}
|
||||
@ -38,24 +64,92 @@ func (l login) Login(ctx context.Context, req dto.ThirdLoginReq) (string, error)
|
||||
//生成token
|
||||
token := uuid.New().String()
|
||||
token = strings.ReplaceAll(token, "-", "")
|
||||
var thirdUserToken = repository.FThirdUserTokenDO{
|
||||
CorpId: req.CorpID,
|
||||
BizId: req.BizId,
|
||||
CorpUid: acUser.Id,
|
||||
var thirdUserToken = repository.GLoginToken{
|
||||
Uid: acUser.Id,
|
||||
AccessToken: token,
|
||||
ExpireTime: time.Now().Add(time.Duration(24*365*100) * time.Hour).UnixMilli(),
|
||||
}
|
||||
|
||||
loginUserToken := repository.ThirdUserToken.FindByBizAndCorpId(ctx, req.BizId, acUser.Id)
|
||||
if loginUserToken == nil {
|
||||
repository.ThirdUserToken.SaveUserLoginToken(ctx, &thirdUserToken)
|
||||
gUserToken := repository.GUserToken.FindByUid(ctx, acUser.Id)
|
||||
if gUserToken == nil {
|
||||
repository.GUserToken.SaveUserLoginToken(ctx, &thirdUserToken)
|
||||
return l.GenAccessToken(&thirdUserToken), nil
|
||||
}
|
||||
|
||||
gUserToken.AccessToken = thirdUserToken.AccessToken
|
||||
gUserToken.ExpireTime = thirdUserToken.ExpireTime
|
||||
repository.GUserToken.UpdateUserLoginToken(ctx, gUserToken)
|
||||
return l.GenAccessToken(gUserToken), nil
|
||||
}
|
||||
|
||||
func (l login) SendResetPwdCode(ctx context.Context, account string) error {
|
||||
//1. 验证账号
|
||||
acUser := repository.GUser.FindByAccount(ctx, account)
|
||||
if acUser == nil || acUser.Deleted == 1 {
|
||||
return errors.New("user not exist")
|
||||
}
|
||||
|
||||
//2. 生成code & 发送
|
||||
code := utils.GetPseudoRandomCode(6)
|
||||
|
||||
//3. save into redis
|
||||
if err := redis.Set(constant.G_RESET_PWD_CODE+account, code, time.Duration(30)*time.Minute); err != nil {
|
||||
return errors.New("cache illegal")
|
||||
}
|
||||
|
||||
//频控
|
||||
if !limiter.Allow() {
|
||||
return errors.New("rate limit, please try again later")
|
||||
}
|
||||
|
||||
//4. send code
|
||||
if err := email.SendEmailVerifyCodeByEmail(code, account); err != nil {
|
||||
return errors.New("send email code illegal")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// ResetPwd 重置密码
|
||||
func (l login) ResetPwd(ctx context.Context, req dto.ThirdResetPwdReq) error {
|
||||
//1. 验证code
|
||||
redisStr, err := redis.Get(constant.G_RESET_PWD_CODE + req.Account)
|
||||
if err != nil && redisStr != req.Code {
|
||||
return errors.New("code is error")
|
||||
}
|
||||
|
||||
//2. 查询用户
|
||||
acUser := repository.GUser.FindByAccount(ctx, req.Account)
|
||||
if acUser == nil || acUser.Deleted == 1 {
|
||||
return errors.New("user not exist")
|
||||
}
|
||||
|
||||
//3. 重置密码
|
||||
h := sha256.Sum256([]byte(req.Password))
|
||||
passHash := hex.EncodeToString(h[:])
|
||||
acUser.Pwd = passHash
|
||||
repository.GUser.UpdateById(ctx, acUser)
|
||||
|
||||
//生成token
|
||||
token := uuid.New().String()
|
||||
token = strings.ReplaceAll(token, "-", "")
|
||||
var thirdUserToken = repository.GLoginToken{
|
||||
Uid: acUser.Id,
|
||||
Platform: "web",
|
||||
AccessToken: token,
|
||||
ExpireTime: time.Now().Add(time.Duration(24*365*100) * time.Hour).UnixMilli(),
|
||||
}
|
||||
|
||||
loginUserToken := repository.GUserToken.FindByUid(ctx, acUser.Id)
|
||||
if loginUserToken == nil {
|
||||
repository.GUserToken.SaveUserLoginToken(ctx, &thirdUserToken)
|
||||
return nil
|
||||
}
|
||||
|
||||
loginUserToken.AccessToken = thirdUserToken.AccessToken
|
||||
loginUserToken.ExpireTime = thirdUserToken.ExpireTime
|
||||
repository.ThirdUserToken.UpdateUserLoginToken(ctx, loginUserToken)
|
||||
return l.GenAccessToken(loginUserToken), nil
|
||||
repository.GUserToken.UpdateUserLoginToken(ctx, loginUserToken)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (l login) GetLoginResult(ctx context.Context, c *echo.Context) *dto.ThirdUserLoginToken {
|
||||
@ -64,13 +158,8 @@ func (l login) GetLoginResult(ctx context.Context, c *echo.Context) *dto.ThirdUs
|
||||
return nil
|
||||
}
|
||||
|
||||
thirdLoginToken := l.ParseThirdUserLoginTokenByToken(accessToken)
|
||||
if thirdLoginToken == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
//redis
|
||||
redisStr, err := redis.Get(constant.THIRD_LOGIN_TOKEN + thirdLoginToken.AccessToken)
|
||||
redisStr, err := redis.Get(constant.THIRD_LOGIN_TOKEN + accessToken)
|
||||
if err != nil && redisStr != "" {
|
||||
var loginInfo dto.ThirdUserLoginToken
|
||||
if redisErr := json.Unmarshal([]byte(redisStr), &loginInfo); redisErr == nil {
|
||||
@ -79,15 +168,13 @@ func (l login) GetLoginResult(ctx context.Context, c *echo.Context) *dto.ThirdUs
|
||||
}
|
||||
|
||||
//repository
|
||||
dbData := repository.ThirdUserToken.FindByToken(ctx, thirdLoginToken.AccessToken)
|
||||
dbData := repository.GUserToken.FindByToken(ctx, accessToken)
|
||||
if dbData == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
var finalData = dto.ThirdUserLoginToken{
|
||||
CorpId: dbData.CorpId,
|
||||
BizId: dbData.BizId,
|
||||
Uid: dbData.CorpUid,
|
||||
Uid: dbData.Uid,
|
||||
AccessToken: l.GenAccessToken(dbData),
|
||||
}
|
||||
|
||||
@ -99,28 +186,6 @@ func (l login) GetLoginResult(ctx context.Context, c *echo.Context) *dto.ThirdUs
|
||||
return &finalData
|
||||
}
|
||||
|
||||
func (login) ParseThirdUserLoginTokenByToken(accessToken string) *dto.ThirdUserLoginToken {
|
||||
splits := strings.Split(accessToken, "_")
|
||||
if len(splits) != 4 {
|
||||
return nil
|
||||
}
|
||||
|
||||
return &dto.ThirdUserLoginToken{
|
||||
CorpId: utils.ToUint64(splits[0]),
|
||||
BizId: utils.ToUint64(splits[1]),
|
||||
Uid: utils.ToUint64(splits[2]),
|
||||
AccessToken: splits[3],
|
||||
}
|
||||
}
|
||||
|
||||
func (login) GenAccessToken(data *repository.FThirdUserTokenDO) string {
|
||||
var buf strings.Builder
|
||||
buf.WriteString(utils.ToString(data.CorpId))
|
||||
buf.WriteString("_")
|
||||
buf.WriteString(utils.ToString(data.BizId))
|
||||
buf.WriteString("_")
|
||||
buf.WriteString(utils.ToString(data.CorpUid))
|
||||
buf.WriteString("_")
|
||||
buf.WriteString(data.AccessToken)
|
||||
return buf.String()
|
||||
func (login) GenAccessToken(data *repository.GLoginToken) string {
|
||||
return data.AccessToken
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user