add verify google auth result

This commit is contained in:
daniel.w 2024-08-24 14:46:26 +08:00
parent 575931f210
commit 5d55ba14a3
13 changed files with 122 additions and 48 deletions

View File

@ -167,6 +167,17 @@ message ListUserInfoResp {
Pager page =2; Pager page =2;
} }
message VerifyAuthResultReq {
string token = 1;
}
message VerifyAuthResultResp {
bool status = 1;
}
message TwitterAccessTokenResp {
string token = 1;
}
service Account { service Account {
// CreateUserAccount -> // CreateUserAccount ->
@ -193,6 +204,7 @@ service Account {
rpc GenerateRefreshCode(GenerateRefreshCodeReq) returns(GenerateRefreshCodeResp); rpc GenerateRefreshCode(GenerateRefreshCodeReq) returns(GenerateRefreshCodeResp);
// VerifyRefreshCode token // VerifyRefreshCode token
rpc VerifyRefreshCode(VerifyRefreshCodeReq) returns(OKResp); rpc VerifyRefreshCode(VerifyRefreshCodeReq) returns(OKResp);
// VerifyGoogleAuthResult google
rpc VerifyGoogleAuthResult(VerifyAuthResultReq)returns(VerifyAuthResultResp);
} }
// ================ account ================ // ================ account ================

18
go.mod
View File

@ -13,7 +13,7 @@ require (
go.mongodb.org/mongo-driver v1.16.0 go.mongodb.org/mongo-driver v1.16.0
go.uber.org/goleak v1.3.0 go.uber.org/goleak v1.3.0
go.uber.org/mock v0.4.0 go.uber.org/mock v0.4.0
golang.org/x/crypto v0.25.0 golang.org/x/crypto v0.26.0
google.golang.org/grpc v1.65.0 google.golang.org/grpc v1.65.0
google.golang.org/protobuf v1.34.2 google.golang.org/protobuf v1.34.2
) )
@ -91,15 +91,15 @@ require (
go.uber.org/automaxprocs v1.5.3 // indirect go.uber.org/automaxprocs v1.5.3 // indirect
go.uber.org/multierr v1.9.0 // indirect go.uber.org/multierr v1.9.0 // indirect
go.uber.org/zap v1.24.0 // indirect go.uber.org/zap v1.24.0 // indirect
golang.org/x/net v0.27.0 // indirect golang.org/x/net v0.28.0 // indirect
golang.org/x/oauth2 v0.20.0 // indirect golang.org/x/oauth2 v0.22.0 // indirect
golang.org/x/sync v0.7.0 // indirect golang.org/x/sync v0.8.0 // indirect
golang.org/x/sys v0.22.0 // indirect golang.org/x/sys v0.24.0 // indirect
golang.org/x/term v0.22.0 // indirect golang.org/x/term v0.23.0 // indirect
golang.org/x/text v0.16.0 // indirect golang.org/x/text v0.17.0 // indirect
golang.org/x/time v0.5.0 // indirect golang.org/x/time v0.6.0 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20240711142825-46eb208f015d // indirect google.golang.org/genproto/googleapis/api v0.0.0-20240711142825-46eb208f015d // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240701130421-f6361c86f094 // indirect google.golang.org/genproto/googleapis/rpc v0.0.0-20240814211410-ddb44dafa142 // indirect
gopkg.in/inf.v0 v0.9.1 // indirect gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect

36
go.sum
View File

@ -228,8 +228,8 @@ golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8U
golang.org/x/crypto v0.0.0-20200302210943-78000ba7a073/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/crypto v0.0.0-20200302210943-78000ba7a073/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
golang.org/x/crypto v0.25.0 h1:ypSNr+bnYL2YhwoMt2zPxHFmbAN1KZs/njMG3hxUp30= golang.org/x/crypto v0.26.0 h1:RrRspgV4mU+YwB4FYnuBoKsUapNIL5cohGAmSH3azsw=
golang.org/x/crypto v0.25.0/go.mod h1:T+wALwcMOSE0kXgUAnPAHqTLW+XHgcELELW8VaDgm/M= golang.org/x/crypto v0.26.0/go.mod h1:GY7jblb9wI+FOo5y8/S2oY4zWP07AkOJ4+jxCqdqn54=
golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
@ -241,17 +241,17 @@ golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwY
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96bSt6lcn1PtDYWL6XObtHCRCNQM= golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96bSt6lcn1PtDYWL6XObtHCRCNQM=
golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c= golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c=
golang.org/x/net v0.27.0 h1:5K3Njcw06/l2y9vpGCSdcxWOYHOUk3dVNGDXN+FvAys= golang.org/x/net v0.28.0 h1:a9JDOJc5GMUJ0+UDqmLT86WiEy7iWyIhz8gz8E4e5hE=
golang.org/x/net v0.27.0/go.mod h1:dDi0PyhWNoiUOrAS8uXv/vnScO4wnHQO4mj9fn/RytE= golang.org/x/net v0.28.0/go.mod h1:yqtgsTWOOnlGLG9GFRrK3++bGOUEkNBoHZc8MEDWPNg=
golang.org/x/oauth2 v0.20.0 h1:4mQdhULixXKP1rwYBW0vAijoXnkTG0BLCDRzfe1idMo= golang.org/x/oauth2 v0.22.0 h1:BzDx2FehcG7jJwgWLELCdmLuxk2i+x9UDpSiss2u0ZA=
golang.org/x/oauth2 v0.20.0/go.mod h1:XYTD2NtWslqkgxebSiOHnXEap4TF09sJSc7H1sXbhtI= golang.org/x/oauth2 v0.22.0/go.mod h1:XYTD2NtWslqkgxebSiOHnXEap4TF09sJSc7H1sXbhtI=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.7.0 h1:YsImfSBoP9QPYL0xyKJPq0gcaJdG3rInoqxTWbfQu9M= golang.org/x/sync v0.8.0 h1:3NFvSEYkUoMifnESzZl15y791HH1qU2xm6eCJU5ZPXQ=
golang.org/x/sync v0.7.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= golang.org/x/sync v0.8.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
@ -263,20 +263,20 @@ golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBc
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.22.0 h1:RI27ohtqKCnwULzJLqkv897zojh5/DwS/ENaMzUOaWI= golang.org/x/sys v0.24.0 h1:Twjiwq9dn6R1fQcyiK+wQyHWfaz/BJB+YIpzU/Cv3Xg=
golang.org/x/sys v0.22.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/sys v0.24.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
golang.org/x/term v0.22.0 h1:BbsgPEJULsl2fV/AT3v15Mjva5yXKQDyKf+TbDz7QJk= golang.org/x/term v0.23.0 h1:F6D4vR+EHoL9/sWAWgAR1H2DcHr4PareCbAaCo1RpuU=
golang.org/x/term v0.22.0/go.mod h1:F3qCibpT5AMpCRfhfT53vVJwhLtIVHhB9XDjfFvnMI4= golang.org/x/term v0.23.0/go.mod h1:DgV24QBUrK6jhZXl+20l6UWznPlwAHm1Q1mGHtydmSk=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
golang.org/x/text v0.3.8/go.mod h1:E6s5w1FMmriuDzIBO73fBruAKo1PCIq6d2Q6DHfQ8WQ= golang.org/x/text v0.3.8/go.mod h1:E6s5w1FMmriuDzIBO73fBruAKo1PCIq6d2Q6DHfQ8WQ=
golang.org/x/text v0.16.0 h1:a94ExnEXNtEwYLGJSIUxnWoxoRz/ZcCsV63ROupILh4= golang.org/x/text v0.17.0 h1:XtiM5bkSOt+ewxlOE/aE/AKEHibwj/6gvWMl9Rsh0Qc=
golang.org/x/text v0.16.0/go.mod h1:GhwF1Be+LQoKShO3cGOHzqOgRrGaYc9AvblQOmPVHnI= golang.org/x/text v0.17.0/go.mod h1:BuEKDfySbSR4drPmRPG/7iBdf8hvFMuRexcpahXilzY=
golang.org/x/time v0.5.0 h1:o7cqy6amK/52YcAKIPlM3a+Fpj35zvRj2TP+e1xFSfk= golang.org/x/time v0.6.0 h1:eTDhh4ZXt5Qf0augr54TN6suAUudPcawVZeIAPU7D4U=
golang.org/x/time v0.5.0/go.mod h1:3BpzKBy/shNhVucY/MWOyx10tF3SFh9QdLuxbVysPQM= golang.org/x/time v0.6.0/go.mod h1:3BpzKBy/shNhVucY/MWOyx10tF3SFh9QdLuxbVysPQM=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/tools v0.0.0-20200619180055-7c47624df98f/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE= golang.org/x/tools v0.0.0-20200619180055-7c47624df98f/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE=
@ -291,8 +291,8 @@ golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8T
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
google.golang.org/genproto/googleapis/api v0.0.0-20240711142825-46eb208f015d h1:kHjw/5UfflP/L5EbledDrcG4C2597RtymmGRZvHiCuY= google.golang.org/genproto/googleapis/api v0.0.0-20240711142825-46eb208f015d h1:kHjw/5UfflP/L5EbledDrcG4C2597RtymmGRZvHiCuY=
google.golang.org/genproto/googleapis/api v0.0.0-20240711142825-46eb208f015d/go.mod h1:mw8MG/Qz5wfgYr6VqVCiZcHe/GJEfI+oGGDCohaVgB0= google.golang.org/genproto/googleapis/api v0.0.0-20240711142825-46eb208f015d/go.mod h1:mw8MG/Qz5wfgYr6VqVCiZcHe/GJEfI+oGGDCohaVgB0=
google.golang.org/genproto/googleapis/rpc v0.0.0-20240701130421-f6361c86f094 h1:BwIjyKYGsK9dMCBOorzRri8MQwmi7mT9rGHsCEinZkA= google.golang.org/genproto/googleapis/rpc v0.0.0-20240814211410-ddb44dafa142 h1:e7S5W7MGGLaSu8j3YjdezkZ+m1/Nm0uRVRMEMGk26Xs=
google.golang.org/genproto/googleapis/rpc v0.0.0-20240701130421-f6361c86f094/go.mod h1:Ue6ibwXGpU+dqIcODieyLOcgj7z8+IcskoNIgZxtrFY= google.golang.org/genproto/googleapis/rpc v0.0.0-20240814211410-ddb44dafa142/go.mod h1:UqMtugtsSgubUsoxbuAoiCXvqvErP7Gf0so0mK9tHxU=
google.golang.org/grpc v1.65.0 h1:bs/cUb4lp1G5iImFFd3u5ixQzweKizoZJAwBNLR42lc= google.golang.org/grpc v1.65.0 h1:bs/cUb4lp1G5iImFFd3u5ixQzweKizoZJAwBNLR42lc=
google.golang.org/grpc v1.65.0/go.mod h1:WgYC2ypjlB0EiQi6wdKixMqukr6lBc0Vo+oOgjrM5ZQ= google.golang.org/grpc v1.65.0/go.mod h1:WgYC2ypjlB0EiQi6wdKixMqukr6lBc0Vo+oOgjrM5ZQ=
google.golang.org/protobuf v1.34.2 h1:6xV6lTsCfpGD21XK49h7MhtcApnLqkfYgPcdHftf6hg= google.golang.org/protobuf v1.34.2 h1:6xV6lTsCfpGD21XK49h7MhtcApnLqkfYgPcdHftf6hg=

View File

@ -30,4 +30,9 @@ type Config struct {
Database string Database string
Collection string Collection string
} }
GoogleAuth struct {
ClientID string
VerifyURL string
}
} }

