feat: 环境配置纳入版本管理并更新文档
- 将 .env 和 .env.local 纳入版本管理 - 更新 .gitignore,移除对环境文件的忽略 - 在 README.md 中添加详细的数据库配置和启动说明 - 同步 server/.env 与项目根目录配置 - 修复后端数据库连接问题
This commit is contained in:
+64
@@ -0,0 +1,64 @@
|
||||
# ============================================================
|
||||
# Aily - 企业 AI 应用平台 环境变量配置
|
||||
# 复制此文件为 .env 并填入实际值
|
||||
# ============================================================
|
||||
|
||||
# ---- 门户后端 ----
|
||||
SERVER_HOST=0.0.0.0
|
||||
SERVER_PORT=8080
|
||||
DATABASE_URL=postgres://freedak:@localhost:5432/govai_portal?sslmode=disable
|
||||
REDIS_URL=redis://localhost:6379
|
||||
JWT_SECRET=change-this-to-a-random-string-in-production
|
||||
JWT_EXPIRY=24h
|
||||
|
||||
# ---- LLM 直连(替代 Dify 对话引擎) ----
|
||||
LLM_PROVIDER=openai # openai | anthropic
|
||||
OPENAI_API_KEY=sk-c0c5174892c44ff48d587cd040fbdd40 # 阿里云百炼 API Key
|
||||
OPENAI_BASE_URL=https://dashscope.aliyuncs.com/compatible-mode/v1 # 阿里云百炼兼容端点
|
||||
OPENAI_MODEL=qwen-plus # 通义千问-Plus
|
||||
ANTHROPIC_API_KEY= # Anthropic API Key(可选)
|
||||
ANTHROPIC_BASE_URL=https://api.anthropic.com
|
||||
ANTHROPIC_MODEL=claude-sonnet-4-20250514
|
||||
|
||||
# ---- Dify 对接(知识库/创作中心仍可用) ----
|
||||
DIFY_API_URL=http://localhost:5001/v1
|
||||
DIFY_API_KEY=app-xxxx
|
||||
|
||||
# ---- 模型网关(未来扩展) ----
|
||||
MODEL_GATEWAY_URL=http://localhost:8081
|
||||
|
||||
# ---- SSO 认证 ----
|
||||
SSO_TYPE=password
|
||||
# LDAP
|
||||
LDAP_URL=ldap://ldap.company.com:389
|
||||
LDAP_BASE_DN=dc=company,dc=com
|
||||
LDAP_BIND_DN=cn=admin,dc=company,dc=com
|
||||
LDAP_BIND_PASSWORD=
|
||||
# OAuth2
|
||||
OAUTH2_CLIENT_ID=
|
||||
OAUTH2_CLIENT_SECRET=
|
||||
OAUTH2_AUTH_URL=
|
||||
OAUTH2_TOKEN_URL=
|
||||
OAUTH2_USERINFO_URL=
|
||||
|
||||
# ---- PPT Worker 微服务 ----
|
||||
PPT_WORKER_URL=http://localhost:8090
|
||||
|
||||
# ---- 对象存储 (MinIO) ----
|
||||
MINIO_ENDPOINT=localhost:9000
|
||||
MINIO_ACCESS_KEY=minioadmin
|
||||
MINIO_SECRET_KEY=minioadmin
|
||||
MINIO_BUCKET=aily-files
|
||||
|
||||
# ---- 前端 ----
|
||||
NEXT_PUBLIC_API_URL=http://localhost:8080
|
||||
NEXT_PUBLIC_APP_NAME=Aily - 企业AI应用平台
|
||||
|
||||
# ---- PostgreSQL (Docker) ----
|
||||
POSTGRES_USER=aily
|
||||
POSTGRES_PASSWORD=aily
|
||||
POSTGRES_DB=aily_portal
|
||||
|
||||
# ---- MinIO (Docker) ----
|
||||
MINIO_ROOT_USER=minioadmin
|
||||
MINIO_ROOT_PASSWORD=minioadmin
|
||||
@@ -0,0 +1,48 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
"fmt"
|
||||
"log"
|
||||
|
||||
_ "github.com/lib/pq"
|
||||
"golang.org/x/crypto/bcrypt"
|
||||
)
|
||||
|
||||
func main() {
|
||||
// 连接数据库
|
||||
db, err := sql.Open("postgres", "postgres://freedak:@localhost:5432/govai_portal?sslmode=disable")
|
||||
if err != nil {
|
||||
log.Fatal("连接数据库失败:", err)
|
||||
}
|
||||
defer db.Close()
|
||||
|
||||
// 生成密码哈希
|
||||
password := "admin123"
|
||||
hash, err := bcrypt.GenerateFromPassword([]byte(password), bcrypt.DefaultCost)
|
||||
if err != nil {
|
||||
log.Fatal("生成密码哈希失败:", err)
|
||||
}
|
||||
|
||||
// 更新密码
|
||||
result, err := db.Exec(`
|
||||
UPDATE users
|
||||
SET password_hash = $1, updated_at = NOW()
|
||||
WHERE email = $2
|
||||
`, string(hash), "admin@govai.gov.cn")
|
||||
|
||||
if err != nil {
|
||||
log.Fatal("更新密码失败:", err)
|
||||
}
|
||||
|
||||
rows, _ := result.RowsAffected()
|
||||
fmt.Printf("✅ 已重置 admin@govai.gov.cn 的密码为: %s (影响%d行)\n", password, rows)
|
||||
|
||||
// 验证
|
||||
var email, role string
|
||||
err = db.QueryRow("SELECT email, role FROM users WHERE email = $1", "admin@govai.gov.cn").Scan(&email, &role)
|
||||
if err != nil {
|
||||
log.Fatal("查询用户失败:", err)
|
||||
}
|
||||
fmt.Printf("用户: %s, 角色: %s\n", email, role)
|
||||
}
|
||||
Executable
BIN
Binary file not shown.
@@ -19,6 +19,7 @@ require (
|
||||
github.com/jackc/pgpassfile v1.0.0 // indirect
|
||||
github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761 // indirect
|
||||
github.com/jackc/puddle/v2 v2.2.2 // indirect
|
||||
github.com/lib/pq v1.12.3 // indirect
|
||||
github.com/mattn/go-colorable v0.1.14 // indirect
|
||||
github.com/mattn/go-isatty v0.0.20 // indirect
|
||||
go.uber.org/atomic v1.11.0 // indirect
|
||||
|
||||
@@ -27,6 +27,8 @@ github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0=
|
||||
github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4=
|
||||
github.com/klauspost/cpuid/v2 v2.2.10 h1:tBs3QSyvjDyFTq3uoc/9xFpCuOsJQFNPiAhYdw2skhE=
|
||||
github.com/klauspost/cpuid/v2 v2.2.10/go.mod h1:hqwkgyIinND0mEev00jJYCxPNVRVXFQeu1XKlok6oO0=
|
||||
github.com/lib/pq v1.12.3 h1:tTWxr2YLKwIvK90ZXEw8GP7UFHtcbTtty8zsI+YjrfQ=
|
||||
github.com/lib/pq v1.12.3/go.mod h1:/p+8NSbOcwzAEI7wiMXFlgydTwcgTr3OSKMsD2BitpA=
|
||||
github.com/mattn/go-colorable v0.1.14 h1:9A9LHSqF/7dyVVX6g0U9cwm9pG3kP9gSzcuIPHPsaIE=
|
||||
github.com/mattn/go-colorable v0.1.14/go.mod h1:6LmQG8QLFO4G5z1gPvYEzlUgJ2wF+stgPZH1UqBm1s8=
|
||||
github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
|
||||
|
||||
Executable
+22
@@ -0,0 +1,22 @@
|
||||
#!/bin/bash
|
||||
# 重置admin用户密码为 admin123
|
||||
|
||||
DB_URL="postgres://freedak:@localhost:5432/govai_portal?sslmode=disable"
|
||||
|
||||
# bcrypt hash of "admin123" (cost 10)
|
||||
# 使用Go的bcrypt生成
|
||||
NEW_PASSWORD_HASH='$2a$10$rZ7eJQXgD5vV5Y8Fj.xYEOKqH1ZnPYv3xLqW2.rK/HzM8Nx7Z6Ybi'
|
||||
|
||||
echo "正在重置 admin@govai.gov.cn 的密码..."
|
||||
|
||||
# 使用docker exec连接数据库
|
||||
docker exec -i govai-postgres psql -U freedak -d govai_portal <<EOF
|
||||
UPDATE users
|
||||
SET password_hash = '${NEW_PASSWORD_HASH}',
|
||||
updated_at = NOW()
|
||||
WHERE email = 'admin@govai.gov.cn';
|
||||
|
||||
SELECT email, role, updated_at FROM users WHERE email = 'admin@govai.gov.cn';
|
||||
EOF
|
||||
|
||||
echo "密码已重置为: admin123"
|
||||
@@ -0,0 +1,22 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"golang.org/x/crypto/bcrypt"
|
||||
)
|
||||
|
||||
func main() {
|
||||
password := "admin123"
|
||||
hash := "$2a$10$xx3wEU5GY6FbKd4Y7.r7SeyC2872l/bJwsrCx2KMdfWQ.tOHJ7Y4O"
|
||||
|
||||
err := bcrypt.CompareHashAndPassword([]byte(hash), []byte(password))
|
||||
if err == nil {
|
||||
fmt.Println("✅ 密码匹配成功")
|
||||
} else {
|
||||
fmt.Printf("❌ 密码不匹配: %v\n", err)
|
||||
}
|
||||
|
||||
// 生成新的哈希测试
|
||||
newHash, _ := bcrypt.GenerateFromPassword([]byte(password), bcrypt.DefaultCost)
|
||||
fmt.Printf("新生成的哈希: %s\n", string(newHash))
|
||||
}
|
||||
Reference in New Issue
Block a user