Skip to content

Commit c8f1feb

Browse files
committed
feat: user registration
1 parent f90858c commit c8f1feb

File tree

17 files changed

+601
-16
lines changed

17 files changed

+601
-16
lines changed

.github/ci/docker-compose.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ services:
2525
- "8080:8080" # 只给宿主机(ZAP)用
2626
environment:
2727
- MYSQL_PASSWORD=${MYSQL_PASSWORD}
28+
- SMTP_PASSWORD=${SMTP_PASSWORD}
29+
- SMTP_EMAIL_FROM=${SMTP_EMAIL_FROM}
2830
command: ["sh", "-c", "apt-get update && apt-get install -y netcat-openbsd && chmod +x /app/wait-for.sh && ./wait-for.sh mysql-container 3306 ./main"]
2931
volumes:
3032
- ./wait-for.sh:/app/wait-for.sh # CI 专用配置

.github/workflows/deploy.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ jobs:
5252
run: |
5353
docker stop ceramicraft-user-mservice || true
5454
docker rm ceramicraft-user-mservice || true
55-
docker run -d --name ceramicraft-user-mservice --network ceramicraft-network -e MYSQL_PASSWORD=${{ secrets.MYSQL_PASSWORD }} -p 8080:8080 "${DOCKER_HUB_USERNAME}/ceramicraft-user-mservice:${{ github.event.inputs.version }}"
55+
docker run -d --name ceramicraft-user-mservice --network ceramicraft-network -e MYSQL_PASSWORD=${{ secrets.MYSQL_PASSWORD }} -e SMTP_PASSWORD=${{ secrets.SMTP_PASSWORD }} -e SMTP_EMAIL_FROM=${{ secrets.SMTP_EMAIL_FROM }} -p 8080:8080 "${DOCKER_HUB_USERNAME}/ceramicraft-user-mservice:${{ github.event.inputs.version }}"
5656
restart:
5757
if: ${{ github.event.inputs.command == 'restart' }}
5858
runs-on: self-hosted
@@ -73,4 +73,4 @@ jobs:
7373
run: |
7474
docker stop ceramicraft-user-mservice || true
7575
docker rm ceramicraft-user-mservice || true
76-
docker run -d --name ceramicraft-user-mservice --network ceramicraft-network -p 8080:8080 "${DOCKER_HUB_USERNAME}/ceramicraft-user-mservice:${{ github.event.inputs.version }}"
76+
docker run -d --name ceramicraft-user-mservice --network ceramicraft-network -e MYSQL_PASSWORD=${{ secrets.MYSQL_PASSWORD }} -e SMTP_PASSWORD=${{ secrets.SMTP_PASSWORD }} -e SMTP_EMAIL_FROM=${{ secrets.SMTP_EMAIL_FROM }} -p 8080:8080 "${DOCKER_HUB_USERNAME}/ceramicraft-user-mservice:${{ github.event.inputs.version }}"

.github/workflows/zap.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ jobs:
2020

2121
- name: Build and run Docker Compose
2222
run: |
23-
MYSQL_PASSWORD=${{ secrets.MYSQL_PASSWORD }} docker compose -f .github/ci/docker-compose.yml up --build -d
23+
MYSQL_PASSWORD=${{ secrets.MYSQL_PASSWORD }} SMTP_PASSWORD=${{ secrets.SMTP_PASSWORD }} SMTP_EMAIL_FROM=${{ secrets.SMTP_EMAIL_FROM }} docker compose -f .github/ci/docker-compose.yml up --build -d
2424
timeout 180 bash -c 'until [ "$(docker compose -f .github/ci/docker-compose.yml ps ceramicraft-user-mservice --format json | jq -r .Health)" = "healthy" ]; do sleep 2; done'
2525
- name: Check Docker Compose Logs
2626
if: failure()

server/config/config.go

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,17 @@ var (
1111
)
1212

1313
type Conf struct {
14-
GrpcConfig *GrpcConfig `mapstructure:"grpc"`
15-
LogConfig *LogConfig `mapstructure:"log"`
16-
HttpConfig *HttpConfig `mapstructure:"http"`
17-
MySQLConfig *MySQL `mapstructure:"mysql"`
14+
GrpcConfig *GrpcConfig `mapstructure:"grpc"`
15+
LogConfig *LogConfig `mapstructure:"log"`
16+
HttpConfig *HttpConfig `mapstructure:"http"`
17+
MySQLConfig *MySQL `mapstructure:"mysql"`
18+
EmailConfig *EmailConfig `mapstructure:"email"`
19+
}
20+
21+
type EmailConfig struct {
22+
SmtpHost string `mapstructure:"smtp_host"`
23+
SmtpEmailFrom string `mapstructure:"smtp_email_from"`
24+
SmtpPass string `mapstructure:"smtp_pass"`
1825
}
1926