View File

@ -1,5 +1,7 @@
package domain package domain
import "time"
const ( const (
DefaultPageSize = 100 DefaultPageSize = 100
DefaultPageIndex = 1 DefaultPageIndex = 1
@ -28,3 +30,12 @@ const (
AccountTypeMail AccountType = 2 AccountTypeMail AccountType = 2
AccountTypeAccount AccountType = 3 AccountTypeAccount AccountType = 3
) )
const (
DefaultSingleFlyCacheTimeout = 24 * time.Hour
DefaultFindDataNotFoundTimeout = 30 * time.Second
)
const (
AppName = "app-cloudep-member-service"
)

View File

@ -44,13 +44,6 @@ type createUserInfoReq struct {
Uid string `validate:"required"` // 唯一辨識碼 Uid string `validate:"required"` // 唯一辨識碼
Language string `validate:"required"` Language string `validate:"required"`
Currency string `validate:"required"` Currency string `validate:"required"`
// VerifyType int32 `validate:"required,oneof=0 1 2 3 4"` // 驗證類型 0. 異常 [ 1.信箱 2.手機 3. GA 4. 關閉] 兩步驟驗證狀態
// AlarmType int32 `validate:"required,oneof=0 1 2"` // 告警狀態 0. 異常 1. 正常(未告警) 2.系統告警中
// Status int32 `validate:"required,oneof=1 2 3 4 5"` // 會員狀態 0. 異常 1. 尚未驗證 2. 啟用 3. 停權中 4. 信箱以驗證 5. 手機以驗證
// Language string
// Currency string
// NickName string
// Avatar string // 會員頭像
} }
// BindUserInfo 初次,綁定 User Info // BindUserInfo 初次,綁定 User Info

