提交 600636a2 编写于 作者: Mr.奇淼('s avatar Mr.奇淼(

用户关联查询 jwt鉴权调整 api删除调整 authorityId默认类型调整

上级 38d951ee
......@@ -14,7 +14,7 @@ type CreateApiParams struct {
}
type DeleteApiParams struct {
Path uint `json:"path"`
ID uint `json:"id"`
}
// @Tags Api
......@@ -41,7 +41,7 @@ func CreateApi(c *gin.Context) {
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body api.DeleteApiParams true "删除api"
// @Param data body dbModel.Api true "删除api"
// @Success 200 {string} json "{"success":true,"data":{},"msg":"获取成功"}"
// @Router /api/deleteApi [post]
func DeleteApi(c *gin.Context) {
......@@ -56,8 +56,8 @@ func DeleteApi(c *gin.Context) {
}
type AuthAndPathIn struct {
AuthorityId string `json:"authorityId"`
ApiIds []uint `json:"apiIds"`
AuthorityId string `json:"authorityId"`
ApiIds []uint `json:"apiIds"`
}
// @Tags Api
......@@ -120,14 +120,12 @@ func GetApiById(c *gin.Context) {
servers.ReportFormat(c, false, fmt.Sprintf("获取数据失败,%v", err), gin.H{})
} else {
servers.ReportFormat(c, true, "获取数据成功", gin.H{
"api": api,
"api": api,
})
}
}
// @Tags Api
// @Summary 创建基础api
// @Security ApiKeyAuth
......@@ -136,16 +134,16 @@ func GetApiById(c *gin.Context) {
// @Param data body api.CreateApiParams true "创建api"
// @Success 200 {string} json "{"success":true,"data":{},"msg":"获取成功"}"
// @Router /api/updataApi [post]
func UpdataApi(c *gin.Context) {
var api dbModel.Api
_ = c.BindJSON(&api)
err := api.UpdataApi()
if err != nil {
servers.ReportFormat(c, false, fmt.Sprintf("修改数据失败,%v", err), gin.H{})
} else {
servers.ReportFormat(c, true, "修改数据成功", gin.H{})
}
}
func UpdataApi(c *gin.Context) {
var api dbModel.Api
_ = c.BindJSON(&api)
err := api.UpdataApi()
if err != nil {
servers.ReportFormat(c, false, fmt.Sprintf("修改数据失败,%v", err), gin.H{})
} else {
servers.ReportFormat(c, true, "修改数据成功", gin.H{})
}
}
// @Tags Api
// @Summary 获取所有的Api 不分页
......@@ -154,13 +152,13 @@ func GetApiById(c *gin.Context) {
// @Produce application/json
// @Success 200 {string} json "{"success":true,"data":{},"msg":"获取成功"}"
// @Router /api/getAllApis [post]
func GetAllApis(c *gin.Context){
err,apis := new(dbModel.Api).GetAllApis()
func GetAllApis(c *gin.Context) {
err, apis := new(dbModel.Api).GetAllApis()
if err != nil {
servers.ReportFormat(c, false, fmt.Sprintf("获取数据失败,%v", err), gin.H{})
} else {
servers.ReportFormat(c, true, "获取数据成功", gin.H{
"apis": apis,
"apis": apis,
})
}
}
\ No newline at end of file
}
......@@ -159,8 +159,8 @@ func UploadHeaderImg(c *gin.Context) {
// @Produce application/json
// @Param data body modelInterface.PageInfo true "分页获取用户列表"
// @Success 200 {string} json "{"success":true,"data":{},"msg":"获取成功"}"
// @Router /user/getInfoList [post]
func GetInfoList(c *gin.Context) {
// @Router /user/getUserList [post]
func GetUserList(c *gin.Context) {
var pageInfo modelInterface.PageInfo
_ = c.BindJSON(&pageInfo)
err, list, total := new(dbModel.User).GetInfoList(pageInfo)
......
......@@ -9,8 +9,8 @@ import (
"time"
)
var accessKey string = "25j8dYBZ2wui***************62b8xiFguwxzZ" // 你在七牛云的accessKey
var secretKey string = "pgdbqEsf7ooZ***************_VecFXPDeG5JY" // 你在七牛云的secretKey
var accessKey string = "25j8dYBZ2wuiy0yhwShytjZDTX662b8xiFguwxzZ" // 你在七牛云的accessKey 这里是我个人测试号的key 仅供测试使用 恳请大家不要乱传东西
var secretKey string = "pgdbqEsf7ooZh7W3xokP833h3dZ_VecFXPDeG5JY" // 你在七牛云的secretKey 这里是我个人测试号的key 仅供测试使用 恳请大家不要乱传东西
// 接收两个参数 一个文件流 一个 bucket 你的七牛云标准空间的名字
func Upload(file *multipart.FileHeader, bucket string, urlPath string) (err error, path string) {
......
......@@ -12,10 +12,10 @@ import (
)
type SqlRes struct {
Path string
Path string
AuthorityId string
ApiId uint
Id uint
ApiId uint
Id uint
}
func JWTAuth() gin.HandlerFunc {
......@@ -32,7 +32,9 @@ func JWTAuth() gin.HandlerFunc {
claims, err := j.ParseToken(token)
if err != nil {
if err == TokenExpired {
servers.ReportFormat(c, false, "授权已过期", gin.H{})
servers.ReportFormat(c, false, "授权已过期", gin.H{
"reload": true,
})
c.Abort()
return
}
......@@ -41,9 +43,9 @@ func JWTAuth() gin.HandlerFunc {
return
}
var sqlRes SqlRes
row:=qmsql.DEFAULTDB.Raw("SELECT apis.path,api_authorities.authority_id,api_authorities.api_id,apis.id FROM apis INNER JOIN api_authorities ON api_authorities.api_id = apis.id WHERE apis.path = ? AND api_authorities.authority_id = ?",c.Request.RequestURI,claims.AuthorityId)
err=row.Scan(&sqlRes).Error
if(fmt.Sprintf("%v",err) == "record not found"){
row := qmsql.DEFAULTDB.Raw("SELECT apis.path,api_authorities.authority_id,api_authorities.api_id,apis.id FROM apis INNER JOIN api_authorities ON api_authorities.api_id = apis.id WHERE apis.path = ? AND api_authorities.authority_id = ?", c.Request.RequestURI, claims.AuthorityId)
err = row.Scan(&sqlRes).Error
if fmt.Sprintf("%v", err) == "record not found" {
servers.ReportFormat(c, false, "没有Api操作权限", gin.H{})
c.Abort()
return
......@@ -68,7 +70,7 @@ type CustomClaims struct {
UUID uuid.UUID
ID uint
NickName string
AuthorityId float64
AuthorityId string
jwt.StandardClaims
}
......
......@@ -26,7 +26,8 @@ func (a *Api) CreateApi() (err error) {
}
func (a *Api) DeleteApi() (err error) {
err = qmsql.DEFAULTDB.Where("path = ?", a.Path).Delete(a).Delete(&ApiAuthority{}).Error
err = qmsql.DEFAULTDB.Delete(a).Error
err = qmsql.DEFAULTDB.Where("api_id = ?", a.ID).Unscoped().Delete(&ApiAuthority{}).Error
return err
}
......@@ -35,17 +36,17 @@ func (a *Api) UpdataApi() (err error) {
return err
}
func (a *Api) GetApiById(id float64)(err error,api Api){
err = qmsql.DEFAULTDB.Where("id = ?",id).First(&api).Error
func (a *Api) GetApiById(id float64) (err error, api Api) {
err = qmsql.DEFAULTDB.Where("id = ?", id).First(&api).Error
return
}
// 获取所有api信息
func (a *Api)GetAllApis()(err error,apis []Api){
func (a *Api) GetAllApis() (err error, apis []Api) {
err = qmsql.DEFAULTDB.Find(&apis).Error
return
}
// 分页获取数据 需要分页实现这个接口即可
func (a *Api) GetInfoList(info modelInterface.PageInfo) (err error, list interface{}, total int) {
// 封装分页方法 调用即可 传入 当前的结构体和分页信息
......@@ -54,7 +55,7 @@ func (a *Api) GetInfoList(info modelInterface.PageInfo) (err error, list interfa
return
} else {
var apiList []Api
err = db.Order("group",true).Find(&apiList).Error
err = db.Order("group", true).Find(&apiList).Error
return err, apiList, total
}
}
......@@ -42,7 +42,7 @@ func (m *Menu) GetMenuAuthority(authorityId string) (err error, menus []Menu) {
}
//获取动态路由树
func (m *Menu) GetMenuTree(authorityId float64) (err error, menus []Menu) {
func (m *Menu) GetMenuTree(authorityId string) (err error, menus []Menu) {
err = qmsql.DEFAULTDB.Where("authority_id = ? AND parent_id = ?", authorityId, 0).Find(&menus).Error
for i := 0; i < len(menus); i++ {
err = getChildrenList(&menus[i])
......
......@@ -13,12 +13,12 @@ import (
type User struct {
gorm.Model `json:"-"`
UUID uuid.UUID `json:"uuid"`
Username string `json:"-"`
Username string `json:"userName"`
Password string `json:"-"`
NickName string `json:"nickName" gorm:"default:'QMPlusUser'"`
HeaderImg string `json:"headerImg" gorm:"default:'http://www.henrongyi.top/avatar/lufu.jpg'"`
Authority Authority `json:"authority" form:"ForeignKey:authority_id;AssociationForeignKey:authority_id"`
AuthorityId float64 `json:"-" gorm:"default:888"`
Authority Authority `json:"authority" gorm:"ForeignKey:AuthorityId;AssociationForeignKey:AuthorityId"`
AuthorityId string `json:"-" gorm:"default:888"`
//Propertie // 多余属性自行添加
//PropertieId uint // 自动关联 Propertie 的Id 附加属性过多 建议创建一对一关系
}
......@@ -83,7 +83,7 @@ func (u *User) GetInfoList(info modelInterface.PageInfo) (err error, list interf
return
} else {
var userList []User
err = db.Find(&userList).Error
err = db.Preload("Authority").Find(&userList).Error
return err, userList, total
}
}
......@@ -9,8 +9,8 @@ import (
func InitUserRouter(Router *gin.Engine) {
UserRouter := Router.Group("user").Use(middleware.JWTAuth())
{
UserRouter.POST("changePassword", api.ChangePassword) // 修改密码
UserRouter.POST("changePassword", api.ChangePassword) // 修改密码
UserRouter.POST("uploadHeaderImg", api.UploadHeaderImg) //上传头像
UserRouter.POST("getInfoList", api.GetInfoList) // 分页获取用户列表
UserRouter.POST("getUserList", api.GetUserList) // 分页获取用户列表
}
}
......@@ -24,7 +24,7 @@
2.用户等基础数据CURD √
3.调用des实现数据加密 √
4.实现基于jwt的权限管理
5.实现基于七牛云的文件上传操作(需提前注册七牛云账号) √
5.实现基于七牛云的文件上传操作(需提前注册七牛云账号) √(为了方便大家测试,我公开了自己的七牛测试号的各种重要token,恳请大家不要乱传东西)
6.等装了分页方法,实现分页接口并且复制粘贴就可使用分页 √
7.前端分页mixin封装 分页方法调用mixins即可 √
8...看项目进度想到什么做什么,主要目的是方便各位快速接私活,完成项目基础功能
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册