2027
type HttpConfig struct {
@@ -63,4 +70,6 @@ func Init() {
6370
} else {
6471
panic("MYSQL_PASSWORD environment variable is not set")
6572
}
73+
Config.EmailConfig.SmtpPass = os.Getenv("SMTP_PASSWORD")
74+
Config.EmailConfig.SmtpEmailFrom = os.Getenv("SMTP_EMAIL_FROM")
6675
}

server/docs/docs.go

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,80 @@ const docTemplate = `{
110110
}
111111
}
112112
}
113+
},
114+
"/user-ms/v1/users": {
115+
"post": {
116+
"description": "This endpoint allows a new user to register by providing their details in JSON format.",
117+
"consumes": [
118+
"application/json"
119+
],
120+
"produces": [
121+
"application/json"
122+
],
123+
"tags": [
124+
"User"
125+
],
126+
"summary": "Register a new user",
127+
"parameters": [
128+
{
129+
"description": "User registration details",
130+
"name": "user",
131+
"in": "body",
132+
"required": true,
133+
"schema": {
134+
"$ref": "#/definitions/data.UserVO"
135+
}
136+
}
137+
],
138+
"responses": {
139+
"200": {
140+
"description": "OK"
141+
},
142+
"500": {
143+
"description": "Internal Server Error",
144+
"schema": {
145+
"$ref": "#/definitions/data.BaseResponse"
146+
}
147+
}
148+
}
149+
}
150+
},
151+
"/user-ms/v1/users/activate": {
152+
"put": {
153+
"description": "This endpoint allows a new user to activate by providing their verification code in JSON format.",
154+
"consumes": [
155+
"application/json"
156+
],
157+
"produces": [
158+
"application/json"
159+
],
160+
"tags": [
161+
"User"
162+
],
163+
"summary": "Activate a new user",
164+
"parameters": [
165+
{
166+
"description": "User activate request",
167+
"name": "user",
168+
"in": "body",
169+
"required": true,
170+
"schema": {
171+
"$ref": "#/definitions/data.UserActivateReq"
172+
}
173+
}
174+
],
175+
"responses": {
176+
"200": {
177+
"description": "OK"
178+
},
179+
"500": {
180+
"description": "Internal Server Error",
181+
"schema": {
182+
"$ref": "#/definitions/data.BaseResponse"
183+
}
184+
}
185+
}
186+
}
113187
}
114188
},
115189
"definitions": {
@@ -125,8 +199,25 @@ const docTemplate = `{
125199
}
126200
}
127201
},
202+
"data.UserActivateReq": {
203+
"type": "object",
204+
"required": [
205+
"code"
206+
],
207+
"properties": {
208+
"code": {
209+
"type": "string",
210+
"maxLength": 6,
211+
"minLength": 6
212+
}
213+
}
214+
},
128215
"data.UserVO": {
129216
"type": "object",
217+
"required": [
218+
"email",
219+
"password"
220+
],
130221
"properties": {
131222
"email": {
132223
"type": "string"

server/docs/swagger.json

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,80 @@
9999
}
100100
}
101101
}
102+
},
103+
"/user-ms/v1/users": {
104+
"post": {
105+
"description": "This endpoint allows a new user to register by providing their details in JSON format.",
106+
"consumes": [
107+
"application/json"
108+
],
109+
"produces": [
110+
"application/json"
111+
],
112+
"tags": [
113+
"User"
114+
],
115+
"summary": "Register a new user",
116+
"parameters": [
117+
{
118+
"description": "User registration details",
119+
"name": "user",
120+
"in": "body",
121+
"required": true,
122+
"schema": {
123+
"$ref": "#/definitions/data.UserVO"
124+
}
125+
}
126+
],
127+
"responses": {
128+
"200": {
129+
"description": "OK"
130+
},
131+
"500": {
132+
"description": "Internal Server Error",
133+
"schema": {
134+
"$ref": "#/definitions/data.BaseResponse"
135+
}
136+
}
137+
}
138+
}
139+
},
140+
"/user-ms/v1/users/activate": {
141+
"put": {
142+
"description": "This endpoint allows a new user to activate by providing their verification code in JSON format.",
143+
"consumes": [
144+
"application/json"
145+
],
146+
"produces": [
147+
"application/json"
148+
],
149+
"tags": [
150+
"User"
151+
],
152+
"summary": "Activate a new user",
153+
"parameters": [
154+
{
155+
"description": "User activate request",
156+
"name": "user",
157+
"in": "body",
158+
"required": true,
159+
"schema": {
160+
"$ref": "#/definitions/data.UserActivateReq"
161+
}
162+
}
163+
],
164+
"responses": {
165+
"200": {
166+
"description": "OK"
167+
},
168+
"500": {
169+
"description": "Internal Server Error",
170+
"schema": {
171+
"$ref": "#/definitions/data.BaseResponse"
172+
}
173+
}
174+
}
175+
}
102176
}
103177
},
104178
"definitions": {
@@ -114,8 +188,25 @@
114188
}
115189
}
116190
},
191+
"data.UserActivateReq": {
192+
"type": "object",
193+
"required": [
194+
"code"
195+
],
196+
"properties": {
197+
"code": {
198+
"type": "string",
199+
"maxLength": 6,
200+
"minLength": 6
201+
}
202+
}
203+
},
117204
"data.UserVO": {
118205
"type": "object",
206+
"required": [
207+
"email",
208+
"password"
209+
],
119210
"properties": {
120211
"email": {
121212
"type": "string"

server/docs/swagger.yaml

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,15 @@ definitions:
77
err_msg:
88
type: string
99
type: object
10+
data.UserActivateReq:
11+
properties:
12+
code:
13+
maxLength: 6
14+
minLength: 6
15+
type: string
16+
required:
17+
- code
18+
type: object
1019
data.UserVO:
1120
properties:
1221
email:
@@ -15,6 +24,9 @@ definitions:
1524
type: integer
1625
password:
1726
type: string
27+
required:
28+
- email
29+
- password
1830
type: object
1931
info:
2032
contact: {}
@@ -74,4 +86,54 @@ paths:
7486
summary: User Logout
7587
tags:
7688
- Authentication
89+
/user-ms/v1/users:
90+
post:
91+
consumes:
92+
- application/json
93+
description: This endpoint allows a new user to register by providing their
94+
details in JSON format.
95+
parameters:
96+
- description: User registration details
97+
in: body
98+
name: user
99+
required: true
100+
schema:
101+
$ref: '#/definitions/data.UserVO'
102+
produces:
103+
- application/json
104+
responses:
105+
"200":
106+
description: OK
107+
"500":
108+
description: Internal Server Error
109+
schema:
110+
$ref: '#/definitions/data.BaseResponse'
111+
summary: Register a new user
112+
tags:
113+
- User
114+
/user-ms/v1/users/activate:
115+
put:
116+
consumes:
117+
- application/json
118+
description: This endpoint allows a new user to activate by providing their
119+
verification code in JSON format.
120+
parameters:
121+
- description: User activate request
122+
in: body
123+
name: user
124+
required: true
125+
schema:
126+
$ref: '#/definitions/data.UserActivateReq'
127+
produces:
128+
- application/json
129+
responses:
130+
"200":
131+
description: OK
132+
"500":
133+
description: Internal Server Error
134+
schema:
135+
$ref: '#/definitions/data.BaseResponse'
136+
summary: Activate a new user
137+
tags:
138+
- User
77139
swagger: "2.0"

server/go.mod

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,5 +87,7 @@ require (
8787
golang.org/x/tools v0.37.0 // indirect
8888
google.golang.org/genproto/googleapis/rpc v0.0.0-20250707201910-8d1bb00bc6a7 // indirect
8989
google.golang.org/protobuf v1.36.9 // indirect
90+
gopkg.in/alexcesaro/quotedprintable.v3 v3.0.0-20150716171945-2caba252f4dc // indirect
91+
gopkg.in/mail.v2 v2.3.1 // indirect
9092
gopkg.in/yaml.v3 v3.0.1 // indirect
9193
)

server/go.sum

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,9 +232,13 @@ google.golang.org/grpc v1.75.1 h1:/ODCNEuf9VghjgO3rqLcfg8fiOP0nSluljWFlDxELLI=
232232
google.golang.org/grpc v1.75.1/go.mod h1:JtPAzKiq4v1xcAB2hydNlWI2RnF85XXcV0mhKXr2ecQ=
233233
google.golang.org/protobuf v1.36.9 h1:w2gp2mA27hUeUzj9Ex9FBjsBm40zfaDtEWow293U7Iw=
234234
google.golang.org/protobuf v1.36.9/go.mod h1:fuxRtAxBytpl4zzqUh6/eyUujkJdNiuEkXntxiD/uRU=
235+
gopkg.in/alexcesaro/quotedprintable.v3 v3.0.0-20150716171945-2caba252f4dc h1:2gGKlE2+asNV9m7xrywl36YYNnBG5ZQ0r/BOOxqPpmk=
236+
gopkg.in/alexcesaro/quotedprintable.v3 v3.0.0-20150716171945-2caba252f4dc/go.mod h1:m7x9LTH6d71AHyAX77c9yqWCCa3UKHcVEj9y7hAtKDk=
235237
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
236238
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
237239
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
240+
gopkg.in/mail.v2 v2.3.1 h1:WYFn/oANrAGP2C0dcV6/pbkPzv8yGzqTjPmTeO7qoXk=
241+
gopkg.in/mail.v2 v2.3.1/go.mod h1:htwXN1Qh09vZJ1NVKxQqHPBaCBbzKhp5GzuJEA4VJWw=
238242
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
239243
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
240244
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

0 commit comments

Comments
 (0)