mirror of
https://github.com/crawlab-team/crawlab.git
synced 2026-01-22 17:31:03 +01:00
- Updated multiple controller methods to return VoidResponse instead of generic Response[any]. - Consolidated error handling to utilize GetErrorVoidResponse for consistent error responses. - Enhanced parameter handling in export and file management functions for improved clarity and maintainability. - Refactored health check and login/logout methods to align with new response structure. - Improved overall consistency in response formatting across various endpoints.
33 lines
884 B
Go
33 lines
884 B
Go
package controllers
|
|
|
|
import (
|
|
"github.com/crawlab-team/crawlab/core/constants"
|
|
"github.com/crawlab-team/crawlab/core/errors"
|
|
"github.com/crawlab-team/crawlab/core/user"
|
|
"github.com/gin-gonic/gin"
|
|
)
|
|
|
|
type PostLoginParams struct {
|
|
Username string `json:"username" validate:"required"`
|
|
Password string `json:"password" validate:"required"`
|
|
}
|
|
|
|
func PostLogin(c *gin.Context, params *PostLoginParams) (response *Response[string], err error) {
|
|
userSvc, err := user.GetUserService()
|
|
if err != nil {
|
|
return GetErrorResponse[string](err)
|
|
}
|
|
|
|
token, loggedInUser, err := userSvc.Login(params.Username, params.Password)
|
|
if err != nil {
|
|
return GetErrorResponse[string](errors.ErrorUserUnauthorized)
|
|
}
|
|
|
|
c.Set(constants.UserContextKey, loggedInUser)
|
|
return GetDataResponse(token)
|
|
}
|
|
|
|
func PostLogout(_ *gin.Context) (response *VoidResponse, err error) {
|
|
return GetVoidResponse()
|
|
}
|