parent
74b5bf24a8
commit
6539ae20fa
@ -0,0 +1,5 @@
|
||||
{
|
||||
"code": 40001,
|
||||
"msg": "UserName required",
|
||||
"error": "Key: 'UserLoginService.UserName' Error:Field validation for 'UserName' failed on the 'required' tag\nKey: 'UserLoginService.Password' Error:Field validation for 'Password' failed on the 'required' tag"
|
||||
}
|
@ -0,0 +1,18 @@
|
||||
POST http://127.0.0.1:5000/Api/V3/User/Login
|
||||
Accept: */*
|
||||
Cache-Control: no-cache
|
||||
|
||||
{}
|
||||
|
||||
<> 2019-11-05T074354.200.json
|
||||
|
||||
###
|
||||
|
||||
POST http://127.0.0.1:5000/Api/V3/User/Login
|
||||
Accept: */*
|
||||
Cache-Control: no-cache
|
||||
|
||||
<> 2019-11-05T074329.200.json
|
||||
|
||||
###
|
||||
|
@ -0,0 +1,25 @@
|
||||
package controllers
|
||||
|
||||
import (
|
||||
"Cloudreve/serializer"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"gopkg.in/go-playground/validator.v8"
|
||||
)
|
||||
|
||||
// ErrorResponse 返回错误消息
|
||||
func ErrorResponse(err error) serializer.Response {
|
||||
if ve, ok := err.(validator.ValidationErrors); ok {
|
||||
for _, e := range ve {
|
||||
return serializer.ParamErr(
|
||||
fmt.Sprintf("%s %s", e.Field, e.Tag),
|
||||
err,
|
||||
)
|
||||
}
|
||||
}
|
||||
if _, ok := err.(*json.UnmarshalTypeError); ok {
|
||||
return serializer.ParamErr("JSON类型不匹配", err)
|
||||
}
|
||||
|
||||
return serializer.ParamErr("参数错误", err)
|
||||
}
|
@ -0,0 +1,22 @@
|
||||
package controllers
|
||||
|
||||
import (
|
||||
"Cloudreve/serializer"
|
||||
"Cloudreve/service/user"
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
// UserLogin 用户登录
|
||||
func UserLogin(c *gin.Context) {
|
||||
var service service.UserLoginService
|
||||
if err := c.ShouldBindJSON(&service); err == nil {
|
||||
//res := service.Login(c)
|
||||
c.JSON(200, serializer.Response{
|
||||
Code: 0,
|
||||
Msg: "OK",
|
||||
})
|
||||
} else {
|
||||
c.JSON(200, ErrorResponse(err))
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,7 @@
|
||||
package service
|
||||
|
||||
// UserLoginService 管理用户登录的服务
|
||||
type UserLoginService struct {
|
||||
UserName string `form:"user_name" json:"user_name" binding:"required,min=5,max=30"`
|
||||
Password string `form:"password" json:"password" binding:"required,min=8,max=40"`
|
||||
}
|
Loading…
Reference in new issue