parent
48c056fb0b
commit
bb68ebffdd
@ -0,0 +1,23 @@
|
||||
/**
|
||||
* @Title:
|
||||
* @Description:
|
||||
* @Author: Yuki Wong(iyuki0430@msn.com)
|
||||
* @Update:
|
||||
* @Date: 2020/7/20 11:49
|
||||
* @File: AccountController.go
|
||||
* @Software: GoLand
|
||||
**/
|
||||
package AccountController
|
||||
|
||||
import (
|
||||
"dsSupport/MyModel/Account/AccountOpenAPI"
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
func Routers(r *gin.RouterGroup) {
|
||||
rr := r.Group("/openapi")
|
||||
|
||||
rr.POST("/account/login", AccountOpenAPI.Login)
|
||||
|
||||
return
|
||||
}
|
@ -0,0 +1,45 @@
|
||||
/**
|
||||
* @Title:
|
||||
* @Description:
|
||||
* @Author: Yuki Wong(iyuki0430@msn.com)
|
||||
* @Update:
|
||||
* @Date: 2020/7/20 11:49
|
||||
* @File: AccountDAO.go
|
||||
* @Software: GoLand
|
||||
**/
|
||||
package AccountDAO
|
||||
|
||||
import (
|
||||
"dsSupport/Utils/ConfigUtil"
|
||||
"dsSupport/Utils/DbUtil"
|
||||
"strings"
|
||||
)
|
||||
|
||||
//数据库
|
||||
var db = DbUtil.Engine
|
||||
|
||||
func Login(username string, password string) (bool, string) {
|
||||
var flag bool
|
||||
var msg string
|
||||
|
||||
if username != "" && password != ""{
|
||||
flag = false
|
||||
msg = "账号或密码不能为空"
|
||||
}
|
||||
|
||||
if len(ConfigUtil.AccountUsers) > 0 {
|
||||
for _, v := range ConfigUtil.AccountUsers {
|
||||
UserPwd := strings.Split(v, ":")
|
||||
if UserPwd[0] == username && UserPwd[1] == password {
|
||||
flag = true
|
||||
msg = "登陆成功"
|
||||
}
|
||||
}
|
||||
} else {
|
||||
flag = false
|
||||
msg = "配置文件错误"
|
||||
}
|
||||
|
||||
return flag, msg
|
||||
}
|
||||
|
@ -0,0 +1,62 @@
|
||||
/**
|
||||
* @Title:
|
||||
* @Description:
|
||||
* @Author: Yuki Wong(iyuki0430@msn.com)
|
||||
* @Update:
|
||||
* @Date: 2020/7/20 11:50
|
||||
* @File: AccountOpenAPI.go
|
||||
* @Software: GoLand
|
||||
**/
|
||||
package AccountOpenAPI
|
||||
|
||||
import (
|
||||
"dsSupport/MyModel/Account/AccountService"
|
||||
"dsSupport/MyModel/MySwagger"
|
||||
"github.com/gin-gonic/gin"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
// 后台登陆 godoc
|
||||
// @Summary 后台登陆
|
||||
// @Description json:"username" xorm:"not null comment('账号') VARCHAR(100)" example:"example"
|
||||
// @Description json:"password" xorm:"not null comment('密码') VARCHAR(100)" example:"123456"
|
||||
// @Tags account
|
||||
// @ID loginAccount
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param input body MySwagger.AccountSwag true "账号密码"
|
||||
// @Success 200 {object} MySwagger.Result
|
||||
// @Failure 400 {object} MySwagger.Result
|
||||
// @Router /v1/openapi/datasource/ReadESDoc [post]
|
||||
func Login(c *gin.Context) {
|
||||
var raw MySwagger.AccountSwag
|
||||
|
||||
if err := c.ShouldBindJSON(&raw); err != nil {
|
||||
c.JSON(http.StatusBadRequest, MySwagger.Result{Success: false, Message: "接入系统数据JSON格式错误"})
|
||||
return
|
||||
}
|
||||
username := raw.Username
|
||||
password := raw.Password
|
||||
|
||||
success, _ := AccountService.Login(username, password)
|
||||
|
||||
if success {
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"status" : "ok",
|
||||
"type" : "account",
|
||||
"currentAuthority" : username,
|
||||
})
|
||||
|
||||
return
|
||||
} else {
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"status" : "error",
|
||||
"type" : "account",
|
||||
"currentAuthority" : "guest",
|
||||
})
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
return
|
||||
}
|
@ -0,0 +1,21 @@
|
||||
/**
|
||||
* @Title:
|
||||
* @Description:
|
||||
* @Author: Yuki Wong(iyuki0430@msn.com)
|
||||
* @Update:
|
||||
* @Date: 2020/7/20 11:50
|
||||
* @File: AccountService.go
|
||||
* @Software: GoLand
|
||||
**/
|
||||
package AccountService
|
||||
|
||||
import (
|
||||
"dsSupport/MyModel/Account/AccountDAO"
|
||||
)
|
||||
|
||||
func Login(username string, password string) (bool, string) {
|
||||
result, message := AccountDAO.Login(username, password)
|
||||
|
||||
return result, message
|
||||
}
|
||||
|
@ -0,0 +1,16 @@
|
||||
/**
|
||||
* @Title: AccountSwag
|
||||
* @Description: 后台登陆查询条件
|
||||
* @Author: Yuki Wong(iyuki0430@msn.com)
|
||||
* @Update:
|
||||
* @Date: 2020/7/9 10:24
|
||||
* @File: Jyt2012Swag.go
|
||||
* @Software: GoLand
|
||||
**/
|
||||
package MySwagger
|
||||
|
||||
type AccountSwag struct {
|
||||
Username string `json:"username" xorm:"not null comment('账号') VARCHAR(100)" example:"example"`
|
||||
Password string `json:"password" xorm:"not null comment('密码') VARCHAR(100)" example:"123456"`
|
||||
}
|
||||
|
Loading…
Reference in new issue