mirror of
https://github.com/Sagit-chu/flvx.git
synced 2026-10-04 17:16:37 +08:00
暂存
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
package controllers
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"github.com/beego/beego/v2/server/web"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
type BaseController struct {
|
||||
web.Controller
|
||||
}
|
||||
|
||||
func (c *BaseController) ServeJSON() {
|
||||
c.Ctx.Output.Header("Content-Type", "application/json; charset=utf-8")
|
||||
|
||||
var err error
|
||||
|
||||
data := c.Data["json"]
|
||||
|
||||
encoder := json.NewEncoder(c.Ctx.Output.Context.ResponseWriter)
|
||||
encoder.SetEscapeHTML(false)
|
||||
|
||||
encoder.SetIndent("", " ")
|
||||
err = encoder.Encode(data)
|
||||
|
||||
if err != nil {
|
||||
http.Error(c.Ctx.Output.Context.ResponseWriter, err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
package controllers
|
||||
|
||||
import (
|
||||
"beego-backend/common"
|
||||
"beego-backend/models/users"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
type LoginController struct {
|
||||
BaseController
|
||||
}
|
||||
|
||||
// @router /login_by_pwd [post]
|
||||
func (c *LoginController) LoginByPwd() {
|
||||
var Data users.LoginModel
|
||||
err := json.Unmarshal(c.Ctx.Input.RequestBody, &Data)
|
||||
if err != nil {
|
||||
Result := common.ResponseResult{
|
||||
Code: -1,
|
||||
Success: false,
|
||||
Message: fmt.Sprintf("系统异常:%v", err.Error()),
|
||||
Data: nil,
|
||||
}
|
||||
c.Data["json"] = &Result
|
||||
c.ServeJSON()
|
||||
return
|
||||
}
|
||||
result := users.LoginByPassword(Data)
|
||||
c.Data["json"] = &result
|
||||
c.ServeJSON()
|
||||
}
|
||||
Reference in New Issue
Block a user