add: AllowOrigins config && changed config format
This commit is contained in:
@@ -18,7 +18,7 @@ func main() {
|
|||||||
|
|
||||||
config.LoadConfig()
|
config.LoadConfig()
|
||||||
|
|
||||||
err := database.Open(config.DB.Path)
|
err := database.Open(config.DB.Path, config.Recipients.AdminEmail)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logger.Error.Fatalf("Couldn't init database: %v", err)
|
logger.Error.Fatalf("Couldn't init database: %v", err)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,9 @@
|
|||||||
{
|
{
|
||||||
|
"site": {
|
||||||
"WebsiteTitle": "My Carsharing Site",
|
"WebsiteTitle": "My Carsharing Site",
|
||||||
"BaseURL": "https://domain.de",
|
"BaseUrl": "https://domain.de",
|
||||||
|
"AllowOrigins": "https://domain.de"
|
||||||
|
},
|
||||||
"Environment": "dev",
|
"Environment": "dev",
|
||||||
"db": {
|
"db": {
|
||||||
"Path": "data/db.sqlite3"
|
"Path": "data/db.sqlite3"
|
||||||
|
|||||||
@@ -23,6 +23,11 @@ type DatabaseConfig struct {
|
|||||||
Path string `json:"Path" default:"data/db.sqlite3" envconfig:"DB_PATH"`
|
Path string `json:"Path" default:"data/db.sqlite3" envconfig:"DB_PATH"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type SiteConfig struct {
|
||||||
|
AllowOrigins string `json:"AllowOrigins" envconfig:"ALLOW_ORIGINS"`
|
||||||
|
WebsiteTitle string `json:"WebsiteTitle" envconfig:"WEBSITE_TITLE"`
|
||||||
|
BaseURL string `json:"BaseUrl" envconfig:"BASE_URL"`
|
||||||
|
}
|
||||||
type AuthenticationConfig struct {
|
type AuthenticationConfig struct {
|
||||||
JWTSecret string
|
JWTSecret string
|
||||||
CSRFSecret string
|
CSRFSecret string
|
||||||
@@ -57,11 +62,10 @@ type SecurityConfig struct {
|
|||||||
}
|
}
|
||||||
type Config struct {
|
type Config struct {
|
||||||
Auth AuthenticationConfig `json:"auth"`
|
Auth AuthenticationConfig `json:"auth"`
|
||||||
|
Site SiteConfig `json:"site"`
|
||||||
Templates TemplateConfig `json:"templates"`
|
Templates TemplateConfig `json:"templates"`
|
||||||
Recipients RecipientsConfig `json:"recipients"`
|
Recipients RecipientsConfig `json:"recipients"`
|
||||||
ConfigFilePath string `json:"config_file_path" envconfig:"CONFIG_FILE_PATH"`
|
ConfigFilePath string `json:"config_file_path" envconfig:"CONFIG_FILE_PATH"`
|
||||||
WebsiteTitle string `json:"WebsiteTitle" envconfig:"WEBSITE_TITLE"`
|
|
||||||
BaseURL string `json:"BaseUrl" envconfig:"BASE_URL"`
|
|
||||||
Env string `json:"Environment" default:"development" envconfig:"ENV"`
|
Env string `json:"Environment" default:"development" envconfig:"ENV"`
|
||||||
DB DatabaseConfig `json:"db"`
|
DB DatabaseConfig `json:"db"`
|
||||||
SMTP SMTPConfig `json:"smtp"`
|
SMTP SMTPConfig `json:"smtp"`
|
||||||
@@ -69,8 +73,7 @@ type Config struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
BaseURL string
|
Site SiteConfig
|
||||||
WebsiteTitle string
|
|
||||||
CFGPath string
|
CFGPath string
|
||||||
CFG Config
|
CFG Config
|
||||||
Auth AuthenticationConfig
|
Auth AuthenticationConfig
|
||||||
@@ -115,11 +118,10 @@ func LoadConfig() {
|
|||||||
DB = CFG.DB
|
DB = CFG.DB
|
||||||
Templates = CFG.Templates
|
Templates = CFG.Templates
|
||||||
SMTP = CFG.SMTP
|
SMTP = CFG.SMTP
|
||||||
BaseURL = CFG.BaseURL
|
|
||||||
Recipients = CFG.Recipients
|
Recipients = CFG.Recipients
|
||||||
Security = CFG.Security
|
Security = CFG.Security
|
||||||
Env = CFG.Env
|
Env = CFG.Env
|
||||||
WebsiteTitle = CFG.WebsiteTitle
|
Site = CFG.Site
|
||||||
logger.Info.Printf("Config loaded: %#v", CFG)
|
logger.Info.Printf("Config loaded: %#v", CFG)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -70,7 +70,7 @@ func (s *EmailService) SendVerificationEmail(user *models.User, token *string) e
|
|||||||
FirstName: user.FirstName,
|
FirstName: user.FirstName,
|
||||||
LastName: user.LastName,
|
LastName: user.LastName,
|
||||||
Token: *token,
|
Token: *token,
|
||||||
BASEURL: config.BaseURL,
|
BASEURL: config.Site.BaseURL,
|
||||||
}
|
}
|
||||||
|
|
||||||
subject := constants.MailVerificationSubject
|
subject := constants.MailVerificationSubject
|
||||||
@@ -102,8 +102,8 @@ func (s *EmailService) SendWelcomeEmail(user *models.User) error {
|
|||||||
MembershipID: user.Membership.ID,
|
MembershipID: user.Membership.ID,
|
||||||
MembershipFee: float32(user.Membership.SubscriptionModel.MonthlyFee),
|
MembershipFee: float32(user.Membership.SubscriptionModel.MonthlyFee),
|
||||||
RentalFee: float32(user.Membership.SubscriptionModel.HourlyRate),
|
RentalFee: float32(user.Membership.SubscriptionModel.HourlyRate),
|
||||||
BASEURL: config.BaseURL,
|
BASEURL: config.Site.BaseURL,
|
||||||
WebsiteTitle: config.WebsiteTitle,
|
WebsiteTitle: config.Site.WebsiteTitle,
|
||||||
Logo: config.Templates.LogoURI,
|
Logo: config.Templates.LogoURI,
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -151,9 +151,9 @@ func (s *EmailService) SendRegistrationNotification(user *models.User) error {
|
|||||||
Email: user.Email,
|
Email: user.Email,
|
||||||
Phone: user.Phone,
|
Phone: user.Phone,
|
||||||
IBAN: user.BankAccount.IBAN,
|
IBAN: user.BankAccount.IBAN,
|
||||||
BASEURL: config.BaseURL,
|
BASEURL: config.Site.BaseURL,
|
||||||
Logo: config.Templates.LogoURI,
|
Logo: config.Templates.LogoURI,
|
||||||
WebsiteTitle: config.WebsiteTitle,
|
WebsiteTitle: config.Site.WebsiteTitle,
|
||||||
}
|
}
|
||||||
|
|
||||||
subject := constants.MailRegistrationSubject
|
subject := constants.MailRegistrationSubject
|
||||||
@@ -175,9 +175,9 @@ func (s *EmailService) RelayContactFormMessage(sender string, name string, messa
|
|||||||
}{
|
}{
|
||||||
Message: message,
|
Message: message,
|
||||||
Name: name,
|
Name: name,
|
||||||
BASEURL: config.BaseURL,
|
BASEURL: config.Site.BaseURL,
|
||||||
Logo: config.Templates.LogoURI,
|
Logo: config.Templates.LogoURI,
|
||||||
WebsiteTitle: config.WebsiteTitle,
|
WebsiteTitle: config.Site.WebsiteTitle,
|
||||||
}
|
}
|
||||||
subject := constants.MailContactSubject
|
subject := constants.MailContactSubject
|
||||||
body, err := ParseTemplate("mail_contact_form.tmpl", data)
|
body, err := ParseTemplate("mail_contact_form.tmpl", data)
|
||||||
|
|||||||
Reference in New Issue
Block a user