Files
crawlab/core/controllers/login.go
Marvin Zhang 931a36c8bf refactor: enhance parameter descriptions and standardize model fields
- Added descriptive annotations to various parameters across controllers to improve API documentation clarity.
- Standardized field definitions in models by including descriptions for better understanding of their purpose.
- Updated validation patterns for ID fields to ensure consistency and improve data integrity.
- Enhanced overall code readability and maintainability by aligning naming conventions and adding necessary comments.
2025-03-19 13:39:02 +08:00

33 lines
930 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" description:"Username" validate:"required"`
Password string `json:"password" description:"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()
}