You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

192 lines
5.7 KiB

package ControllerSso
import (
"dsSso/Model"
"dsSso/Service/ServiceJoinApp"
"dsSso/Utils/ConvertUtil"
"github.com/gin-gonic/gin"
"net/http"
)
//模块的路由配置
func Routers(r *gin.RouterGroup) {
rr := r.Group("")
//用于统一认证管理员登录
rr.GET("/login", login)
//列表
rr.GET("/getJoinAppList", GetJoinAppList)
//新增
rr.POST("/addJoinApp", AddJoinApp)
//修改
rr.POST("/updateJoinApp", UpdateJoinApp)
//删除
rr.POST("/deleteJoinAppById", DeleteJoinAppById)
//根据appId获取接入第三方统一认证系统的信息
rr.GET("/getJoinAppInfoById", GetJoinAppInfoById)
return
}
// @Summary 接入系统管理中心维护的路由跳转
// @Description manager dsideal4r5t6y7u 为统一认证管理员默认帐号
// @Tags 接入系统维护类
// @Accept application/x-www-form-urlencoded
// @Produce json
// @Success 200 {string} string
// @Router /sso/login [get]
func login(c *gin.Context) {
//如果没有本domain下的cookie,那么跳转到登录页
url := "/sso/static/index.html"
c.Redirect(302, url)
}
// @Summary 获取接入系统的列表
// @Description 获取接入系统的列表
// @Tags 接入系统维护类
// @Accept application/x-www-form-urlencoded
// @Produce json
// @Param limit query int true "每页多少条数据"
// @Param page query int true "显示第几页"
// @Param keyword query string false "搜索的关键词"
// @Success 200 {object} Model.Res
// @Router /sso/getJoinAppList [get]
// @X-IntLimit ["limit","page"]
// @X-LengthLimit [{"keyword":"0,20"}]
func GetJoinAppList(c *gin.Context) {
page := ConvertUtil.StringToInt(c.Query("page"))
limit := ConvertUtil.StringToInt(c.Query("limit"))
keyword := c.Query("keyword")
//获取数据
list, count := ServiceJoinApp.GetJoinAppList(page, limit, keyword)
c.JSON(http.StatusOK, Model.Res{
Code: http.StatusOK,
Msg: "获取列表成功!",
Items: list,
TotalCount: count,
})
return
}
// @Summary 增加一条接入系统的记录
// @Description 增加一条接入系统的记录
// @Tags 接入系统维护类
// @Accept application/x-www-form-urlencoded
// @Produce json
// @Param app_name formData string true "系统名称"
// @Param redirect_uri formData string true "回调的地址"
// @Success 200 {object} Model.Res
// @Router /sso/addJoinApp [post]
// @X-LengthLimit [{"app_name":"1,30"},{"redirect_uri_1":"8,100"},{"redirect_uri_2":"8,100"}]
func AddJoinApp(c *gin.Context) {
//接收参数
appName := c.PostForm("app_name")
redirectUri := c.PostForm("redirect_uri")
//调用 Service进行插入
success := ServiceJoinApp.AddJoinApp(appName, redirectUri)
if !success {
c.JSON(http.StatusOK, Model.Res{
Code: http.StatusRequestedRangeNotSatisfiable,
Msg: "新增接入系统出错,请联系研发人员检查!",
})
return
}
c.JSON(http.StatusOK, Model.Res{
Code: http.StatusOK,
Msg: "操作成功!",
})
return
}
// @Summary 修改一条接入系统的记录
// @Description 修改一条接入系统的记录
// @Tags 接入系统维护类
// @Accept application/x-www-form-urlencoded
// @Produce json
// @Param app_id formData string false "系统app_id"
// @Param app_name formData string true "系统名称"
// @Param redirect_uri formData string true "回调的地址"
// @Success 200 {object} Model.Res
// @Router /sso/updateJoinApp [post]
// @X-IntLimit ["app_id"]
// @X-LengthLimit [{"app_name":"1,30"},{"redirect_uri_1":"8,100"},{"redirect_uri_2":"8,100"}]
func UpdateJoinApp(c *gin.Context) {
//接收参数
systemId := c.PostForm("app_id")
systemName := c.PostForm("app_name")
redirectUri := c.PostForm("redirect_uri")
//调用 Service进行插入
success := ServiceJoinApp.UpdateJoinApp(systemId, systemName, redirectUri)
if !success {
c.JSON(http.StatusOK, Model.Res{
Code: http.StatusNotImplemented,
Msg: "修改统一认证系统出错,请检查参数输入是否正确!",
})
return
}
c.JSON(http.StatusOK, Model.Res{
Code: http.StatusOK,
Msg: "操作成功!",
})
return
}
// @Summary 删除一条统一认证系统的记录
// @Description 删除一条统一认证系统的记录
// @Tags 接入系统维护类
// @Accept application/x-www-form-urlencoded
// @Produce json
// @Param app_id formData string true "系统app_id"
// @Success 200 {object} Model.Res
// @Router /sso/deleteJoinAppById [post]
// @X-IntLimit ["app_id"]
func DeleteJoinAppById(c *gin.Context) {
//接收参数
appId := c.PostForm("app_id")
//检查参数的合法性
success := ServiceJoinApp.DeleteJoinAppById(appId)
if !success {
c.JSON(http.StatusOK, Model.Res{
Code: http.StatusInternalServerError,
Msg: "删除统一认证系统出错,请检查参数是否正确!",
})
return
}
c.JSON(http.StatusOK, Model.Res{
Code: http.StatusOK,
Msg: "操作成功!",
})
return
}
// @Summary 根据appId获取接入第三方统一认证系统的信息
// @Description 根据appId获取接入第三方统一认证系统的信息
// @Tags 接入系统维护类
// @Accept application/x-www-form-urlencoded
// @Produce json
// @Param app_id query string true "系统app_id"
// @Success 200 {object} Model.AppInfo
// @Router /sso/getJoinAppInfoById [get]
// @X-IntLimit ["app_id"]
func GetJoinAppInfoById(c *gin.Context) {
//接收参数
appId := c.Query("app_id")
//获取信息
res := ServiceJoinApp.GetJoinAppInfoById(appId)
if res != nil {
c.JSON(http.StatusOK, Model.AppInfo{
Code: http.StatusOK,
AppKey: res["app_key"].(string),
AppName: res["app_name"].(string),
AppSecret: res["app_secret"].(string),
RedirectUri: res["redirect_uri"].(string),
Msg: "获取信息成功!",
})
} else
{
c.JSON(http.StatusOK, Model.Res{
Code: http.StatusInternalServerError,
Msg: "未查询到数据!",
})
}
return
}