This commit is contained in:
qaq
2025-07-02 23:11:07 +08:00
parent 94e01ae63b
commit f1cab0563a
16 changed files with 388 additions and 0 deletions
@@ -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()
}