54 lines
1017 B
Go
54 lines
1017 B
Go
package api
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
"gopkg.in/validator.v2"
|
|
)
|
|
|
|
func (s *Service) Login(c *gin.Context) {
|
|
c.JSON(http.StatusNotImplemented, gin.H{
|
|
"status": "todo",
|
|
})
|
|
}
|
|
|
|
func (s *Service) Logout(c *gin.Context) {
|
|
c.JSON(http.StatusNotImplemented, gin.H{
|
|
"status": "todo",
|
|
})
|
|
}
|
|
|
|
type SignupRequest struct {
|
|
Login string `validate:"min=3,max=40,regexp=^[a-zA-Z0-9]*$"`
|
|
Password string `validate:"min=8,max=40"`
|
|
}
|
|
|
|
func (s *Service) Signup(c *gin.Context) {
|
|
var account *SignupRequest
|
|
|
|
if c.Request.ContentLength == 0 {
|
|
c.AbortWithStatusJSON(http.StatusBadRequest, gin.H{
|
|
"error": "missing body",
|
|
})
|
|
return
|
|
}
|
|
|
|
if err := c.ShouldBindJSON(&account); err != nil {
|
|
c.AbortWithStatusJSON(http.StatusBadRequest, gin.H{
|
|
"error": err.Error(),
|
|
})
|
|
return
|
|
}
|
|
if err := validator.Validate(account); err != nil {
|
|
c.AbortWithStatusJSON(http.StatusBadRequest, gin.H{
|
|
"error": err.Error(),
|
|
})
|
|
return
|
|
}
|
|
|
|
c.JSON(http.StatusOK, gin.H{
|
|
"status": "success",
|
|
})
|
|
}
|