diff --git a/.env-example b/.env-example index 332f0d4..2b4b511 100644 --- a/.env-example +++ b/.env-example @@ -1,4 +1,9 @@ # API key for chatgpt CHATGPT_KEY=api key for chatgpt +# Chat gpt model +CHATGPT_MODEL=gpt-4o # This is secret key for jwt signature JWT_SECRET=just a random string here +# Set to false to disable registration +ALLOW_REGISTER=true + diff --git a/backend/config/config.go b/backend/config/config.go index 91e7963..3864ea8 100644 --- a/backend/config/config.go +++ b/backend/config/config.go @@ -1,6 +1,9 @@ package config -import "os" +import ( + "log" + "os" +) func defaultValue(val string, def string) string { if val == "" { @@ -20,4 +23,8 @@ func LoadEnv() { Env["JWT_SECRET"] = defaultValue(os.Getenv("JWT_SECRET"), "just a random string here") Env["Environment"] = defaultValue(os.Getenv("Environment"), "dev") Env["CHATGPT_KEY"] = defaultValue(os.Getenv("CHATGPT_KEY"), "") + Env["REGISTER"] = defaultValue(os.Getenv("ALLOW_REGISTER"), "true") + log.Printf("[INFO] Register set to '%s'\n", Env["REGISTER"]) + Env["CHATGPT_MODEL"] = defaultValue(os.Getenv("CHATGPT_MODEL"), "gpt-4o") + log.Printf("[INFO] ChatGPT model set to '%s'\n", Env["CHATGPT_MODEL"]) } diff --git a/backend/controllers/user/user.go b/backend/controllers/user/user.go index d1b8e15..bec5300 100644 --- a/backend/controllers/user/user.go +++ b/backend/controllers/user/user.go @@ -25,6 +25,12 @@ type RegisterForm struct { } func Register(c *gin.Context) { + // Check for register environment + if config.Env["REGISTER"] != "true" { + res.Error(c, "Registration is disabled", http.StatusForbidden) + return + } + // Receive data from frontend, check if data is okay, hash password, call model var data RegisterForm if err := c.ShouldBindJSON(&data); err != nil { diff --git a/backend/utils/chatgpt/chatgpt.go b/backend/utils/chatgpt/chatgpt.go index 3d102d3..431e636 100644 --- a/backend/utils/chatgpt/chatgpt.go +++ b/backend/utils/chatgpt/chatgpt.go @@ -37,7 +37,7 @@ func GenerateCoverLetter(templateHTML string, jobHTML string) (GeneratedCover, e } payload := ChatRequest{ - Model: "gpt-4o", // o4-mini + Model: config.Env["CHATGPT_MODEL"], ResponseFormat: &ResponseFormat{Type: "json_object"}, Messages: []ChatMessage{ { diff --git a/production.yml b/production.yml index 699aff8..04627e0 100644 --- a/production.yml +++ b/production.yml @@ -30,7 +30,7 @@ services: container_name: cover-letter-frontend ports: - - 80:8080 + - 8000:8080 networks: - cover-letter-network db: