Skip to content

Commit

Permalink
Fix: Refactor setUserInfoHeaders to sendAuthResponse
Browse files Browse the repository at this point in the history
Renamed the setUserInfoHeaders function to sendAuthResponse for clarity and consolidated the functionality into a single method. Simplified comments and adjusted all references to reflect this change, improving the code's readability and maintainability.

Signed-off-by: Christian Roessner <c@roessner.co>
  • Loading branch information
Christian Roessner committed Nov 20, 2024
1 parent 4740087 commit 335b870
Showing 1 changed file with 6 additions and 9 deletions.
15 changes: 6 additions & 9 deletions server/core/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -583,7 +583,7 @@ func (a *AuthState) authOK(ctx *gin.Context) {
case global.ServDovecot:
setDovecotHeaders(ctx, a)
case global.ServUserInfo, global.ServJSON:
setUserInfoHeaders(ctx, a)
sendAuthResponse(ctx, a)
}

handleLogging(ctx, a)
Expand Down Expand Up @@ -727,11 +727,8 @@ func formatValues(values []any) []string {
return stringValues
}

// setUserInfoHeaders sets the necessary headers for the user info response.
// It includes the Content-Type header with the value "application/json; charset=UTF-8".
// It also includes the X-User-Found header with the string representation of a.UserFound.
// Finally, it uses ctx.JSON to send a JSON response with a status code of a.StatusCodeOK and a body of backend.PositivePasswordCache.
func setUserInfoHeaders(ctx *gin.Context, a *AuthState) {
// sendAuthResponse sends a JSON response with the appropriate headers and content based on the AuthState.
func sendAuthResponse(ctx *gin.Context, a *AuthState) {
ctx.Header("Content-Type", "application/json; charset=UTF-8")
ctx.JSON(a.StatusCodeOK, &backend.PositivePasswordCache{
AccountField: a.AccountField,
Expand Down Expand Up @@ -857,13 +854,13 @@ func (a *AuthState) setSMPTHeaders(ctx *gin.Context) {
}
}

// setUserInfoHeaders sets the necessary headers for UserInfo service in a Gin context
// sendAuthResponse sets the necessary headers for UserInfo service in a Gin context
// Usage example:
//
// func (a *AuthState) authTempFail(ctx *gin.Context, reason string) {
// ...
// if a.Service == global.ServUserInfo {
// a.setUserInfoHeaders(ctx, reason)
// a.sendAuthResponse(ctx, reason)
// return
// }
// ...
Expand All @@ -887,7 +884,7 @@ func (a *AuthState) setUserInfoHeaders(ctx *gin.Context, reason string) {
// If the service is "user", it also sets headers specific to user information.
// After setting the headers, it returns the appropriate response based on the service.
// If the service is not "user", it returns an internal server error response with the status message.
// If the service is "user", it calls the setUserInfoHeaders method to set additional headers and returns.
// If the service is "user", it calls the sendAuthResponse method to set additional headers and returns.
//
// Parameters:
// - ctx: The gin context object.
Expand Down

0 comments on commit 335b870

Please sign in to comment.