v2.5.1 beta2 (#1048)
* 修复日志中间件报文过大的报错问题 * 修复 Token 失效后导致的白屏问题 * 增加自动创建插件模板功能 * 密码加密方式改为 hash * 增加刷新防抖 Co-authored-by: songzhibin97 <718428482@qq.com> Co-authored-by: icedays <icedays@163.com> Co-authored-by: hedeqiang <laravel_code@163.com>
This commit is contained in:
committed by
GitHub
co-authored by
songzhibin97
icedays
hedeqiang
parent
843e5a9ad4
commit
6add2094a6
@@ -17,7 +17,7 @@ import (
|
||||
"strings"
|
||||
"text/template"
|
||||
|
||||
"github.com/flipped-aurora/gin-vue-admin/server/resource/template/subcontract"
|
||||
"github.com/flipped-aurora/gin-vue-admin/server/resource/autocode_template/subcontract"
|
||||
|
||||
"github.com/flipped-aurora/gin-vue-admin/server/global"
|
||||
"github.com/flipped-aurora/gin-vue-admin/server/model/system"
|
||||
@@ -28,7 +28,8 @@ import (
|
||||
|
||||
const (
|
||||
autoPath = "autocode_template/"
|
||||
basePath = "resource/template"
|
||||
autocodePath = "resource/autocode_template"
|
||||
plugPath = "resource/plug_template"
|
||||
packageService = "service/%s/enter.go"
|
||||
packageServiceName = "service"
|
||||
packageRouter = "router/%s/enter.go"
|
||||
@@ -483,7 +484,7 @@ func (autoCodeService *AutoCodeService) getNeedList(autoCode *system.AutoCodeStr
|
||||
utils.TrimSpace(field)
|
||||
}
|
||||
// 获取 basePath 文件夹下所有tpl文件
|
||||
tplFileList, err := autoCodeService.GetAllTplFile(basePath, nil)
|
||||
tplFileList, err := autoCodeService.GetAllTplFile(autocodePath, nil)
|
||||
if err != nil {
|
||||
return nil, nil, nil, err
|
||||
}
|
||||
@@ -505,7 +506,7 @@ func (autoCodeService *AutoCodeService) getNeedList(autoCode *system.AutoCodeStr
|
||||
// resource/template/web/api.js.tpl -> autoCode/web/autoCode.PackageName/api/autoCode.PackageName.js
|
||||
// resource/template/readme.txt.tpl -> autoCode/readme.txt
|
||||
for index, value := range dataList {
|
||||
trimBase := strings.TrimPrefix(value.locationPath, basePath+"/")
|
||||
trimBase := strings.TrimPrefix(value.locationPath, autocodePath+"/")
|
||||
if trimBase == "readme.txt.tpl" {
|
||||
dataList[index].autoCodePath = autoPath + "readme.txt"
|
||||
continue
|
||||
@@ -789,3 +790,26 @@ func ImportReference(filepath, importCode, structName, packageName, groupName st
|
||||
// 写回数据
|
||||
return ioutil.WriteFile(filepath, buffer.Bytes(), 0o600)
|
||||
}
|
||||
|
||||
// 自动创建插件模板
|
||||
func (autoCodeService *AutoCodeService) CreatePlug(plug system.AutoPlugReq) error {
|
||||
tplFileList, _ := autoCodeService.GetAllTplFile(plugPath, nil)
|
||||
for _, tpl := range tplFileList {
|
||||
temp, err := template.ParseFiles(tpl)
|
||||
fmt.Println(err)
|
||||
pathArr := strings.SplitAfter(tpl, "/")
|
||||
if strings.Index(pathArr[2], "tpl") < 0 {
|
||||
dirPath := filepath.Join(global.GVA_CONFIG.AutoCode.Root, global.GVA_CONFIG.AutoCode.Server, fmt.Sprintf(global.GVA_CONFIG.AutoCode.SPlug, plug.Snake+"/"+pathArr[2]))
|
||||
os.MkdirAll(dirPath, 0755)
|
||||
}
|
||||
file := filepath.Join(global.GVA_CONFIG.AutoCode.Root, global.GVA_CONFIG.AutoCode.Server, fmt.Sprintf(global.GVA_CONFIG.AutoCode.SPlug, plug.Snake+"/"+tpl[len(plugPath):len(tpl)-4]))
|
||||
f, _ := os.OpenFile(file, os.O_WRONLY|os.O_CREATE, 0666)
|
||||
e := temp.Execute(f, plug)
|
||||
if e != nil {
|
||||
fmt.Println(e)
|
||||
return e
|
||||
}
|
||||
defer f.Close()
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -3,7 +3,6 @@ package system
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
"github.com/flipped-aurora/gin-vue-admin/server/global"
|
||||
"github.com/flipped-aurora/gin-vue-admin/server/model/common/request"
|
||||
"github.com/flipped-aurora/gin-vue-admin/server/model/system"
|
||||
@@ -25,8 +24,8 @@ func (userService *UserService) Register(u system.SysUser) (err error, userInter
|
||||
if !errors.Is(global.GVA_DB.Where("username = ?", u.Username).First(&user).Error, gorm.ErrRecordNotFound) { // 判断用户名是否注册
|
||||
return errors.New("用户名已注册"), userInter
|
||||
}
|
||||
// 否则 附加uuid 密码md5简单加密 注册
|
||||
u.Password = utils.MD5V([]byte(u.Password))
|
||||
// 否则 附加uuid 密码hash加密 注册
|
||||
u.Password = utils.BcryptHash(u.Password)
|
||||
u.UUID = uuid.NewV4()
|
||||
err = global.GVA_DB.Create(&u).Error
|
||||
return err, u
|
||||
@@ -44,15 +43,18 @@ func (userService *UserService) Login(u *system.SysUser) (err error, userInter *
|
||||
}
|
||||
|
||||
var user system.SysUser
|
||||
u.Password = utils.MD5V([]byte(u.Password))
|
||||
err = global.GVA_DB.Where("username = ? AND password = ?", u.Username, u.Password).Preload("Authorities").Preload("Authority").First(&user).Error
|
||||
err = global.GVA_DB.Where("username = ?", u.Username).Preload("Authorities").Preload("Authority").First(&user).Error
|
||||
if err == nil {
|
||||
if ok := utils.BcryptCheck(u.Password, user.Password); !ok {
|
||||
return errors.New("密码错误"), nil
|
||||
}
|
||||
var am system.SysMenu
|
||||
ferr := global.GVA_DB.First(&am, "name = ? AND authority_id = ?", user.Authority.DefaultRouter, user.AuthorityId).Error
|
||||
if errors.Is(ferr, gorm.ErrRecordNotFound) {
|
||||
user.Authority.DefaultRouter = "404"
|
||||
}
|
||||
}
|
||||
|
||||
return err, &user
|
||||
}
|
||||
|
||||
@@ -64,9 +66,17 @@ func (userService *UserService) Login(u *system.SysUser) (err error, userInter *
|
||||
|
||||
func (userService *UserService) ChangePassword(u *system.SysUser, newPassword string) (err error, userInter *system.SysUser) {
|
||||
var user system.SysUser
|
||||
u.Password = utils.MD5V([]byte(u.Password))
|
||||
err = global.GVA_DB.Where("username = ? AND password = ?", u.Username, u.Password).First(&user).Update("password", utils.MD5V([]byte(newPassword))).Error
|
||||
return err, u
|
||||
err = global.GVA_DB.Where("username = ?", u.Username).First(&user).Error
|
||||
if err != nil {
|
||||
return err, nil
|
||||
}
|
||||
if ok := utils.BcryptCheck(u.Password, user.Password); !ok {
|
||||
return errors.New("原密码错误"), nil
|
||||
}
|
||||
user.Password = utils.BcryptHash(newPassword)
|
||||
err = global.GVA_DB.Save(&user).Error
|
||||
return err, &user
|
||||
|
||||
}
|
||||
|
||||
//@author: [piexlmax](https://github.com/piexlmax)
|
||||
@@ -213,6 +223,6 @@ func (userService *UserService) FindUserByUuid(uuid string) (err error, user *sy
|
||||
//@return: err error
|
||||
|
||||
func (userService *UserService) ResetPassword(ID uint) (err error) {
|
||||
err = global.GVA_DB.Model(&system.SysUser{}).Where("id = ?", ID).Update("password", utils.MD5V([]byte("123456"))).Error
|
||||
err = global.GVA_DB.Model(&system.SysUser{}).Where("id = ?", ID).Update("password", utils.BcryptHash("123456")).Error
|
||||
return err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user