wip
This commit is contained in:
@@ -10,7 +10,6 @@ import (
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"github.com/alexedwards/argon2id"
|
||||
"gorm.io/driver/sqlite"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
@@ -53,7 +52,7 @@ func Open(dbPath string, adminMail string, debug bool) (*gorm.DB, error) {
|
||||
|
||||
if err := db.AutoMigrate(
|
||||
&models.User{},
|
||||
&models.SubscriptionModel{},
|
||||
&models.Subscription{},
|
||||
&models.Membership{},
|
||||
&models.Consent{},
|
||||
&models.Verification{},
|
||||
@@ -83,12 +82,12 @@ func Open(dbPath string, adminMail string, debug bool) (*gorm.DB, error) {
|
||||
}
|
||||
|
||||
var subscriptionsCount int64
|
||||
db.Model(&models.SubscriptionModel{}).Count(&subscriptionsCount)
|
||||
subscriptionModels := createSubscriptionModels()
|
||||
for _, model := range subscriptionModels {
|
||||
db.Model(&models.Subscription{}).Count(&subscriptionsCount)
|
||||
subscriptions := createSubscriptions()
|
||||
for _, model := range subscriptions {
|
||||
var exists int64
|
||||
db.
|
||||
Model(&models.SubscriptionModel{}).
|
||||
Model(&models.Subscription{}).
|
||||
Where("name = ?", model.Name).
|
||||
Count(&exists)
|
||||
logger.Error.Printf("looked for model.name %v and found %v", model.Name, exists)
|
||||
@@ -103,7 +102,7 @@ func Open(dbPath string, adminMail string, debug bool) (*gorm.DB, error) {
|
||||
var userCount int64
|
||||
db.Model(&models.User{}).Count(&userCount)
|
||||
if userCount == 0 {
|
||||
var createdModel models.SubscriptionModel
|
||||
var createdModel models.Subscription
|
||||
if err := db.First(&createdModel).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -118,10 +117,10 @@ func Open(dbPath string, adminMail string, debug bool) (*gorm.DB, error) {
|
||||
return db, nil
|
||||
}
|
||||
|
||||
func createSubscriptionModels() []models.SubscriptionModel {
|
||||
return []models.SubscriptionModel{
|
||||
func createSubscriptions() []models.Subscription {
|
||||
return []models.Subscription{
|
||||
{
|
||||
Name: constants.SupporterSubscriptionModelName,
|
||||
Name: constants.SupporterSubscriptionName,
|
||||
Details: "Dieses Modell ist für Sponsoren und Nichtmitglieder, die keinen Vereinsmitglied sind.",
|
||||
HourlyRate: 999,
|
||||
MonthlyFee: 0,
|
||||
@@ -162,11 +161,6 @@ func createAdmin(userMail string) (*models.User, error) {
|
||||
// Encode into a URL-safe base64 string
|
||||
password := base64.URLEncoding.EncodeToString(passwordBytes)[:12]
|
||||
|
||||
hash, err := argon2id.CreateHash(password, argon2id.DefaultParams)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
logger.Error.Print("==============================================================")
|
||||
logger.Error.Printf("Admin Email: %v", userMail)
|
||||
logger.Error.Printf("Admin Password: %v", password)
|
||||
@@ -176,7 +170,7 @@ func createAdmin(userMail string) (*models.User, error) {
|
||||
FirstName: "Ad",
|
||||
LastName: "Min",
|
||||
DateOfBirth: time.Now().AddDate(-20, 0, 0),
|
||||
Password: hash,
|
||||
Password: password,
|
||||
Company: "",
|
||||
Address: "",
|
||||
ZipCode: "",
|
||||
|
||||
Reference in New Issue
Block a user