conform service design/usage patterns
This commit is contained in:
parent
89a5fdc4e5
commit
fd3b2a0dba
13 changed files with 65 additions and 60 deletions
|
|
@ -115,7 +115,7 @@ func changePasswordHandler(app *app.AppState) http.Handler {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
app.Log.Info(model.LOG_ACCOUNT, "\"%s\" changed password by user request. (%s)", session.Account.Username, controller.ResolveIP(app, r))
|
app.LogService.Info(model.LOG_ACCOUNT, "\"%s\" changed password by user request. (%s)", session.Account.Username, controller.ResolveIP(app, r))
|
||||||
|
|
||||||
controller.SetSessionError(app.DB, session, "")
|
controller.SetSessionError(app.DB, session, "")
|
||||||
controller.SetSessionMessage(app.DB, session, "Password updated successfully.")
|
controller.SetSessionMessage(app.DB, session, "Password updated successfully.")
|
||||||
|
|
@ -145,7 +145,7 @@ func deleteAccountHandler(app *app.AppState) http.Handler {
|
||||||
|
|
||||||
// check password
|
// check password
|
||||||
if err := bcrypt.CompareHashAndPassword([]byte(session.Account.Password), []byte(r.Form.Get("password"))); err != nil {
|
if err := bcrypt.CompareHashAndPassword([]byte(session.Account.Password), []byte(r.Form.Get("password"))); err != nil {
|
||||||
app.Log.Warn(model.LOG_ACCOUNT, "Account \"%s\" attempted account deletion with incorrect password. (%s)", session.Account.Username, controller.ResolveIP(app, r))
|
app.LogService.Warn(model.LOG_ACCOUNT, "Account \"%s\" attempted account deletion with incorrect password. (%s)", session.Account.Username, controller.ResolveIP(app, r))
|
||||||
controller.SetSessionError(app.DB, session, "Incorrect password.")
|
controller.SetSessionError(app.DB, session, "Incorrect password.")
|
||||||
http.Redirect(w, r, "/admin/account", http.StatusFound)
|
http.Redirect(w, r, "/admin/account", http.StatusFound)
|
||||||
return
|
return
|
||||||
|
|
@ -159,7 +159,7 @@ func deleteAccountHandler(app *app.AppState) http.Handler {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
app.Log.Info(model.LOG_ACCOUNT, "Account \"%s\" deleted by user request. (%s)", session.Account.Username, controller.ResolveIP(app, r))
|
app.LogService.Info(model.LOG_ACCOUNT, "Account \"%s\" deleted by user request. (%s)", session.Account.Username, controller.ResolveIP(app, r))
|
||||||
|
|
||||||
controller.SetSessionAccount(app.DB, session, nil)
|
controller.SetSessionAccount(app.DB, session, nil)
|
||||||
controller.SetSessionError(app.DB, session, "")
|
controller.SetSessionError(app.DB, session, "")
|
||||||
|
|
@ -310,7 +310,7 @@ func totpConfirmHandler(app *app.AppState) http.Handler {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
app.Log.Info(model.LOG_ACCOUNT, "\"%s\" created TOTP method \"%s\".", session.Account.Username, totp.Name)
|
app.LogService.Info(model.LOG_ACCOUNT, "\"%s\" created TOTP method \"%s\".", session.Account.Username, totp.Name)
|
||||||
|
|
||||||
controller.SetSessionError(app.DB, session, "")
|
controller.SetSessionError(app.DB, session, "")
|
||||||
controller.SetSessionMessage(app.DB, session, fmt.Sprintf("TOTP method \"%s\" created successfully.", totp.Name))
|
controller.SetSessionMessage(app.DB, session, fmt.Sprintf("TOTP method \"%s\" created successfully.", totp.Name))
|
||||||
|
|
@ -358,7 +358,7 @@ func totpDeleteHandler(app *app.AppState) http.Handler {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
app.Log.Info(model.LOG_ACCOUNT, "\"%s\" deleted TOTP method \"%s\".", session.Account.Username, totp.Name)
|
app.LogService.Info(model.LOG_ACCOUNT, "\"%s\" deleted TOTP method \"%s\".", session.Account.Username, totp.Name)
|
||||||
|
|
||||||
controller.SetSessionError(app.DB, session, "")
|
controller.SetSessionError(app.DB, session, "")
|
||||||
controller.SetSessionMessage(app.DB, session, fmt.Sprintf("TOTP method \"%s\" deleted successfully.", totp.Name))
|
controller.SetSessionMessage(app.DB, session, fmt.Sprintf("TOTP method \"%s\" deleted successfully.", totp.Name))
|
||||||
|
|
|
||||||
|
|
@ -241,7 +241,7 @@ func registerAccountHandler(app *app.AppState) http.Handler {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
app.Log.Info(
|
app.LogService.Info(
|
||||||
model.LOG_ACCOUNT,
|
model.LOG_ACCOUNT,
|
||||||
"Account \"%s\" (%s) created using invite \"%s\". (%s)",
|
"Account \"%s\" (%s) created using invite \"%s\". (%s)",
|
||||||
credentials.Username,
|
credentials.Username,
|
||||||
|
|
@ -252,7 +252,7 @@ func registerAccountHandler(app *app.AppState) http.Handler {
|
||||||
|
|
||||||
err = controller.DeleteInvite(app.DB, invite.Code)
|
err = controller.DeleteInvite(app.DB, invite.Code)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
app.Log.Warn(model.LOG_ACCOUNT, "Failed to delete expired invite \"%s\": %v", invite.Code, err)
|
app.LogService.Warn(model.LOG_ACCOUNT, "Failed to delete expired invite \"%s\": %v", invite.Code, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// registration success!
|
// registration success!
|
||||||
|
|
@ -332,7 +332,7 @@ func loginHandler(app *app.AppState) http.Handler {
|
||||||
|
|
||||||
err = bcrypt.CompareHashAndPassword([]byte(account.Password), []byte(password))
|
err = bcrypt.CompareHashAndPassword([]byte(account.Password), []byte(password))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
app.Log.Warn(model.LOG_ACCOUNT, "\"%s\" attempted login with incorrect password. (%s)", account.Username, controller.ResolveIP(app, r))
|
app.LogService.Warn(model.LOG_ACCOUNT, "\"%s\" attempted login with incorrect password. (%s)", account.Username, controller.ResolveIP(app, r))
|
||||||
if locked := handleFailedLogin(app, account, r); locked {
|
if locked := handleFailedLogin(app, account, r); locked {
|
||||||
controller.SetSessionError(app.DB, session, "Too many failed attempts. This account is now locked.")
|
controller.SetSessionError(app.DB, session, "Too many failed attempts. This account is now locked.")
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -366,8 +366,8 @@ func loginHandler(app *app.AppState) http.Handler {
|
||||||
|
|
||||||
// login success!
|
// login success!
|
||||||
// TODO: log login activity to user
|
// TODO: log login activity to user
|
||||||
app.Log.Info(model.LOG_ACCOUNT, "\"%s\" logged in. (%s)", account.Username, controller.ResolveIP(app, r))
|
app.LogService.Info(model.LOG_ACCOUNT, "\"%s\" logged in. (%s)", account.Username, controller.ResolveIP(app, r))
|
||||||
app.Log.Warn(model.LOG_ACCOUNT, "\"%s\" does not have any TOTP methods assigned.", account.Username)
|
app.LogService.Warn(model.LOG_ACCOUNT, "\"%s\" does not have any TOTP methods assigned.", account.Username)
|
||||||
|
|
||||||
err = controller.SetSessionAccount(app.DB, session, account)
|
err = controller.SetSessionAccount(app.DB, session, account)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
@ -420,7 +420,7 @@ func loginTOTPHandler(app *app.AppState) http.Handler {
|
||||||
totpCode := r.FormValue("totp")
|
totpCode := r.FormValue("totp")
|
||||||
|
|
||||||
if len(totpCode) != controller.TOTP_CODE_LENGTH {
|
if len(totpCode) != controller.TOTP_CODE_LENGTH {
|
||||||
app.Log.Warn(model.LOG_ACCOUNT, "\"%s\" failed login (Invalid TOTP). (%s)", session.AttemptAccount.Username, controller.ResolveIP(app, r))
|
app.LogService.Warn(model.LOG_ACCOUNT, "\"%s\" failed login (Invalid TOTP). (%s)", session.AttemptAccount.Username, controller.ResolveIP(app, r))
|
||||||
controller.SetSessionError(app.DB, session, "Invalid TOTP.")
|
controller.SetSessionError(app.DB, session, "Invalid TOTP.")
|
||||||
render()
|
render()
|
||||||
return
|
return
|
||||||
|
|
@ -434,7 +434,7 @@ func loginTOTPHandler(app *app.AppState) http.Handler {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if totpMethod == nil {
|
if totpMethod == nil {
|
||||||
app.Log.Warn(model.LOG_ACCOUNT, "\"%s\" failed login (Incorrect TOTP). (%s)", session.AttemptAccount.Username, controller.ResolveIP(app, r))
|
app.LogService.Warn(model.LOG_ACCOUNT, "\"%s\" failed login (Incorrect TOTP). (%s)", session.AttemptAccount.Username, controller.ResolveIP(app, r))
|
||||||
if locked := handleFailedLogin(app, session.AttemptAccount, r); locked {
|
if locked := handleFailedLogin(app, session.AttemptAccount, r); locked {
|
||||||
controller.SetSessionError(app.DB, session, "Too many failed attempts. This account is now locked.")
|
controller.SetSessionError(app.DB, session, "Too many failed attempts. This account is now locked.")
|
||||||
controller.SetSessionAttemptAccount(app.DB, session, nil)
|
controller.SetSessionAttemptAccount(app.DB, session, nil)
|
||||||
|
|
@ -446,7 +446,7 @@ func loginTOTPHandler(app *app.AppState) http.Handler {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
app.Log.Info(model.LOG_ACCOUNT, "\"%s\" logged in with TOTP method \"%s\". (%s)", session.AttemptAccount.Username, totpMethod.Name, controller.ResolveIP(app, r))
|
app.LogService.Info(model.LOG_ACCOUNT, "\"%s\" logged in with TOTP method \"%s\". (%s)", session.AttemptAccount.Username, totpMethod.Name, controller.ResolveIP(app, r))
|
||||||
|
|
||||||
err = controller.SetSessionAccount(app.DB, session, session.AttemptAccount)
|
err = controller.SetSessionAccount(app.DB, session, session.AttemptAccount)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
@ -574,7 +574,7 @@ func handleFailedLogin(app *app.AppState, account *model.Account, r *http.Reques
|
||||||
account.Username,
|
account.Username,
|
||||||
err,
|
err,
|
||||||
)
|
)
|
||||||
app.Log.Warn(
|
app.LogService.Warn(
|
||||||
model.LOG_ACCOUNT,
|
model.LOG_ACCOUNT,
|
||||||
"Failed to lock account \"%s\"",
|
"Failed to lock account \"%s\"",
|
||||||
account.Username,
|
account.Username,
|
||||||
|
|
@ -588,7 +588,7 @@ func handleFailedLogin(app *app.AppState, account *model.Account, r *http.Reques
|
||||||
model.MAX_LOGIN_FAIL_ATTEMPTS,
|
model.MAX_LOGIN_FAIL_ATTEMPTS,
|
||||||
controller.ResolveIP(app, r),
|
controller.ResolveIP(app, r),
|
||||||
)
|
)
|
||||||
app.Log.Warn(
|
app.LogService.Warn(
|
||||||
model.LOG_ACCOUNT,
|
model.LOG_ACCOUNT,
|
||||||
"Account \"%s\" was locked: %d failed login attempts (IP: %s)",
|
"Account \"%s\" was locked: %d failed login attempts (IP: %s)",
|
||||||
account.Username,
|
account.Username,
|
||||||
|
|
@ -606,7 +606,7 @@ func handleFailedLogin(app *app.AppState, account *model.Account, r *http.Reques
|
||||||
account.Username,
|
account.Username,
|
||||||
err,
|
err,
|
||||||
)
|
)
|
||||||
app.Log.Warn(
|
app.LogService.Warn(
|
||||||
model.LOG_ACCOUNT,
|
model.LOG_ACCOUNT,
|
||||||
"Failed to increment login failures for \"%s\"",
|
"Failed to increment login failures for \"%s\"",
|
||||||
account.Username,
|
account.Username,
|
||||||
|
|
|
||||||
|
|
@ -43,7 +43,7 @@ func logsHandler(app *app.AppState) http.Handler {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
logs, err := app.Log.Search(levelFilter, typeFilter, query, 100, 0)
|
logs, err := app.LogService.Search(levelFilter, typeFilter, query, 100, 0)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Fprintf(os.Stderr, "WARN: Failed to fetch audit logs: %v\n", err)
|
fmt.Fprintf(os.Stderr, "WARN: Failed to fetch audit logs: %v\n", err)
|
||||||
http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
|
http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
|
||||||
|
|
|
||||||
|
|
@ -115,7 +115,7 @@ func CreateArtist(app *app.AppState) http.Handler {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
app.Log.Info(model.LOG_ARTIST, "Artist \"%s\" created by \"%s\".", artist.Name, session.Account.Username)
|
app.LogService.Info(model.LOG_ARTIST, "Artist \"%s\" created by \"%s\".", artist.Name, session.Account.Username)
|
||||||
|
|
||||||
w.WriteHeader(http.StatusCreated)
|
w.WriteHeader(http.StatusCreated)
|
||||||
})
|
})
|
||||||
|
|
@ -166,7 +166,7 @@ func UpdateArtist(app *app.AppState, artist *model.Artist) http.Handler {
|
||||||
http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
|
http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
|
||||||
}
|
}
|
||||||
|
|
||||||
app.Log.Info(model.LOG_ARTIST, "Artist \"%s\" updated by \"%s\".", artist.Name, session.Account.Username)
|
app.LogService.Info(model.LOG_ARTIST, "Artist \"%s\" updated by \"%s\".", artist.Name, session.Account.Username)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -184,6 +184,6 @@ func DeleteArtist(app *app.AppState, artist *model.Artist) http.Handler {
|
||||||
http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
|
http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
|
||||||
}
|
}
|
||||||
|
|
||||||
app.Log.Info(model.LOG_ARTIST, "Artist \"%s\" deleted by \"%s\".", artist.Name, session.Account.Username)
|
app.LogService.Info(model.LOG_ARTIST, "Artist \"%s\" deleted by \"%s\".", artist.Name, session.Account.Username)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -224,7 +224,7 @@ func CreateRelease(app *app.AppState) http.Handler {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
app.Log.Info(model.LOG_MUSIC, "Release \"%s\" created by \"%s\".", release.ID, session.Account.Username)
|
app.LogService.Info(model.LOG_MUSIC, "Release \"%s\" created by \"%s\".", release.ID, session.Account.Username)
|
||||||
|
|
||||||
w.Header().Add("Content-Type", "application/json")
|
w.Header().Add("Content-Type", "application/json")
|
||||||
w.WriteHeader(http.StatusCreated)
|
w.WriteHeader(http.StatusCreated)
|
||||||
|
|
@ -307,7 +307,7 @@ func UpdateRelease(app *app.AppState, release *model.Release) http.Handler {
|
||||||
http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
|
http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
|
||||||
}
|
}
|
||||||
|
|
||||||
app.Log.Info(model.LOG_MUSIC, "Release \"%s\" updated by \"%s\".", release.ID, session.Account.Username)
|
app.LogService.Info(model.LOG_MUSIC, "Release \"%s\" updated by \"%s\".", release.ID, session.Account.Username)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -336,7 +336,7 @@ func UpdateReleaseTracks(app *app.AppState, release *model.Release) http.Handler
|
||||||
http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
|
http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
|
||||||
}
|
}
|
||||||
|
|
||||||
app.Log.Info(model.LOG_MUSIC, "Tracklist for release \"%s\" updated by \"%s\".", release.ID, session.Account.Username)
|
app.LogService.Info(model.LOG_MUSIC, "Tracklist for release \"%s\" updated by \"%s\".", release.ID, session.Account.Username)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -381,7 +381,7 @@ func UpdateReleaseCredits(app *app.AppState, release *model.Release) http.Handle
|
||||||
http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
|
http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
|
||||||
}
|
}
|
||||||
|
|
||||||
app.Log.Info(model.LOG_MUSIC, "Credits for release \"%s\" updated by \"%s\".", release.ID, session.Account.Username)
|
app.LogService.Info(model.LOG_MUSIC, "Credits for release \"%s\" updated by \"%s\".", release.ID, session.Account.Username)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -410,7 +410,7 @@ func UpdateReleaseLinks(app *app.AppState, release *model.Release) http.Handler
|
||||||
http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
|
http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
|
||||||
}
|
}
|
||||||
|
|
||||||
app.Log.Info(model.LOG_MUSIC, "Links for release \"%s\" updated by \"%s\".", release.ID, session.Account.Username)
|
app.LogService.Info(model.LOG_MUSIC, "Links for release \"%s\" updated by \"%s\".", release.ID, session.Account.Username)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -428,6 +428,6 @@ func DeleteRelease(app *app.AppState, release *model.Release) http.Handler {
|
||||||
http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
|
http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
|
||||||
}
|
}
|
||||||
|
|
||||||
app.Log.Info(model.LOG_MUSIC, "Release \"%s\" deleted by \"%s\".", release.ID, session.Account.Username)
|
app.LogService.Info(model.LOG_MUSIC, "Release \"%s\" deleted by \"%s\".", release.ID, session.Account.Username)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -97,7 +97,7 @@ func CreateTrack(app *app.AppState) http.Handler {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
app.Log.Info(model.LOG_MUSIC, "Track \"%s\" (%s) created by \"%s\".", track.Title, track.ID, session.Account.Username)
|
app.LogService.Info(model.LOG_MUSIC, "Track \"%s\" (%s) created by \"%s\".", track.Title, track.ID, session.Account.Username)
|
||||||
|
|
||||||
w.Header().Add("Content-Type", "text/plain")
|
w.Header().Add("Content-Type", "text/plain")
|
||||||
w.WriteHeader(http.StatusCreated)
|
w.WriteHeader(http.StatusCreated)
|
||||||
|
|
@ -132,7 +132,7 @@ func UpdateTrack(app *app.AppState, track *model.Track) http.Handler {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
app.Log.Info(model.LOG_MUSIC, "Track \"%s\" (%s) updated by \"%s\".", track.Title, track.ID, session.Account.Username)
|
app.LogService.Info(model.LOG_MUSIC, "Track \"%s\" (%s) updated by \"%s\".", track.Title, track.ID, session.Account.Username)
|
||||||
|
|
||||||
w.Header().Add("Content-Type", "application/json")
|
w.Header().Add("Content-Type", "application/json")
|
||||||
encoder := json.NewEncoder(w)
|
encoder := json.NewEncoder(w)
|
||||||
|
|
@ -160,6 +160,6 @@ func DeleteTrack(app *app.AppState, track *model.Track) http.Handler {
|
||||||
http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
|
http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
|
||||||
}
|
}
|
||||||
|
|
||||||
app.Log.Info(model.LOG_MUSIC, "Track \"%s\" (%s) deleted by \"%s\".", track.Title, track.ID, session.Account.Username)
|
app.LogService.Info(model.LOG_MUSIC, "Track \"%s\" (%s) deleted by \"%s\".", track.Title, track.ID, session.Account.Username)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -50,7 +50,7 @@ func HandleImageUpload(app *app.AppState, data *string, directory string, filena
|
||||||
return "", nil
|
return "", nil
|
||||||
}
|
}
|
||||||
|
|
||||||
app.Log.Info(model.LOG_FILES, "\"%s\" created.", imagePath)
|
app.LogService.Info(model.LOG_FILES, "\"%s\" created.", imagePath)
|
||||||
|
|
||||||
return filename, nil
|
return filename, nil
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -38,10 +38,10 @@ func GetSessionFromRequest(app *app.AppState, r *http.Request) (*model.Session,
|
||||||
account, _ := app.AccountService.GetByID(session.Account.ID)
|
account, _ := app.AccountService.GetByID(session.Account.ID)
|
||||||
msg += " (Account \"" + account.Username + "\")"
|
msg += " (Account \"" + account.Username + "\")"
|
||||||
}
|
}
|
||||||
app.Log.Warn(model.LOG_ACCOUNT, msg)
|
app.LogService.Warn(model.LOG_ACCOUNT, msg)
|
||||||
err = DeleteSession(app.DB, session.Token)
|
err = DeleteSession(app.DB, session.Token)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
app.Log.Warn(model.LOG_ACCOUNT, "Failed to delete affected session")
|
app.LogService.Warn(model.LOG_ACCOUNT, "Failed to delete affected session")
|
||||||
}
|
}
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|
|
||||||
22
main.go
22
main.go
|
|
@ -92,7 +92,7 @@ func main() {
|
||||||
app.DB = psqlDB
|
app.DB = psqlDB
|
||||||
|
|
||||||
logRepo := logRepo.NewLogRepositoryPostgres(psqlDB)
|
logRepo := logRepo.NewLogRepositoryPostgres(psqlDB)
|
||||||
app.Log = logService.NewLogService(
|
app.LogService = logService.NewLogService(
|
||||||
logRepo,
|
logRepo,
|
||||||
log.New(os.Stderr, "logger", model.DEFAULT_LOG_FLAGS),
|
log.New(os.Stderr, "logger", model.DEFAULT_LOG_FLAGS),
|
||||||
)
|
)
|
||||||
|
|
@ -139,7 +139,7 @@ func main() {
|
||||||
logger.Fatalf("FATAL: Failed to create TOTP method: %v\n", err)
|
logger.Fatalf("FATAL: Failed to create TOTP method: %v\n", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
app.Log.Info(model.LOG_ACCOUNT, "TOTP method \"%s\" for \"%s\" created via config utility.", totp.Name, account.Username)
|
app.LogService.Info(model.LOG_ACCOUNT, "TOTP method \"%s\" for \"%s\" created via config utility.", totp.Name, account.Username)
|
||||||
url := controller.GenerateTOTPURI(account.Username, totp.Secret)
|
url := controller.GenerateTOTPURI(account.Username, totp.Secret)
|
||||||
logger.Printf("%s\n", url)
|
logger.Printf("%s\n", url)
|
||||||
return
|
return
|
||||||
|
|
@ -165,7 +165,7 @@ func main() {
|
||||||
logger.Fatalf("FATAL: Failed to create TOTP method: %v\n", err)
|
logger.Fatalf("FATAL: Failed to create TOTP method: %v\n", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
app.Log.Info(model.LOG_ACCOUNT, "TOTP method \"%s\" for \"%s\" deleted via config utility.", totpName, account.Username)
|
app.LogService.Info(model.LOG_ACCOUNT, "TOTP method \"%s\" for \"%s\" deleted via config utility.", totpName, account.Username)
|
||||||
logger.Printf("TOTP method \"%s\" deleted.\n", totpName)
|
logger.Printf("TOTP method \"%s\" deleted.\n", totpName)
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|
@ -231,7 +231,7 @@ func main() {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logger.Fatalf("FATAL: Failed to clean up TOTP methods: %v\n", err)
|
logger.Fatalf("FATAL: Failed to clean up TOTP methods: %v\n", err)
|
||||||
}
|
}
|
||||||
app.Log.Info(model.LOG_ACCOUNT, "TOTP methods pruned via config utility.")
|
app.LogService.Info(model.LOG_ACCOUNT, "TOTP methods pruned via config utility.")
|
||||||
logger.Printf("Cleaned up dangling TOTP methods successfully.\n")
|
logger.Printf("Cleaned up dangling TOTP methods successfully.\n")
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|
@ -242,7 +242,7 @@ func main() {
|
||||||
logger.Fatalf("FATAL: Failed to create invite code: %v\n", err)
|
logger.Fatalf("FATAL: Failed to create invite code: %v\n", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
app.Log.Info(model.LOG_ACCOUNT, "Invite generted via config utility (%s).", invite.Code)
|
app.LogService.Info(model.LOG_ACCOUNT, "Invite generted via config utility (%s).", invite.Code)
|
||||||
logger.Printf(
|
logger.Printf(
|
||||||
"Here you go! This code expires in %d hours: %s\n",
|
"Here you go! This code expires in %d hours: %s\n",
|
||||||
int(math.Ceil(invite.ExpiresAt.Sub(invite.CreatedAt).Hours())),
|
int(math.Ceil(invite.ExpiresAt.Sub(invite.CreatedAt).Hours())),
|
||||||
|
|
@ -257,7 +257,7 @@ func main() {
|
||||||
logger.Fatalf("FATAL: Failed to delete invites: %v\n", err)
|
logger.Fatalf("FATAL: Failed to delete invites: %v\n", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
app.Log.Info(model.LOG_ACCOUNT, "Invites purged via config utility.")
|
app.LogService.Info(model.LOG_ACCOUNT, "Invites purged via config utility.")
|
||||||
logger.Printf("Invites deleted successfully.\n")
|
logger.Printf("Invites deleted successfully.\n")
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|
@ -310,7 +310,7 @@ func main() {
|
||||||
logger.Fatalf("FATAL: Failed to update password: %v\n", err)
|
logger.Fatalf("FATAL: Failed to update password: %v\n", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
app.Log.Info(model.LOG_ACCOUNT, "Password for '%s' updated via config utility.", account.Username)
|
app.LogService.Info(model.LOG_ACCOUNT, "Password for '%s' updated via config utility.", account.Username)
|
||||||
logger.Printf("Password for \"%s\" updated successfully.\n", account.Username)
|
logger.Printf("Password for \"%s\" updated successfully.\n", account.Username)
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|
@ -342,7 +342,7 @@ func main() {
|
||||||
logger.Fatalf("FATAL: Failed to delete account: %v\n", err)
|
logger.Fatalf("FATAL: Failed to delete account: %v\n", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
app.Log.Info(model.LOG_ACCOUNT, "Account '%s' deleted via config utility.", account.Username)
|
app.LogService.Info(model.LOG_ACCOUNT, "Account '%s' deleted via config utility.", account.Username)
|
||||||
logger.Printf("Account \"%s\" deleted successfully.\n", account.Username)
|
logger.Printf("Account \"%s\" deleted successfully.\n", account.Username)
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|
@ -367,7 +367,7 @@ func main() {
|
||||||
logger.Fatalf("FATAL: Failed to lock account: %v\n", err)
|
logger.Fatalf("FATAL: Failed to lock account: %v\n", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
app.Log.Info(model.LOG_ACCOUNT, "Account '%s' locked via config utility.", account.Username)
|
app.LogService.Info(model.LOG_ACCOUNT, "Account '%s' locked via config utility.", account.Username)
|
||||||
logger.Printf("Account \"%s\" locked successfully.\n", account.Username)
|
logger.Printf("Account \"%s\" locked successfully.\n", account.Username)
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|
@ -392,13 +392,13 @@ func main() {
|
||||||
logger.Fatalf("FATAL: Failed to unlock account: %v\n", err)
|
logger.Fatalf("FATAL: Failed to unlock account: %v\n", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
app.Log.Info(model.LOG_ACCOUNT, "Account '%s' unlocked via config utility.", account.Username)
|
app.LogService.Info(model.LOG_ACCOUNT, "Account '%s' unlocked via config utility.", account.Username)
|
||||||
logger.Printf("Account \"%s\" unlocked successfully.\n", account.Username)
|
logger.Printf("Account \"%s\" unlocked successfully.\n", account.Username)
|
||||||
return
|
return
|
||||||
|
|
||||||
case "logs":
|
case "logs":
|
||||||
// TODO: add log search parameters
|
// TODO: add log search parameters
|
||||||
logs, err := app.Log.Search([]model.LogLevel{}, []string{}, "", 100, 0)
|
logs, err := app.LogService.Search([]model.LogLevel{}, []string{}, "", 100, 0)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logger.Fatalf("FATAL: Failed to fetch logs: %v\n", err)
|
logger.Fatalf("FATAL: Failed to fetch logs: %v\n", err)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,8 +6,14 @@ import (
|
||||||
"github.com/jmoiron/sqlx"
|
"github.com/jmoiron/sqlx"
|
||||||
|
|
||||||
"arimelody-web/model/twitch"
|
"arimelody-web/model/twitch"
|
||||||
|
|
||||||
|
logService "arimelody-web/service/log"
|
||||||
|
inviteService "arimelody-web/service/invite"
|
||||||
accountService "arimelody-web/service/account"
|
accountService "arimelody-web/service/account"
|
||||||
"arimelody-web/service/log"
|
sessionService "arimelody-web/service/session"
|
||||||
|
artistService "arimelody-web/service/artist"
|
||||||
|
releaseService "arimelody-web/service/release"
|
||||||
|
trackService "arimelody-web/service/track"
|
||||||
)
|
)
|
||||||
|
|
||||||
type (
|
type (
|
||||||
|
|
@ -45,10 +51,15 @@ type (
|
||||||
AppState struct {
|
AppState struct {
|
||||||
DB *sqlx.DB
|
DB *sqlx.DB
|
||||||
Config Config
|
Config Config
|
||||||
Log *log.LogService
|
|
||||||
Twitch *twitch.State
|
Twitch *twitch.State
|
||||||
PublicFS embed.FS
|
PublicFS embed.FS
|
||||||
|
|
||||||
|
LogService *logService.LogService
|
||||||
|
InviteService *inviteService.InviteService
|
||||||
AccountService *accountService.AccountService
|
AccountService *accountService.AccountService
|
||||||
|
SesisonService *sessionService.SessionService
|
||||||
|
ArtistService *artistService.ArtistService
|
||||||
|
ReleaseService *releaseService.ReleaseService
|
||||||
|
TrackService *trackService.TrackService
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
|
||||||
|
|
@ -7,11 +7,9 @@ import (
|
||||||
"strconv"
|
"strconv"
|
||||||
)
|
)
|
||||||
|
|
||||||
type (
|
type AccountRepositoryMemory struct {
|
||||||
AccountRepositoryMemory struct {
|
accounts []*model.Account
|
||||||
accounts []*model.Account
|
}
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
var _ AccountRepository = new(AccountRepositoryMemory)
|
var _ AccountRepository = new(AccountRepositoryMemory)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -8,11 +8,9 @@ import (
|
||||||
_ "github.com/lib/pq"
|
_ "github.com/lib/pq"
|
||||||
)
|
)
|
||||||
|
|
||||||
type (
|
type AccountRepositoryPostgres struct {
|
||||||
AccountRepositoryPostgres struct {
|
db *sqlx.DB
|
||||||
db *sqlx.DB
|
}
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
var _ AccountRepository = new(AccountRepositoryPostgres)
|
var _ AccountRepository = new(AccountRepositoryPostgres)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -8,11 +8,9 @@ import (
|
||||||
_ "github.com/lib/pq"
|
_ "github.com/lib/pq"
|
||||||
)
|
)
|
||||||
|
|
||||||
type (
|
type LogRepositoryPostgres struct {
|
||||||
LogRepositoryPostgres struct {
|
db *sqlx.DB
|
||||||
db *sqlx.DB
|
}
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
var _ LogRepository = new(LogRepositoryPostgres)
|
var _ LogRepository = new(LogRepositoryPostgres)
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue