fixed a bug that stopped sessions from being deleted
This commit is contained in:
@@ -9,6 +9,7 @@ type EventType int
|
|||||||
|
|
||||||
const (
|
const (
|
||||||
ReadFile EventType = iota
|
ReadFile EventType = iota
|
||||||
|
AuthenticateUser
|
||||||
)
|
)
|
||||||
|
|
||||||
func Info(message string) {
|
func Info(message string) {
|
||||||
@@ -58,5 +59,10 @@ func Event(eventType EventType, eventData ...any) {
|
|||||||
log.Printf("Reading file %s", eventData[0])
|
log.Printf("Reading file %s", eventData[0])
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
case AuthenticateUser:
|
||||||
|
{
|
||||||
|
log.Printf("Authenticating user %s", eventData[0])
|
||||||
|
break
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -57,6 +57,7 @@ func createUserPhoto(username string, photoData []byte) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func authenticateUser(username, password string) (UserData, error) {
|
func authenticateUser(username, password string) (UserData, error) {
|
||||||
|
logging.Event(logging.AuthenticateUser, username)
|
||||||
ldapServerMutex.Lock()
|
ldapServerMutex.Lock()
|
||||||
defer ldapServerMutex.Unlock()
|
defer ldapServerMutex.Unlock()
|
||||||
if ldapServer.Connection == nil {
|
if ldapServer.Connection == nil {
|
||||||
@@ -232,9 +233,7 @@ func logoutHandler(w http.ResponseWriter, r *http.Request) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
sessionMutex.Lock()
|
deleteSession(token)
|
||||||
delete(sessions, token)
|
|
||||||
sessionMutex.Unlock()
|
|
||||||
http.Redirect(w, r, "/login", http.StatusSeeOther)
|
http.Redirect(w, r, "/login", http.StatusSeeOther)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -94,3 +94,13 @@ func validateSession(r *http.Request) (bool, *SessionData) {
|
|||||||
logging.Infof("Validated session for %s", sessionData.data.Username)
|
logging.Infof("Validated session for %s", sessionData.data.Username)
|
||||||
return true, &sessionData
|
return true, &sessionData
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func deleteSession(session_id string) {
|
||||||
|
sessionMutex.Lock()
|
||||||
|
|
||||||
|
tokenEncoded := sha256.Sum256([]byte(session_id))
|
||||||
|
tokenEncodedString := string(tokenEncoded[:])
|
||||||
|
|
||||||
|
delete(sessions, tokenEncodedString)
|
||||||
|
sessionMutex.Unlock()
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user