Compare commits
3 Commits
bcaa023d3c
...
074b3f8f31
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
074b3f8f31 | ||
|
|
f8b3c10933 | ||
|
|
c11425dde7 |
@@ -1,7 +1,6 @@
|
|||||||
package logging
|
package logging
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
"log"
|
"log"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -38,7 +37,7 @@ func Infof(message string, v ...any) {
|
|||||||
if currentLevel > InfoLevel {
|
if currentLevel > InfoLevel {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
log.Printf("Info: %s", fmt.Sprintf(message, v...))
|
log.Printf("Info: "+message, v...)
|
||||||
}
|
}
|
||||||
|
|
||||||
func Debug(message string) {
|
func Debug(message string) {
|
||||||
@@ -52,7 +51,7 @@ func Debugf(message string, v ...any) {
|
|||||||
if currentLevel > DebugLevel {
|
if currentLevel > DebugLevel {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
log.Printf("Debug: %s", fmt.Sprintf(message, v...))
|
log.Printf("Debug: "+message, v...)
|
||||||
}
|
}
|
||||||
|
|
||||||
func Warn(message string) {
|
func Warn(message string) {
|
||||||
@@ -66,7 +65,7 @@ func Warnf(message string, v ...any) {
|
|||||||
if currentLevel > WarnLevel {
|
if currentLevel > WarnLevel {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
log.Printf("Warn: %s", fmt.Sprintf(message, v...))
|
log.Printf("Warn: "+message, v...)
|
||||||
}
|
}
|
||||||
|
|
||||||
func Error(message string) {
|
func Error(message string) {
|
||||||
@@ -80,7 +79,7 @@ func Errorf(message string, v ...any) {
|
|||||||
if currentLevel > ErrorLevel {
|
if currentLevel > ErrorLevel {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
log.Printf("Error: %s", fmt.Sprintf(message, v...))
|
log.Printf("Error: "+message, v...)
|
||||||
}
|
}
|
||||||
|
|
||||||
func Fatal(message string) {
|
func Fatal(message string) {
|
||||||
|
|||||||
@@ -228,10 +228,11 @@ func logoutHandler(w http.ResponseWriter, r *http.Request) {
|
|||||||
if exist {
|
if exist {
|
||||||
if r.FormValue("csrf_token") != sessionData.CSRFToken {
|
if r.FormValue("csrf_token") != sessionData.CSRFToken {
|
||||||
http.Error(w, "Unable to log user out", http.StatusForbidden)
|
http.Error(w, "Unable to log user out", http.StatusForbidden)
|
||||||
log.Printf("%s attempted to logout with invalid csrf token", sessionData.data.Username)
|
logging.Debugf("%s attempted to logout with invalid csrf token", sessionData.data.Username)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
logging.Infof("handling logout event for %s", sessionData.data.Username)
|
||||||
|
|
||||||
deleteSession(token)
|
deleteSession(token)
|
||||||
http.Redirect(w, r, "/login", http.StatusSeeOther)
|
http.Redirect(w, r, "/login", http.StatusSeeOther)
|
||||||
@@ -289,9 +290,9 @@ func logoHandler(w http.ResponseWriter, r *http.Request) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func cleanupSessions() {
|
func cleanupSessions() {
|
||||||
sessionMutex.Lock()
|
logging.Debug("Cleaning up stale session\n")
|
||||||
defer sessionMutex.Unlock()
|
|
||||||
|
|
||||||
|
sessionMutex.Lock()
|
||||||
sessions_to_delete := []string{}
|
sessions_to_delete := []string{}
|
||||||
for session_token, session_data := range sessions {
|
for session_token, session_data := range sessions {
|
||||||
timeUntilRemoval := time.Minute * 5
|
timeUntilRemoval := time.Minute * 5
|
||||||
@@ -302,8 +303,9 @@ func cleanupSessions() {
|
|||||||
sessions_to_delete = append(sessions_to_delete, session_token)
|
sessions_to_delete = append(sessions_to_delete, session_token)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
sessionMutex.Unlock()
|
||||||
for _, session_id := range sessions_to_delete {
|
for _, session_id := range sessions_to_delete {
|
||||||
delete(sessions, session_id)
|
deleteSession(session_id)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user