View File

@ -51,8 +51,6 @@ func (l *CreateUserAccountLogic) CreateUserAccount(in *member.CreateLoginUserReq
return nil, ers.InvalidFormat(err.Error()) return nil, ers.InvalidFormat(err.Error())
} }
// TODO 檢查平台,依照不同平台,做不同的事
token, err := HasPasswordFunc(in.GetToken(), l.svcCtx.Config.Bcrypt.Cost) token, err := HasPasswordFunc(in.GetToken(), l.svcCtx.Config.Bcrypt.Cost)
if err != nil { if err != nil {
return nil, ers.ArkInternal(fmt.Sprintf("failed to encrypt err: %v", err.Error())) return nil, ers.ArkInternal(fmt.Sprintf("failed to encrypt err: %v", err.Error()))

View File

@ -1,7 +1,10 @@
package accountlogic package accountlogic
import ( import (
"app-cloudep-member-server/internal/domain"
"context" "context"
"errors"
"github.com/zeromicro/go-zero/core/stores/sqlx"
ers "code.30cm.net/digimon/library-go/errors" ers "code.30cm.net/digimon/library-go/errors"
@ -40,7 +43,17 @@ func (l *GetUidByAccountLogic) GetUidByAccount(in *member.GetUIDByAccountReq) (*
account, err := l.svcCtx.AccountToUidModel.FindOneByAccount(l.ctx, in.GetAccount()) account, err := l.svcCtx.AccountToUidModel.FindOneByAccount(l.ctx, in.GetAccount())
if err != nil { if err != nil {
return nil, err if errors.As(err, &sqlx.ErrNotFound) {
return nil, ers.ResourceNotFound(in.GetAccount())
}
logx.WithCallerSkip(1).WithFields(
logx.Field("app", domain.AppName),
logx.Field("func", "VerifyGoogleToken"),
logx.Field("req", in),
).Error(err.Error())
return nil, ers.DBError(err.Error())
} }
return &member.GetUidByAccountResp{ return &member.GetUidByAccountResp{

View File

@ -1,9 +1,10 @@
package accountlogic package accountlogic
import ( import (
"context"
ers "code.30cm.net/digimon/library-go/errors" ers "code.30cm.net/digimon/library-go/errors"
"context"
"errors"
"github.com/zeromicro/go-zero/core/stores/sqlx"
"app-cloudep-member-server/gen_result/pb/member" "app-cloudep-member-server/gen_result/pb/member"
"app-cloudep-member-server/internal/svc" "app-cloudep-member-server/internal/svc"
@ -40,6 +41,9 @@ func (l *GetUserAccountInfoLogic) GetUserAccountInfo(in *member.GetUIDByAccountR
account, err := l.svcCtx.AccountModel.FindOneByAccount(l.ctx, in.GetAccount()) account, err := l.svcCtx.AccountModel.FindOneByAccount(l.ctx, in.GetAccount())
if err != nil { if err != nil {
if errors.As(err, &sqlx.ErrNotFound) {
return nil, ers.ResourceNotFound(in.GetAccount())
}
return nil, ers.DBError(err.Error()) return nil, ers.DBError(err.Error())
} }

View File

@ -1,9 +1,12 @@
package accountlogic package accountlogic
import ( import (
"app-cloudep-member-server/internal/domain"
"app-cloudep-member-server/internal/utils" "app-cloudep-member-server/internal/utils"
"context" "context"
"errors"
"fmt" "fmt"
"github.com/zeromicro/go-zero/core/stores/sqlx"
ers "code.30cm.net/digimon/library-go/errors" ers "code.30cm.net/digimon/library-go/errors"
@ -51,6 +54,16 @@ func (l *UpdateUserTokenLogic) UpdateUserToken(in *member.UpdateTokenReq) (*memb
err = l.svcCtx.AccountModel.UpdateTokenByLoginID(l.ctx, in.GetAccount(), token) err = l.svcCtx.AccountModel.UpdateTokenByLoginID(l.ctx, in.GetAccount(), token)
if err != nil { if err != nil {
if errors.As(err, &sqlx.ErrNotFound) {
return nil, ers.ResourceNotFound(in.GetAccount())
}
logx.WithCallerSkip(1).WithFields(
logx.Field("app", domain.AppName),
logx.Field("func", "VerifyGoogleToken"),
logx.Field("req", in),
).Error(err.Error())
return nil, ers.DBError(err.Error()) return nil, ers.DBError(err.Error())
} }

View File

@ -1,6 +1,7 @@
package accountlogic package accountlogic
import ( import (
"app-cloudep-member-server/internal/domain"
"context" "context"
"fmt" "fmt"
@ -43,6 +44,11 @@ func (l *VerifyRefreshCodeLogic) VerifyRefreshCode(in *member.VerifyRefreshCodeR
rk := fmt.Sprintf("verify:%s:%s", checkType, in.GetAccount()) rk := fmt.Sprintf("verify:%s:%s", checkType, in.GetAccount())
get, err := l.svcCtx.Redis.Get(rk) get, err := l.svcCtx.Redis.Get(rk)
if err != nil { if err != nil {
logx.WithCallerSkip(1).WithFields(
logx.Field("app", domain.AppName),
logx.Field("func", "Redis.Get"),
logx.Field("req", in),
).Error(err.Error())
return nil, ers.DBError("failed to connect to redis", err.Error()) return nil, ers.DBError("failed to connect to redis", err.Error())
} }
@ -56,6 +62,11 @@ func (l *VerifyRefreshCodeLogic) VerifyRefreshCode(in *member.VerifyRefreshCodeR
_, err = l.svcCtx.Redis.Del(rk) _, err = l.svcCtx.Redis.Del(rk)
if err != nil { if err != nil {
logx.WithCallerSkip(1).WithFields(
logx.Field("app", domain.AppName),
logx.Field("func", "Redis.Del"),
logx.Field("key", rk),
).Error(err.Error())
return nil, ers.DBError("failed to del redis key", rk) return nil, ers.DBError("failed to del redis key", rk)
} }

View File

@ -93,3 +93,9 @@ func (s *AccountServer) VerifyRefreshCode(ctx context.Context, in *member.Verify
l := accountlogic.NewVerifyRefreshCodeLogic(ctx, s.svcCtx) l := accountlogic.NewVerifyRefreshCodeLogic(ctx, s.svcCtx)
return l.VerifyRefreshCode(in) return l.VerifyRefreshCode(in)
} }
// VerifyGoogleAuthResult 驗證 google 登入是否有效
func (s *AccountServer) VerifyGoogleAuthResult(ctx context.Context, in *member.VerifyAuthResultReq) (*member.VerifyAuthResultResp, error) {
l := accountlogic.NewVerifyGoogleAuthResultLogic(ctx, s.svcCtx)
return l.VerifyGoogleAuthResult(in)
}

View File

@ -7,10 +7,10 @@ import (
"app-cloudep-member-server/internal/model" "app-cloudep-member-server/internal/model"
mgo "app-cloudep-member-server/internal/model/mongo" mgo "app-cloudep-member-server/internal/model/mongo"
"app-cloudep-member-server/internal/usecase" "app-cloudep-member-server/internal/usecase"
"fmt"
ers "code.30cm.net/digimon/library-go/errors" ers "code.30cm.net/digimon/library-go/errors"
vi "code.30cm.net/digimon/library-go/validator" vi "code.30cm.net/digimon/library-go/validator"
"fmt"
"github.com/zeromicro/go-zero/core/stores/cache"
"github.com/zeromicro/go-zero/core/stores/redis" "github.com/zeromicro/go-zero/core/stores/redis"
"github.com/zeromicro/go-zero/core/stores/sqlx" "github.com/zeromicro/go-zero/core/stores/sqlx"
) )
@ -30,6 +30,7 @@ func NewServiceContext(c config.Config) *ServiceContext {
// 設置 // 設置
ers.Scope = domain.Scope ers.Scope = domain.Scope
// TODO 可優化項目,將連線數量以及 timeout 都便可設定
sqlConn := sqlx.NewMysql(c.DB.DsnString) sqlConn := sqlx.NewMysql(c.DB.DsnString)
newRedis, err := redis.NewRedis(c.RedisCluster, redis.Cluster()) newRedis, err := redis.NewRedis(c.RedisCluster, redis.Cluster())
if err != nil { if err != nil {
@ -46,9 +47,16 @@ func NewServiceContext(c config.Config) *ServiceContext {
Config: c, Config: c,
Validate: vi.MustValidator(vi.WithAccount("account")), Validate: vi.MustValidator(vi.WithAccount("account")),
Redis: *newRedis, Redis: *newRedis,
UserModel: model.NewUserTableModel(sqlConn, c.Cache), UserModel: model.NewUserTableModel(sqlConn, c.Cache,
AccountToUidModel: model.NewAccountToUidModel(sqlConn, c.Cache), cache.WithExpiry(domain.DefaultSingleFlyCacheTimeout),
AccountModel: model.NewAccountModel(sqlConn, c.Cache), cache.WithNotFoundExpiry(domain.DefaultFindDataNotFoundTimeout)),
AccountToUidModel: model.NewAccountToUidModel(sqlConn, c.Cache,
cache.WithExpiry(domain.DefaultSingleFlyCacheTimeout),
cache.WithNotFoundExpiry(domain.DefaultFindDataNotFoundTimeout)),
AccountModel: model.NewAccountModel(sqlConn, c.Cache,
cache.WithExpiry(domain.DefaultSingleFlyCacheTimeout),
cache.WithNotFoundExpiry(domain.DefaultFindDataNotFoundTimeout),
),
GenUIDUseCase: usecase.MustGenerateUseCase(usecase.GenerateUseCaseParam{ GenUIDUseCase: usecase.MustGenerateUseCase(usecase.GenerateUseCaseParam{
GenerateUIDRepo: mongo, GenerateUIDRepo: mongo,
}), }),