@@ -49,6 +49,37 @@ func (ag *AuthGroup) Login(c *gin.Context) {
|
||||
c.JSON(http.StatusOK, resp)
|
||||
}
|
||||
|
||||
// RegisterUser registers a new user with all permissions set to false.
|
||||
// @Summary Register user
|
||||
// @Description Registers a new user with login, password, name, last name. All permissions are set to false.
|
||||
// @Tags auth
|
||||
// @Accept json
|
||||
// @Param request body repository.UserRegister true "Registration data"
|
||||
// @Success 200 {object} map[string]string
|
||||
// @Failure 400 {object} map[string]string
|
||||
// @Failure 409 {object} map[string]string
|
||||
// @Failure 500 {object} map[string]string
|
||||
// @Router /auth/register [post]
|
||||
func (ag *AuthGroup) RegisterUser(c *gin.Context) {
|
||||
var req repository.UserRegister
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": "invalid request body"})
|
||||
return
|
||||
}
|
||||
|
||||
if ag.Repo.ExistsByLogin(req.Login) {
|
||||
c.JSON(http.StatusConflict, gin.H{"error": "login already exists"})
|
||||
return
|
||||
}
|
||||
|
||||
if _, err := ag.Repo.RegisterUser(req); err != nil {
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"error": "failed to register user"})
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(http.StatusOK, gin.H{"message": "user registered"})
|
||||
}
|
||||
|
||||
// CreateToken creates a new user.
|
||||
// @Summary Create user
|
||||
// @Description Creates a new user with permissions
|
||||
|
||||
Reference in New Issue
Block a user