Skip to content

Commit

Permalink
用户头像由上传模式改为 媒体库选择模式
Browse files Browse the repository at this point in the history
  • Loading branch information
QM303176530 committed Aug 31, 2020
1 parent ad17cb8 commit dda3f7a
Show file tree
Hide file tree
Showing 13 changed files with 109 additions and 661 deletions.
1 change: 0 additions & 1 deletion server/GORMV2接口测试文档.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
| /menu/updateBaseMenu | 更新菜单 || SliverHorn |
| /menu/getBaseMenuById | 根据id获取菜单 || SliverHorn |
| /user/changePassword | 修改密码 || SliverHorn |
| /user/uploadHeaderImg | 上传头像 || SliverHorn |
| /user/getUserList | 获取用户列表 || SliverHorn |
| /user/setUserAuthority | 修改用户角色 || SliverHorn |
| /fileUploadAndDownload/upload | 文件上传示例 || SliverHorn |
Expand Down
67 changes: 22 additions & 45 deletions server/api/v1/sys_user.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ func tokenNext(c *gin.Context, user model.SysUser) {
NickName: user.NickName,
Username: user.Username,
AuthorityId: user.AuthorityId,
BufferTime: 60*60*24, // 缓冲时间1天 缓冲时间内会获得新的token刷新令牌 此时一个用户会存在两个有效令牌 但是前端只留一个 另一个会丢失
BufferTime: 60 * 60 * 24, // 缓冲时间1天 缓冲时间内会获得新的token刷新令牌 此时一个用户会存在两个有效令牌 但是前端只留一个 另一个会丢失
StandardClaims: jwt.StandardClaims{
NotBefore: time.Now().Unix() - 1000, // 签名生效时间
ExpiresAt: time.Now().Unix() + 60*60*24*7, // 过期时间 7天
Expand Down Expand Up @@ -174,50 +174,6 @@ type UserHeaderImg struct {
HeaderImg multipart.File `json:"headerImg"`
}

// @Tags SysUser
// @Summary 用户上传头像
// @Security ApiKeyAuth
// @accept multipart/form-data
// @Produce application/json
// @Param headerImg formData file true "用户上传头像"
// @Param username formData string true "用户上传头像"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"上传成功"}"
// @Router /user/uploadHeaderImg [post]
func UploadHeaderImg(c *gin.Context) {
claims, _ := c.Get("claims")
// 获取头像文件
// 这里我们通过断言获取 claims内的所有内容
waitUse := claims.(*request.CustomClaims)
uuid := waitUse.UUID
_, header, err := c.Request.FormFile("headerImg")
// 便于找到用户 以后从jwt中取
if err != nil {
response.FailWithMessage(fmt.Sprintf("上传文件失败,%v", err), c)
} else {
// 文件上传后拿到文件路径
var uploadErr error
var filePath string
if global.GVA_CONFIG.LocalUpload.Local {
// 本地上传
uploadErr, filePath, _ = utils.UploadAvatarLocal(header)
} else {
// 七牛云上传
uploadErr, filePath, _ = utils.UploadRemote(header)
}
if uploadErr != nil {
response.FailWithMessage(fmt.Sprintf("接收返回值失败,%v", err), c)
} else {
// 修改数据库后得到修改后的user并且返回供前端使用
err, user := service.UploadHeaderImg(uuid, filePath)
if err != nil {
response.FailWithMessage(fmt.Sprintf("修改数据库链接失败,%v", err), c)
} else {
response.OkWithData(resp.SysUserResponse{User: *user}, c)
}
}
}
}

// @Tags SysUser
// @Summary 分页获取用户列表
// @Security ApiKeyAuth
Expand Down Expand Up @@ -298,3 +254,24 @@ func DeleteUser(c *gin.Context) {
response.OkWithMessage("删除成功", c)
}
}

// @Tags SysUser
// @Summary 删除用户
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body model.SysUser true "删除用户"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"修改成功"}"
// @Router /user/setUserInfo [put]
func SetUserInfo(c *gin.Context) {
var user model.SysUser
c.ShouldBindJSON(&user)
err, ReqUser := service.SetUserInfo(user)
if err != nil {
response.FailWithMessage(fmt.Sprintf("更新失败,%v", err), c)
} else {
response.OkWithData(gin.H{
"userInfo": ReqUser,
}, c)
}
}
134 changes: 25 additions & 109 deletions server/db/qmplus.sql

