tableSettings.go (1604B)
1 package database 2 3 import "github.com/sirupsen/logrus" 4 5 // Settings table, should always be one row 6 type Settings struct { 7 ID int64 8 MaybeAuthEnabled bool // either or not unauthenticated users can access the "maybe auth" pages 9 SilentSelfKick bool // either or not people can use the forum features 10 ForumEnabled bool // either or not people can use the forum features 11 SignupEnabled bool // either or not people can sign up 12 SignupFakeEnabled bool // either or not signup is faked to be enabled 13 ProtectHome bool // ... 14 HomeUsersList bool // ... 15 ForceLoginCaptcha bool // either or not people are forced to complete captcha at login 16 DownloadsEnabled bool // either or not people can download files 17 PokerWithdrawEnabled bool // either or not poker withdraw is enabled 18 CaptchaDifficulty int64 // captcha difficulty 19 PowEnabled bool 20 MoneroPrice float64 21 } 22 23 // GetSettings get the saved settings from the DB 24 func (d *DkfDB) GetSettings() (out Settings) { 25 if err := d.db.Model(Settings{}).First(&out).Error; err != nil { 26 out.SignupEnabled = true 27 out.SilentSelfKick = true 28 out.ForumEnabled = true 29 out.MaybeAuthEnabled = true 30 out.DownloadsEnabled = true 31 out.CaptchaDifficulty = 2 32 out.MoneroPrice = 170.0 33 d.db.Create(&out) 34 } 35 return 36 } 37 38 // Save the settings to DB 39 func (s *Settings) Save(db *DkfDB) error { 40 return db.db.Save(s).Error 41 } 42 43 // DoSave settings in the database, ignore error 44 func (s *Settings) DoSave(db *DkfDB) { 45 if err := s.Save(db); err != nil { 46 logrus.Error(err) 47 } 48 }