mirror of
https://github.com/hrfee/jfa-go.git
synced 2024-12-22 17:10:10 +00:00
add more error logging; mutex for app.storage.users
This commit is contained in:
parent
ab3d5f3321
commit
76b822213e
4
api.go
4
api.go
@ -446,6 +446,8 @@ func (app *appContext) newUser(req newUserDTO, confirmed bool) (f errorFunc, suc
|
||||
}
|
||||
}
|
||||
if invite.UserExpiry {
|
||||
app.storage.usersLock.Lock()
|
||||
defer app.storage.usersLock.Unlock()
|
||||
expiry := time.Now().Add(time.Duration(60*(invite.UserDays*24+invite.UserHours)+invite.UserMinutes) * time.Minute)
|
||||
app.storage.users[id] = expiry
|
||||
if err := app.storage.storeUsers(); err != nil {
|
||||
@ -473,6 +475,8 @@ func (app *appContext) ExtendExpiry(gc *gin.Context) {
|
||||
respondBool(400, false, gc)
|
||||
return
|
||||
}
|
||||
app.storage.usersLock.Lock()
|
||||
defer app.storage.usersLock.Unlock()
|
||||
for _, id := range req.Users {
|
||||
if expiry, ok := app.storage.users[id]; ok {
|
||||
app.storage.users[id] = expiry.Add(time.Duration(60*(req.Days*24+req.Hours)+req.Minutes) * time.Minute)
|
||||
|
24
main.go
24
main.go
@ -353,17 +353,29 @@ func start(asDaemon, firstCall bool) {
|
||||
app.debug.Println("Loading storage")
|
||||
|
||||
app.storage.invite_path = app.config.Section("files").Key("invites").String()
|
||||
app.storage.loadInvites()
|
||||
if err := app.storage.loadInvites(); err != nil {
|
||||
app.err.Printf("Failed to load Invites: %v", err)
|
||||
}
|
||||
app.storage.emails_path = app.config.Section("files").Key("emails").String()
|
||||
app.storage.loadEmails()
|
||||
if err := app.storage.loadEmails(); err != nil {
|
||||
app.err.Printf("Failed to load Emails: %v", err)
|
||||
}
|
||||
app.storage.policy_path = app.config.Section("files").Key("user_template").String()
|
||||
app.storage.loadPolicy()
|
||||
if err := app.storage.loadPolicy(); err != nil {
|
||||
app.err.Printf("Failed to load Policy: %v", err)
|
||||
}
|
||||
app.storage.configuration_path = app.config.Section("files").Key("user_configuration").String()
|
||||
app.storage.loadConfiguration()
|
||||
if err := app.storage.loadConfiguration(); err != nil {
|
||||
app.err.Printf("Failed to load Configuration: %v", err)
|
||||
}
|
||||
app.storage.displayprefs_path = app.config.Section("files").Key("user_displayprefs").String()
|
||||
app.storage.loadDisplayprefs()
|
||||
if err := app.storage.loadDisplayprefs(); err != nil {
|
||||
app.err.Printf("Failed to load Displayprefs: %v", err)
|
||||
}
|
||||
app.storage.users_path = app.config.Section("files").Key("users").String()
|
||||
app.storage.loadUsers()
|
||||
if err := app.storage.loadUsers(); err != nil {
|
||||
app.err.Printf("Failed to load Users: %v", err)
|
||||
}
|
||||
|
||||
app.storage.profiles_path = app.config.Section("files").Key("user_profiles").String()
|
||||
app.storage.loadProfiles()
|
||||
|
@ -26,7 +26,7 @@ type Storage struct {
|
||||
policy mediabrowser.Policy
|
||||
configuration mediabrowser.Configuration
|
||||
lang Lang
|
||||
invitesLock sync.Mutex
|
||||
invitesLock, usersLock sync.Mutex
|
||||
}
|
||||
|
||||
type customEmails struct {
|
||||
@ -480,6 +480,8 @@ func (st *Storage) storeInvites() error {
|
||||
}
|
||||
|
||||
func (st *Storage) loadUsers() error {
|
||||
st.usersLock.Lock()
|
||||
defer st.usersLock.Unlock()
|
||||
return loadJSON(st.users_path, &st.users)
|
||||
}
|
||||
|
||||
|
@ -44,6 +44,12 @@ func (rt *userDaemon) run() {
|
||||
}
|
||||
|
||||
func (app *appContext) checkUsers() {
|
||||
if err := app.storage.loadUsers(); err != nil {
|
||||
app.err.Printf("Failed to load user expiries: %v", err)
|
||||
return
|
||||
}
|
||||
app.storage.usersLock.Lock()
|
||||
defer app.storage.usersLock.Unlock()
|
||||
if len(app.storage.users) == 0 {
|
||||
return
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user