mirror of
https://github.com/crawlab-team/crawlab.git
synced 2026-01-27 17:50:53 +01:00
- 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.
33 lines
930 B
Go
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()
|
|
}
|