123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899 |
- /*
- * @description: api 登陆接口相关
- * @Author: CP
- * @Date: 2020-09-17 16:23:02
- * @FilePath: \construction_management\web\api\login_api.go
- */
- package api
- import (
- "fmt"
- "github.com/kataras/iris/v12"
- "go.mod/services"
- "go.mod/web/utils"
- "go.mod/web/viewmodels"
- )
- type LoginApi struct {
- //框架-web应用上下文环境
- Ctx iris.Context
- // 需要用的service
- ServiceProjectAccount services.ProjectAccountService
- ServiceLogin services.LoginService
- ServiceProject services.ProjectService
- }
- // @Summary 登录
- // @Description 登录接口
- // @Tags 登录/登出
- // @Accept json
- // @Produce json
- // @Param code body string true "项目编号" default(234)
- // @Param account body string true "项目账号" default(caipin)
- // @Param password body string true "密码" default(123456)
- // @Success 200 {object} viewmodels.ProjectAccount "{code:0成功,data:viewmodels.ProjectAccount,msg:}"
- // @Failure 400 {string} string "{code:-1参数类错误,msg:错误信息}"
- // @Router /api/login [post]
- func (c *LoginApi) Post() {
- //验证规则
- LoginData, err := c.ServiceLogin.ValidRule(c.Ctx)
- if err != nil {
- ErrMsg := utils.FormValidError(err)
- c.Ctx.JSON(iris.Map{"code": -1, "msg": ErrMsg})
- return
- }
- //验证登陆用户
- Data, err := c.ServiceLogin.ValidProjectAccount(LoginData, c.Ctx.ResponseWriter())
- if err != nil {
- c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)})
- return
- }
- c.Ctx.JSON(iris.Map{
- "code": 0,
- "msg": "",
- "data": Data,
- })
- }
- // @Summary 登出
- // @Tags 登录/登出
- // @Accept json
- // @Produce json
- // @Success 200 {string} string "{code:0,msg:string}"
- // @Failure 400 {string} string "{code:-1,msg:string}"
- // @Router /api/login/out [post]
- func (c *LoginApi) GetOut() {
- c.ServiceLogin.Out(c.Ctx)
- c.Ctx.JSON(iris.Map{"code": 0, "msg": ""})
- }
- // @Summary 获得项目名称
- // @Tags 登录/登出
- // @Accept json
- // @Produce json
- // @Param code query string true "项目编号" default({code:2})
- // @Success 200 {object} viewmodels.Project "{code:0成功,data:viewmodels.Project,msg:}"
- // @Failure 400 {string} string "{code:-1,msg:string}"
- // @Router /api/login/project/name [get]
- func (c *LoginApi) GetProjectName() {
- // 验证内容
- ProjectData := viewmodels.Project{}
- err := c.Ctx.ReadForm(&ProjectData)
- if err != nil {
- c.Ctx.JSON(iris.Map{
- "code": -1,
- "msg": "ReadJSON转换异常,请检查code",
- })
- return
- } else {
- // 获得项目信息
- dataList := c.ServiceProject.GetName(ProjectData.Code)
- c.Ctx.JSON(iris.Map{
- "code": 0,
- "msg": "",
- "data": dataList,
- })
- }
- }
|