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
|
||||
}
|
||||
|
||||
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.SetSessionMessage(app.DB, session, "Password updated successfully.")
|
||||
|
|
@ -145,7 +145,7 @@ func deleteAccountHandler(app *app.AppState) http.Handler {
|
|||
|
||||
// check password
|
||||
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.")
|
||||
http.Redirect(w, r, "/admin/account", http.StatusFound)
|
||||
return
|
||||
|
|
@ -159,7 +159,7 @@ func deleteAccountHandler(app *app.AppState) http.Handler {
|
|||
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.SetSessionError(app.DB, session, "")
|
||||
|
|
@ -310,7 +310,7 @@ func totpConfirmHandler(app *app.AppState) http.Handler {
|
|||
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.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
|
||||
}
|
||||
|
||||
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.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
|
||||
}
|
||||
|
||||
app.Log.Info(
|
||||
app.LogService.Info(
|
||||
model.LOG_ACCOUNT,
|
||||
"Account \"%s\" (%s) created using invite \"%s\". (%s)",
|
||||
credentials.Username,
|
||||
|
|
@ -252,7 +252,7 @@ func registerAccountHandler(app *app.AppState) http.Handler {
|
|||
|
||||
err = controller.DeleteInvite(app.DB, invite.Code)
|
||||
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!
|
||||
|
|
@ -332,7 +332,7 @@ func loginHandler(app *app.AppState) http.Handler {
|
|||
|
||||
err = bcrypt.CompareHashAndPassword([]byte(account.Password), []byte(password))
|
||||
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 {
|
||||
controller.SetSessionError(app.DB, session, "Too many failed attempts. This account is now locked.")
|
||||
} else {
|
||||
|
|
@ -366,8 +366,8 @@ func loginHandler(app *app.AppState) http.Handler {
|
|||
|
||||
// login success!
|
||||
// TODO: log login activity to user
|
||||
app.Log.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.Info(model.LOG_ACCOUNT, "\"%s\" logged in. (%s)", account.Username, controller.ResolveIP(app, r))
|
||||
app.LogService.Warn(model.LOG_ACCOUNT, "\"%s\" does not have any TOTP methods assigned.", account.Username)
|
||||
|
||||
err = controller.SetSessionAccount(app.DB, session, account)
|
||||
if err != nil {
|
||||
|
|
@ -420,7 +420,7 @@ func loginTOTPHandler(app *app.AppState) http.Handler {
|
|||
totpCode := r.FormValue("totp")
|
||||
|
||||
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.")
|
||||
render()
|
||||
return
|
||||
|
|
@ -434,7 +434,7 @@ func loginTOTPHandler(app *app.AppState) http.Handler {
|
|||
return
|
||||
}
|
||||
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 {
|
||||
controller.SetSessionError(app.DB, session, "Too many failed attempts. This account is now locked.")
|
||||
controller.SetSessionAttemptAccount(app.DB, session, nil)
|
||||
|
|
@ -446,7 +446,7 @@ func loginTOTPHandler(app *app.AppState) http.Handler {
|
|||
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)
|
||||
if err != nil {
|
||||
|
|
@ -574,7 +574,7 @@ func handleFailedLogin(app *app.AppState, account *model.Account, r *http.Reques
|
|||
account.Username,
|
||||
err,
|
||||
)
|
||||
app.Log.Warn(
|
||||
app.LogService.Warn(
|
||||
model.LOG_ACCOUNT,
|
||||
"Failed to lock account \"%s\"",
|
||||
account.Username,
|
||||
|
|
@ -588,7 +588,7 @@ func handleFailedLogin(app *app.AppState, account *model.Account, r *http.Reques
|
|||
model.MAX_LOGIN_FAIL_ATTEMPTS,
|
||||
controller.ResolveIP(app, r),
|
||||
)
|
||||
app.Log.Warn(
|
||||
app.LogService.Warn(
|
||||
model.LOG_ACCOUNT,
|
||||
"Account \"%s\" was locked: %d failed login attempts (IP: %s)",
|
||||
account.Username,
|
||||
|
|
@ -606,7 +606,7 @@ func handleFailedLogin(app *app.AppState, account *model.Account, r *http.Reques
|
|||
account.Username,
|
||||
err,
|
||||
)
|
||||
app.Log.Warn(
|
||||
app.LogService.Warn(
|
||||
model.LOG_ACCOUNT,
|
||||
"Failed to increment login failures for \"%s\"",
|
||||
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 {
|
||||
fmt.Fprintf(os.Stderr, "WARN: Failed to fetch audit logs: %v\n", err)
|
||||
http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue