Skip to content

Commit

Permalink
patch🚑: dev merge
Browse files Browse the repository at this point in the history
patch🚑:  dev merge
  • Loading branch information
wenjianzhang authored Mar 5, 2022
2 parents 72391f0 + 1508e85 commit 1fe19d1
Show file tree
Hide file tree
Showing 19 changed files with 364 additions and 70 deletions.
2 changes: 1 addition & 1 deletion LICENSE.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2020 wenjianzhang
Copyright (c) 2020 go-admin-team

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
4 changes: 2 additions & 2 deletions README.Zh-cn.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,9 @@

### 轻松实现go-admin写出第一个应用 - 文档教程

[步骤一 - 基础内容介绍](http://doc.zhangwj.com/go-admin-site/guide/intro/tutorial01.html)
[步骤一 - 基础内容介绍](https://doc.zhangwj.com/guide/intro/tutorial01.html)

[步骤二 - 实际应用 - 编写增删改查](http://doc.zhangwj.com/go-admin-site/guide/intro/tutorial02.html)
[步骤二 - 实际应用 - 编写增删改查](https://doc.zhangwj.com/guide/intro/tutorial02.html)

### 手把手教你从入门到放弃 - 视频教程

Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,9 @@ At the same time, a series of tutorials including videos and documents are provi

### Easily implement go-admin to write the first application-documentation tutorial

[Step 1 - basic content introduction](http://doc.zhangwj.com/go-admin-site/guide/intro/tutorial01.html)
[Step 1 - basic content introduction](https://doc.zhangwj.com/guide/intro/tutorial01.html)

[Step 2 - Practical application - writing database operations](http://doc.zhangwj.com/go-admin-site/guide/intro/tutorial02.html)
[Step 2 - Practical application - writing database operations](https://doc.zhangwj.com/guide/intro/tutorial02.html)

### Teach you from getting started to giving up-video tutorial

Expand Down
46 changes: 30 additions & 16 deletions app/admin/apis/sys_user.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package apis

import (
"github.com/gin-gonic/gin/binding"
"github.com/go-admin-team/go-admin-core/sdk/config"
"go-admin/app/admin/models"
"net/http"

Expand Down Expand Up @@ -30,7 +31,7 @@ type SysUser struct {
// @Security Bearer
func (e SysUser) GetPage(c *gin.Context) {
s := service.SysUser{}
req :=dto.SysUserGetPageReq{}
req := dto.SysUserGetPageReq{}
err := e.MakeContext(c).
MakeOrm().
Bind(&req).
Expand Down Expand Up @@ -67,7 +68,7 @@ func (e SysUser) GetPage(c *gin.Context) {
// @Security Bearer
func (e SysUser) Get(c *gin.Context) {
s := service.SysUser{}
req :=dto.SysUserById{}
req := dto.SysUserById{}
err := e.MakeContext(c).
MakeOrm().
Bind(&req, nil).
Expand Down Expand Up @@ -101,7 +102,7 @@ func (e SysUser) Get(c *gin.Context) {
// @Security Bearer
func (e SysUser) Insert(c *gin.Context) {
s := service.SysUser{}
req :=dto.SysUserInsertReq{}
req := dto.SysUserInsertReq{}
err := e.MakeContext(c).
MakeOrm().
Bind(&req, binding.JSON).
Expand Down Expand Up @@ -136,7 +137,7 @@ func (e SysUser) Insert(c *gin.Context) {
// @Security Bearer
func (e SysUser) Update(c *gin.Context) {
s := service.SysUser{}
req :=dto.SysUserUpdateReq{}
req := dto.SysUserUpdateReq{}
err := e.MakeContext(c).
MakeOrm().
Bind(&req).
Expand Down Expand Up @@ -171,7 +172,7 @@ func (e SysUser) Update(c *gin.Context) {
// @Security Bearer
func (e SysUser) Delete(c *gin.Context) {
s := service.SysUser{}
req :=dto.SysUserById{}
req := dto.SysUserById{}
err := e.MakeContext(c).
MakeOrm().
Bind(&req, binding.JSON).
Expand Down Expand Up @@ -208,7 +209,7 @@ func (e SysUser) Delete(c *gin.Context) {
// @Security Bearer
func (e SysUser) InsetAvatar(c *gin.Context) {
s := service.SysUser{}
req :=dto.UpdateSysUserAvatarReq{}
req := dto.UpdateSysUserAvatarReq{}
err := e.MakeContext(c).
MakeOrm().
MakeService(&s.Service).
Expand Down Expand Up @@ -257,7 +258,7 @@ func (e SysUser) InsetAvatar(c *gin.Context) {
// @Security Bearer
func (e SysUser) UpdateStatus(c *gin.Context) {
s := service.SysUser{}
req :=dto.UpdateSysUserStatusReq{}
req := dto.UpdateSysUserStatusReq{}
err := e.MakeContext(c).
MakeOrm().
Bind(&req, binding.JSON, nil).
Expand Down Expand Up @@ -294,7 +295,7 @@ func (e SysUser) UpdateStatus(c *gin.Context) {
// @Security Bearer
func (e SysUser) ResetPwd(c *gin.Context) {
s := service.SysUser{}
req :=dto.ResetSysUserPwdReq{}
req := dto.ResetSysUserPwdReq{}
err := e.MakeContext(c).
MakeOrm().
Bind(&req, binding.JSON).
Expand All @@ -311,16 +312,23 @@ func (e SysUser) ResetPwd(c *gin.Context) {
//数据权限检查
p := actions.GetPermissionFromContext(c)

if req.UserId == 1 && config.ApplicationConfig.Mode == "demo" {
req.Password = "123456"
}
err = s.ResetPwd(&req, p)
if err != nil {
e.Logger.Error(err)
return
}
e.OK(req.GetId(), "更新成功")
if req.UserId == 1 && config.ApplicationConfig.Mode == "demo" {
e.OK(req.GetId(), "admin:现在使用的预览环境,休想改掉我!否则会影响其他朋友体验的哦!可以创建其他用户体验该功能!")
} else {
e.OK(req.GetId(), "更新成功")
}
}

// UpdatePwd
// @Summary 重置密码
// @Summary 修改密码
// @Description 获取JSON
// @Tags 用户
// @Accept application/json
Expand All @@ -331,7 +339,7 @@ func (e SysUser) ResetPwd(c *gin.Context) {
// @Security Bearer
func (e SysUser) UpdatePwd(c *gin.Context) {
s := service.SysUser{}
req :=dto.PassWord{}
req := dto.PassWord{}
err := e.MakeContext(c).
MakeOrm().
Bind(&req).
Expand All @@ -345,14 +353,20 @@ func (e SysUser) UpdatePwd(c *gin.Context) {

// 数据权限检查
p := actions.GetPermissionFromContext(c)

if user.GetUserId(c) == 1 && config.ApplicationConfig.Mode == "demo" {
req.NewPassword = "123456"
}
err = s.UpdatePwd(user.GetUserId(c), req.OldPassword, req.NewPassword, p)
if err != nil {
e.Logger.Error(err)
e.Error(http.StatusForbidden, err, "密码修改失败")
return
}
e.OK(nil, "密码修改成功")
if user.GetUserId(c) == 1 && config.ApplicationConfig.Mode == "demo" {
e.OK(nil, "admin:现在使用的预览环境,休想改掉我!否则会影响其他朋友体验的哦!可以创建其他用户体验该功能!")
} else {
e.OK(nil, "密码修改成功")
}
}

// GetProfile
Expand All @@ -364,7 +378,7 @@ func (e SysUser) UpdatePwd(c *gin.Context) {
// @Security Bearer
func (e SysUser) GetProfile(c *gin.Context) {
s := service.SysUser{}
req :=dto.SysUserById{}
req := dto.SysUserById{}
err := e.MakeContext(c).
MakeOrm().
MakeService(&s.Service).
Expand Down Expand Up @@ -401,7 +415,7 @@ func (e SysUser) GetProfile(c *gin.Context) {
// @Router /api/v1/getinfo [get]
// @Security Bearer
func (e SysUser) GetInfo(c *gin.Context) {
req :=dto.SysUserById{}
req := dto.SysUserById{}
s := service.SysUser{}
r := service.SysRole{}
err := e.MakeContext(c).
Expand Down Expand Up @@ -450,4 +464,4 @@ func (e SysUser) GetInfo(c *gin.Context) {
mp["name"] = sysUser.NickName
mp["code"] = 200
e.OK(mp, "")
}
}
2 changes: 1 addition & 1 deletion app/admin/service/sys_role.go
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ func (e *SysRole) UpdateDataScope(c *dto.RoleDataScopeReq) *SysRole {
var dlist = make([]models.SysDept, 0)
var model = models.SysRole{}
tx.Preload("SysDept").First(&model, c.RoleId)
tx.Where("id in ?", c.DeptIds).Find(&dlist)
tx.Where("dept_id in ?", c.DeptIds).Find(&dlist)
err = tx.Model(&model).Association("SysDept").Delete(model.SysDept)
if err != nil {
e.Log.Errorf("delete SysDept error:%s", err)
Expand Down
9 changes: 3 additions & 6 deletions app/admin/service/sys_user.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,7 @@ func (e *SysUser) UpdateAvatar(c *dto.UpdateSysUserAvatarReq, p *actions.DataPer
return errors.New("无权更新该数据")

}
c.Generate(&model)
err = e.Orm.Save(&model).Error
err = e.Orm.Table(model.TableName()).Where("user_id =? ", c.UserId).Updates(c).Error
if err != nil {
e.Log.Errorf("Service UpdateSysUser error: %s", err)
return err
Expand All @@ -151,8 +150,7 @@ func (e *SysUser) UpdateStatus(c *dto.UpdateSysUserStatusReq, p *actions.DataPer
return errors.New("无权更新该数据")

}
c.Generate(&model)
err = e.Orm.Save(&model).Error
err = e.Orm.Table(model.TableName()).Where("user_id =? ", c.UserId).Updates(c).Error
if err != nil {
e.Log.Errorf("Service UpdateSysUser error: %s", err)
return err
Expand All @@ -174,8 +172,7 @@ func (e *SysUser) ResetPwd(c *dto.ResetSysUserPwdReq, p *actions.DataPermission)
if db.RowsAffected == 0 {
return errors.New("无权更新该数据")
}
c.Generate(&model)
err = e.Orm.Save(&model).Error
err = e.Orm.Table(model.TableName()).Where("user_id =? ", c.UserId).Updates(c).Error
if err != nil {
e.Log.Errorf("At Service ResetSysUserPwd error: %s", err)
return err
Expand Down
48 changes: 40 additions & 8 deletions common/file_store/initialize.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,45 @@
package file_store

type FileStore struct {
import "fmt"

type OXS struct {
// Endpoint 访问域名
Endpoint string
// AccessKeyID AK
AccessKeyID string
// AccessKeySecret AKS
AccessKeySecret string
// BucketName 桶名称
BucketName string
}

// Setup 配置数据库
func (e *FileStore) Setup(driver string) {
//fileStoreType := driver
//if fileStoreType == "ALiYunOSS" {
// var store = new(ALiYunOSS)
// store.Setup()
//}
// Setup 配置文件存储driver
func (e *OXS) Setup(driver DriverType, options ...ClientOption) FileStoreType {
fileStoreType := driver
var fileStore FileStoreType
switch fileStoreType {
case AliYunOSS:
fileStore = new(ALiYunOSS)
err := fileStore.Setup(e.Endpoint, e.AccessKeyID, e.AccessKeySecret, e.BucketName)
if err != nil {
fmt.Println(err)
}
return fileStore
case HuaweiOBS:
fileStore = new(HuaWeiOBS)
err := fileStore.Setup(e.Endpoint, e.AccessKeyID, e.AccessKeySecret, e.BucketName)
if err != nil {
fmt.Println(err)
}
return fileStore
case QiNiuKodo:
fileStore = new(QiNiuKODO)
err := fileStore.Setup(e.Endpoint, e.AccessKeyID, e.AccessKeySecret, e.BucketName)
if err != nil {
fmt.Println(err)
}
return fileStore
}

return nil
}
25 changes: 23 additions & 2 deletions common/file_store/interface.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,27 @@
package file_store

// DriverType 驱动类型
type DriverType string

const (
// HuaweiOBS 华为云OBS
HuaweiOBS DriverType = "HuaweiOBS"
// AliYunOSS 阿里云OSS
AliYunOSS DriverType = "AliYunOSS"
// QiNiuKodo 七牛云kodo
QiNiuKodo DriverType = "QiNiuKodo"
)

type ClientOption map[string]interface{}

// TODO: FileStoreType名称待定

// FileStoreType OXS
type FileStoreType interface {
Setup() error
UpLoad(yourObjectName string, localFile string) error
// Setup 装载 endpoint sss
Setup(endpoint, accessKeyID, accessKeySecret, BucketName string, options ...ClientOption) error
// UpLoad 上传
UpLoad(yourObjectName string, localFile interface{}) error
// GetTempToken 获取临时Token
GetTempToken() (string, error)
}
Loading

0 comments on commit 1fe19d1

Please sign in to comment.