Compare commits
4 Commits
ed7232e5c0
...
b5d177910c
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b5d177910c | ||
|
|
7df6587fd6 | ||
|
|
94988790f8 | ||
|
|
45dcef5702 |
@@ -100,15 +100,9 @@ func (h *UserEndpoint) GetUserInfo(ctx *gin.Context) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
status := 0
|
|
||||||
if user.ID > 0 {
|
|
||||||
status = 1
|
|
||||||
}
|
|
||||||
|
|
||||||
ctx.JSON(http.StatusOK, common.SuccessResponse(ctx, model.UserInfoResponse{
|
ctx.JSON(http.StatusOK, common.SuccessResponse(ctx, model.UserInfoResponse{
|
||||||
Username: user.Username,
|
Username: user.Username,
|
||||||
Phone: user.Phone,
|
Email: user.Email,
|
||||||
Status: status,
|
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -26,6 +26,7 @@ type GoogleOAuthConfig struct {
|
|||||||
ClientID string `mapstructure:"client_id"`
|
ClientID string `mapstructure:"client_id"`
|
||||||
ClientSecret string `mapstructure:"client_secret"`
|
ClientSecret string `mapstructure:"client_secret"`
|
||||||
RedirectURI string `mapstructure:"redirect_uri"`
|
RedirectURI string `mapstructure:"redirect_uri"`
|
||||||
|
Proxy string `mapstructure:"proxy"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type MathpixConfig struct {
|
type MathpixConfig struct {
|
||||||
|
|||||||
@@ -4,8 +4,8 @@ server:
|
|||||||
|
|
||||||
database:
|
database:
|
||||||
driver: mysql
|
driver: mysql
|
||||||
host: mysql
|
host: localhost
|
||||||
port: 3306
|
port: 3006
|
||||||
username: root
|
username: root
|
||||||
password: texpixel#pwd123!
|
password: texpixel#pwd123!
|
||||||
dbname: doc_ai
|
dbname: doc_ai
|
||||||
@@ -13,7 +13,7 @@ database:
|
|||||||
max_open: 100
|
max_open: 100
|
||||||
|
|
||||||
redis:
|
redis:
|
||||||
addr: redis:6379
|
addr: localhost:6079
|
||||||
password: yoge@123321!
|
password: yoge@123321!
|
||||||
db: 0
|
db: 0
|
||||||
|
|
||||||
@@ -52,6 +52,7 @@ baidu_ocr:
|
|||||||
token: "e3a47bd2438f1f38840c203fc5939d17a54482d1"
|
token: "e3a47bd2438f1f38840c203fc5939d17a54482d1"
|
||||||
|
|
||||||
google:
|
google:
|
||||||
client_id: ""
|
client_id: "404402221037-nqdsk11bkpk5a7oh396mrg1ieh28u6q1.apps.googleusercontent.com"
|
||||||
client_secret: ""
|
client_secret: "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"
|
||||||
redirect_uri: "http://localhost:5173/auth/callback"
|
redirect_uri: "https://app.cloud.texpixel.com:10443/auth/google/callback"
|
||||||
|
proxy: "http://localhost:7890"
|
||||||
|
|||||||
@@ -50,3 +50,9 @@ mathpix:
|
|||||||
|
|
||||||
baidu_ocr:
|
baidu_ocr:
|
||||||
token: "e3a47bd2438f1f38840c203fc5939d17a54482d1"
|
token: "e3a47bd2438f1f38840c203fc5939d17a54482d1"
|
||||||
|
|
||||||
|
google:
|
||||||
|
client_id: "404402221037-nqdsk11bkpk5a7oh396mrg1ieh28u6q1.apps.googleusercontent.com"
|
||||||
|
client_secret: "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"
|
||||||
|
redirect_uri: "https://texpixel.com/auth/google/callback"
|
||||||
|
proxy: "http://100.115.184.74:7890"
|
||||||
|
|||||||
@@ -6,7 +6,8 @@ ssh ubuntu << 'ENDSSH'
|
|||||||
cd /home/yoge/Dev/doc_ai_backed
|
cd /home/yoge/Dev/doc_ai_backed
|
||||||
git checkout test
|
git checkout test
|
||||||
git pull origin test
|
git pull origin test
|
||||||
docker compose down
|
docker compose -f docker-compose.infra.yml up -d
|
||||||
|
docker compose down
|
||||||
docker image rm doc_ai_backed-doc_ai:latest
|
docker image rm doc_ai_backed-doc_ai:latest
|
||||||
docker compose -f docker-compose.yml up -d
|
docker compose up -d
|
||||||
ENDSSH
|
ENDSSH
|
||||||
32
docker-compose.infra.yml
Normal file
32
docker-compose.infra.yml
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
services:
|
||||||
|
mysql:
|
||||||
|
image: mysql:8.0
|
||||||
|
container_name: mysql
|
||||||
|
environment:
|
||||||
|
MYSQL_ROOT_PASSWORD: texpixel#pwd123!
|
||||||
|
MYSQL_DATABASE: doc_ai
|
||||||
|
MYSQL_USER: texpixel
|
||||||
|
MYSQL_PASSWORD: texpixel#pwd123!
|
||||||
|
ports:
|
||||||
|
- "3006:3306"
|
||||||
|
volumes:
|
||||||
|
- mysql_data:/var/lib/mysql
|
||||||
|
healthcheck:
|
||||||
|
test: ["CMD", "mysqladmin", "ping", "-h", "localhost", "-uroot", "-ptexpixel#pwd123!"]
|
||||||
|
interval: 5s
|
||||||
|
timeout: 5s
|
||||||
|
retries: 10
|
||||||
|
start_period: 30s
|
||||||
|
restart: always
|
||||||
|
|
||||||
|
redis:
|
||||||
|
image: redis:latest
|
||||||
|
container_name: redis
|
||||||
|
command: redis-server --requirepass "yoge@123321!"
|
||||||
|
ports:
|
||||||
|
- "6079:6379"
|
||||||
|
restart: always
|
||||||
|
|
||||||
|
volumes:
|
||||||
|
mysql_data:
|
||||||
|
driver: local
|
||||||
@@ -2,58 +2,9 @@ services:
|
|||||||
doc_ai:
|
doc_ai:
|
||||||
build: .
|
build: .
|
||||||
container_name: doc_ai
|
container_name: doc_ai
|
||||||
ports:
|
network_mode: host
|
||||||
- "8024:8024"
|
|
||||||
volumes:
|
volumes:
|
||||||
- ./config:/app/config
|
- ./config:/app/config
|
||||||
- ./logs:/app/logs
|
- ./logs:/app/logs
|
||||||
networks:
|
|
||||||
- backend
|
|
||||||
depends_on:
|
|
||||||
mysql:
|
|
||||||
condition: service_healthy
|
|
||||||
redis:
|
|
||||||
condition: service_started
|
|
||||||
command: ["-env", "dev"]
|
command: ["-env", "dev"]
|
||||||
restart: always
|
restart: always
|
||||||
|
|
||||||
mysql:
|
|
||||||
image: mysql:8.0
|
|
||||||
container_name: mysql
|
|
||||||
environment:
|
|
||||||
MYSQL_ROOT_PASSWORD: texpixel#pwd123!
|
|
||||||
MYSQL_DATABASE: doc_ai
|
|
||||||
MYSQL_USER: texpixel
|
|
||||||
MYSQL_PASSWORD: texpixel#pwd123!
|
|
||||||
ports:
|
|
||||||
- "3006:3306"
|
|
||||||
volumes:
|
|
||||||
- mysql_data:/var/lib/mysql
|
|
||||||
networks:
|
|
||||||
- backend
|
|
||||||
healthcheck:
|
|
||||||
test: ["CMD", "mysqladmin", "ping", "-h", "localhost", "-uroot", "-ptexpixel#pwd123!"]
|
|
||||||
interval: 5s
|
|
||||||
timeout: 5s
|
|
||||||
retries: 10
|
|
||||||
start_period: 30s
|
|
||||||
restart: always
|
|
||||||
|
|
||||||
redis:
|
|
||||||
image: redis:latest
|
|
||||||
container_name: redis
|
|
||||||
command: redis-server --requirepass "yoge@123321!"
|
|
||||||
ports:
|
|
||||||
- "6079:6379"
|
|
||||||
networks:
|
|
||||||
- backend
|
|
||||||
restart: always
|
|
||||||
|
|
||||||
volumes:
|
|
||||||
mysql_data:
|
|
||||||
# 持久化MySQL数据卷
|
|
||||||
driver: local
|
|
||||||
|
|
||||||
networks:
|
|
||||||
backend:
|
|
||||||
driver: bridge
|
|
||||||
|
|||||||
@@ -20,8 +20,7 @@ type PhoneLoginResponse struct {
|
|||||||
|
|
||||||
type UserInfoResponse struct {
|
type UserInfoResponse struct {
|
||||||
Username string `json:"username"`
|
Username string `json:"username"`
|
||||||
Phone string `json:"phone"`
|
Email string `json:"email"`
|
||||||
Status int `json:"status"` // 0: not login, 1: login
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type EmailRegisterRequest struct {
|
type EmailRegisterRequest struct {
|
||||||
|
|||||||
@@ -9,7 +9,8 @@ import (
|
|||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
|
|
||||||
"gitea.com/texpixel/document_ai/internal/model/user"
|
"gitea.com/texpixel/document_ai/config"
|
||||||
|
model "gitea.com/texpixel/document_ai/internal/model/user"
|
||||||
"gitea.com/texpixel/document_ai/internal/storage/cache"
|
"gitea.com/texpixel/document_ai/internal/storage/cache"
|
||||||
"gitea.com/texpixel/document_ai/internal/storage/dao"
|
"gitea.com/texpixel/document_ai/internal/storage/dao"
|
||||||
"gitea.com/texpixel/document_ai/pkg/common"
|
"gitea.com/texpixel/document_ai/pkg/common"
|
||||||
@@ -171,6 +172,17 @@ type googleTokenResponse struct {
|
|||||||
TokenType string `json:"token_type"`
|
TokenType string `json:"token_type"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (svc *UserService) googleHTTPClient() *http.Client {
|
||||||
|
if config.GlobalConfig.Google.Proxy == "" {
|
||||||
|
return &http.Client{}
|
||||||
|
}
|
||||||
|
proxyURL, err := url.Parse(config.GlobalConfig.Google.Proxy)
|
||||||
|
if err != nil {
|
||||||
|
return &http.Client{}
|
||||||
|
}
|
||||||
|
return &http.Client{Transport: &http.Transport{Proxy: http.ProxyURL(proxyURL)}}
|
||||||
|
}
|
||||||
|
|
||||||
func (svc *UserService) ExchangeGoogleCodeAndGetUserInfo(ctx context.Context, clientID, clientSecret, code, redirectURI string) (*model.GoogleUserInfo, error) {
|
func (svc *UserService) ExchangeGoogleCodeAndGetUserInfo(ctx context.Context, clientID, clientSecret, code, redirectURI string) (*model.GoogleUserInfo, error) {
|
||||||
tokenURL := "https://oauth2.googleapis.com/token"
|
tokenURL := "https://oauth2.googleapis.com/token"
|
||||||
formData := url.Values{
|
formData := url.Values{
|
||||||
@@ -181,7 +193,8 @@ func (svc *UserService) ExchangeGoogleCodeAndGetUserInfo(ctx context.Context, cl
|
|||||||
"redirect_uri": {redirectURI},
|
"redirect_uri": {redirectURI},
|
||||||
}
|
}
|
||||||
|
|
||||||
resp, err := http.PostForm(tokenURL, formData)
|
client := svc.googleHTTPClient()
|
||||||
|
resp, err := client.PostForm(tokenURL, formData)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error(ctx, "func", "ExchangeGoogleCodeAndGetUserInfo", "msg", "exchange code failed", "error", err)
|
log.Error(ctx, "func", "ExchangeGoogleCodeAndGetUserInfo", "msg", "exchange code failed", "error", err)
|
||||||
return nil, err
|
return nil, err
|
||||||
@@ -219,7 +232,7 @@ func (svc *UserService) getGoogleUserInfo(ctx context.Context, accessToken strin
|
|||||||
}
|
}
|
||||||
req.Header.Set("Authorization", "Bearer "+accessToken)
|
req.Header.Set("Authorization", "Bearer "+accessToken)
|
||||||
|
|
||||||
client := &http.Client{}
|
client := svc.googleHTTPClient()
|
||||||
resp, err := client.Do(req)
|
resp, err := client.Do(req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|||||||
Reference in New Issue
Block a user