Large diffs are not rendered by default.

6 changes: 0 additions & 6 deletions server/db/sqlite/casbin_rule.sql
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,6 @@ INSERT INTO casbin_rule (p_type,v0,v1,v2,v3,v4,v5) VALUES (
INSERT INTO casbin_rule (p_type,v0,v1,v2,v3,v4,v5) VALUES (
'p','8881','/user/changePassword','POST','','','');
INSERT INTO casbin_rule (p_type,v0,v1,v2,v3,v4,v5) VALUES (
'p','8881','/user/uploadHeaderImg','POST','','','');
INSERT INTO casbin_rule (p_type,v0,v1,v2,v3,v4,v5) VALUES (
'p','8881','/user/getInfoList','POST','','','');
INSERT INTO casbin_rule (p_type,v0,v1,v2,v3,v4,v5) VALUES (
'p','8881','/user/getUserList','POST','','','');
Expand Down Expand Up @@ -121,8 +119,6 @@ INSERT INTO casbin_rule (p_type,v0,v1,v2,v3,v4,v5) VALUES (
INSERT INTO casbin_rule (p_type,v0,v1,v2,v3,v4,v5) VALUES (
'p','9528','/user/changePassword','POST','','','');
INSERT INTO casbin_rule (p_type,v0,v1,v2,v3,v4,v5) VALUES (
'p','9528','/user/uploadHeaderImg','POST','','','');
INSERT INTO casbin_rule (p_type,v0,v1,v2,v3,v4,v5) VALUES (
'p','9528','/user/getInfoList','POST','','','');
INSERT INTO casbin_rule (p_type,v0,v1,v2,v3,v4,v5) VALUES (
'p','9528','/user/getUserList','POST','','','');
Expand Down Expand Up @@ -201,8 +197,6 @@ INSERT INTO casbin_rule (p_type,v0,v1,v2,v3,v4,v5) VALUES (
INSERT INTO casbin_rule (p_type,v0,v1,v2,v3,v4,v5) VALUES (
'p','888','/user/changePassword','POST','','','');
INSERT INTO casbin_rule (p_type,v0,v1,v2,v3,v4,v5) VALUES (
'p','888','/user/uploadHeaderImg','POST','','','');
INSERT INTO casbin_rule (p_type,v0,v1,v2,v3,v4,v5) VALUES (
'p','888','/user/getInfoList','POST','','','');
INSERT INTO casbin_rule (p_type,v0,v1,v2,v3,v4,v5) VALUES (
'p','888','/user/getUserList','POST','','','');
Expand Down
2 changes: 0 additions & 2 deletions server/db/sqlite/sys_apis.sql
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,6 @@ INSERT INTO sys_apis (id,created_at,updated_at,deleted_at,authority_id,"path",de
INSERT INTO sys_apis (id,created_at,updated_at,deleted_at,authority_id,"path",description,api_group,"method") VALUES (
23,1569828559000,1569828559000,NULL,NULL,'/user/changePassword','修改密码','user','POST');
INSERT INTO sys_apis (id,created_at,updated_at,deleted_at,authority_id,"path",description,api_group,"method") VALUES (
24,1569828573000,1569828573000,NULL,NULL,'/user/uploadHeaderImg','上传头像','user','POST');
INSERT INTO sys_apis (id,created_at,updated_at,deleted_at,authority_id,"path",description,api_group,"method") VALUES (
25,1569828600000,1569828600000,NULL,NULL,'/user/getInfoList','分页获取用户列表','user','POST');
INSERT INTO sys_apis (id,created_at,updated_at,deleted_at,authority_id,"path",description,api_group,"method") VALUES (
28,1570605317000,1570605427000,NULL,NULL,'/user/getUserList','获取用户列表','user','POST');
Expand Down
Loading

0 comments on commit dda3f7a

Please sign in to comment.