mirror of
https://github.com/crawlab-team/crawlab.git
synced 2026-01-30 18:00:56 +01:00
- Refactored multiple controller methods to accept structured parameters for improved clarity and maintainability. - Consolidated error handling and response generation across various endpoints. - Updated function signatures to eliminate unnecessary context parameters and enhance type safety. - Improved consistency in response formatting and error handling across controllers. - Enhanced file handling methods to support multipart file uploads and directory operations more effectively.
33 lines
893 B
Go
33 lines
893 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 *Response[any], err error) {
|
|
return GetDataResponse[any](nil)
|
|
}
|