From 6187fedd4e4e61caa5cd19cac8d1e671467cddf7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AD=9F=E5=B8=85?= <133814250@qq.com> Date: Mon, 15 May 2023 10:17:04 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=B3=A8=E5=86=8C=E5=BC=BA?= =?UTF-8?q?=E5=88=B6=E9=82=80=E8=AF=B7=E7=A0=81=E5=BC=80=E5=85=B3=E3=80=81?= =?UTF-8?q?=E5=BE=AE=E4=BF=A1=E5=86=85=E7=99=BB=E5=BD=95=E8=87=AA=E5=8A=A8?= =?UTF-8?q?=E8=8E=B7=E5=8F=96openid=E5=BC=80=E5=85=B3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../internal/controller/admin/admin/role.go | 3 +- .../internal/controller/admin/common/ems.go | 3 +- .../internal/controller/admin/common/site.go | 1 - .../internal/controller/admin/sys/config.go | 7 ++-- .../controller/admin/sys/cron_group.go | 3 +- .../controller/admin/sys/dict_type.go | 3 +- server/internal/controller/admin/sys/log.go | 3 +- .../internal/controller/api/member/member.go | 3 +- server/internal/controller/api/pay/notify.go | 6 +-- server/internal/controller/api/user/hello.go | 3 +- server/internal/controller/home/base/site.go | 3 +- server/internal/logic/admin/member.go | 24 +++++++++-- server/internal/logic/admin/site.go | 24 +++++++---- server/internal/model/config.go | 6 ++- server/storage/data/hotgo.sql | 41 ++++++++++--------- server/utility/file/mime.go | 5 +-- web/src/router/router-guards.ts | 13 +++--- web/src/store/modules/user.ts | 14 +++++++ web/src/utils/urlUtils.ts | 8 ++++ web/src/views/login/components/form-other.vue | 9 ++-- web/src/views/login/components/style.less | 2 - web/src/views/login/login/form.vue | 2 +- web/src/views/login/register/agreement.vue | 9 ++-- web/src/views/login/register/index.vue | 1 + web/src/views/org/user/list.vue | 23 +++-------- web/src/views/system/config/LoginSetting.vue | 34 ++++++++++++++- 26 files changed, 157 insertions(+), 96 deletions(-) diff --git a/server/internal/controller/admin/admin/role.go b/server/internal/controller/admin/admin/role.go index 84ea0f2..a8b26e8 100644 --- a/server/internal/controller/admin/admin/role.go +++ b/server/internal/controller/admin/admin/role.go @@ -3,7 +3,6 @@ // @Copyright Copyright (c) 2023 HotGo CLI // @Author Ms <133814250@qq.com> // @License https://github.com/bufanyun/hotgo/blob/master/LICENSE -// package admin import ( @@ -103,7 +102,7 @@ func (c *cRole) UpdatePermissions(ctx context.Context, req *role.UpdatePermissio } // DataScopeSelect 获取数据权限选项 -func (c *cRole) DataScopeSelect(ctx context.Context, req *role.DataScopeSelectReq) (res *role.DataScopeSelectRes, err error) { +func (c *cRole) DataScopeSelect(ctx context.Context, _ *role.DataScopeSelectReq) (res *role.DataScopeSelectRes, err error) { data := service.AdminRole().DataScopeSelect(ctx) res = new(role.DataScopeSelectRes) res.List = data diff --git a/server/internal/controller/admin/common/ems.go b/server/internal/controller/admin/common/ems.go index 95153e0..0cd32d8 100644 --- a/server/internal/controller/admin/common/ems.go +++ b/server/internal/controller/admin/common/ems.go @@ -3,7 +3,6 @@ // @Copyright Copyright (c) 2023 HotGo CLI // @Author Ms <133814250@qq.com> // @License https://github.com/bufanyun/hotgo/blob/master/LICENSE -// package common import ( @@ -43,7 +42,7 @@ func (c *cEms) SendTest(ctx context.Context, req *common.SendTestEmailReq) (res } // SendBindEms 发送换绑邮件 -func (c *cSms) SendBindEms(ctx context.Context, req *common.SendBindEmsReq) (res *common.SendBindEmsRes, err error) { +func (c *cSms) SendBindEms(ctx context.Context, _ *common.SendBindEmsReq) (res *common.SendBindEmsRes, err error) { var ( memberId = contexts.GetUserId(ctx) models *entity.AdminMember diff --git a/server/internal/controller/admin/common/site.go b/server/internal/controller/admin/common/site.go index fc93cda..8a27625 100644 --- a/server/internal/controller/admin/common/site.go +++ b/server/internal/controller/admin/common/site.go @@ -36,7 +36,6 @@ func (c *cSite) Config(ctx context.Context, _ *common.SiteConfigReq) (res *commo Version: consts.VersionApp, WsAddr: c.getWsAddr(ctx, request), Domain: c.getDomain(ctx, request), - //InviteUrl: "http://192.168.1.27:8001/#/login?scope=register&inviteCode=", } return } diff --git a/server/internal/controller/admin/sys/config.go b/server/internal/controller/admin/sys/config.go index 1f19d27..2be9551 100644 --- a/server/internal/controller/admin/sys/config.go +++ b/server/internal/controller/admin/sys/config.go @@ -3,7 +3,6 @@ // @Copyright Copyright (c) 2023 HotGo CLI // @Author Ms <133814250@qq.com> // @License https://github.com/bufanyun/hotgo/blob/master/LICENSE -// package sys import ( @@ -46,7 +45,7 @@ func (c *cConfig) UpdateConfig(ctx context.Context, req *config.UpdateReq) (res } // TypeSelect 数据类型选项 -func (c *cConfig) TypeSelect(ctx context.Context, req *config.TypeSelectReq) (res config.TypeSelectRes, err error) { +func (c *cConfig) TypeSelect(_ context.Context, _ *config.TypeSelectReq) (res config.TypeSelectRes, err error) { for _, v := range consts.ConfigTypes { res = append(res, form.Select{ Value: v, @@ -58,8 +57,8 @@ func (c *cConfig) TypeSelect(ctx context.Context, req *config.TypeSelectReq) (re } // GetCash 获取指定分组的配置 -func (c *cConfig) GetCash(ctx context.Context, req *config.GetCashReq) (res *config.GetCashRes, err error) { +func (c *cConfig) GetCash(ctx context.Context, _ *config.GetCashReq) (res *config.GetCashRes, err error) { res = new(config.GetCashRes) res.GetConfigModel, err = service.SysConfig().GetConfigByGroup(ctx, sysin.GetConfigInp{Group: "cash"}) return -} \ No newline at end of file +} diff --git a/server/internal/controller/admin/sys/cron_group.go b/server/internal/controller/admin/sys/cron_group.go index 6455c10..6037af2 100644 --- a/server/internal/controller/admin/sys/cron_group.go +++ b/server/internal/controller/admin/sys/cron_group.go @@ -3,7 +3,6 @@ // @Copyright Copyright (c) 2023 HotGo CLI // @Author Ms <133814250@qq.com> // @License https://github.com/bufanyun/hotgo/blob/master/LICENSE -// package sys import ( @@ -99,7 +98,7 @@ func (c *cCronGroup) Status(ctx context.Context, req *cron.GroupStatusReq) (res } // Select 选项 -func (c *cCronGroup) Select(ctx context.Context, req *cron.GroupSelectReq) (res *cron.GroupSelectRes, err error) { +func (c *cCronGroup) Select(ctx context.Context, _ *cron.GroupSelectReq) (res *cron.GroupSelectRes, err error) { data, err := service.SysCronGroup().Select(ctx, sysin.CronGroupSelectInp{}) if err != nil { return diff --git a/server/internal/controller/admin/sys/dict_type.go b/server/internal/controller/admin/sys/dict_type.go index b20483b..0ec805b 100644 --- a/server/internal/controller/admin/sys/dict_type.go +++ b/server/internal/controller/admin/sys/dict_type.go @@ -3,7 +3,6 @@ // @Copyright Copyright (c) 2023 HotGo CLI // @Author Ms <133814250@qq.com> // @License https://github.com/bufanyun/hotgo/blob/master/LICENSE -// package sys import ( @@ -21,7 +20,7 @@ var ( type cDictType struct{} // Tree 树 -func (c *cDictType) Tree(ctx context.Context, req *dict.TypeTreeReq) (res *dict.TypeTreeRes, err error) { +func (c *cDictType) Tree(ctx context.Context, _ *dict.TypeTreeReq) (res *dict.TypeTreeRes, err error) { res = new(dict.TypeTreeRes) res.List, err = service.SysDictType().Tree(ctx) return diff --git a/server/internal/controller/admin/sys/log.go b/server/internal/controller/admin/sys/log.go index 499b11b..e6fce95 100644 --- a/server/internal/controller/admin/sys/log.go +++ b/server/internal/controller/admin/sys/log.go @@ -3,7 +3,6 @@ // @Copyright Copyright (c) 2023 HotGo CLI // @Author Ms <133814250@qq.com> // @License https://github.com/bufanyun/hotgo/blob/master/LICENSE -// package sys import ( @@ -22,7 +21,7 @@ var Log = sLog{} type sLog struct{} // Clear 清空日志 -func (c *sLog) Clear(ctx context.Context, req *log.ClearReq) (res *log.ClearRes, err error) { +func (c *sLog) Clear(ctx context.Context, _ *log.ClearReq) (res *log.ClearRes, err error) { err = gerror.New("暂时考虑到安全问题,请到数据库清空") return } diff --git a/server/internal/controller/api/member/member.go b/server/internal/controller/api/member/member.go index 29a1727..9599400 100644 --- a/server/internal/controller/api/member/member.go +++ b/server/internal/controller/api/member/member.go @@ -3,7 +3,6 @@ // @Copyright Copyright (c) 2023 HotGo CLI // @Author Ms <133814250@qq.com> // @License https://github.com/bufanyun/hotgo/blob/master/LICENSE -// package member import ( @@ -18,7 +17,7 @@ var ( type cMember struct{} -func (c *cMember) GetIdByCode(ctx context.Context, req *member.GetIdByCodeReq) (res *member.GetIdByCodeRes, err error) { +func (c *cMember) GetIdByCode(ctx context.Context, _ *member.GetIdByCodeReq) (res *member.GetIdByCodeRes, err error) { g.RequestFromCtx(ctx).Response.Writeln("Hello World api member!") return } diff --git a/server/internal/controller/api/pay/notify.go b/server/internal/controller/api/pay/notify.go index 7b780c1..15497d3 100644 --- a/server/internal/controller/api/pay/notify.go +++ b/server/internal/controller/api/pay/notify.go @@ -20,7 +20,7 @@ var ( type cNotify struct{} // AliPay 支付宝回调 -func (c *cNotify) AliPay(ctx context.Context, req *pay.NotifyAliPayReq) (res *pay.NotifyAliPayRes, err error) { +func (c *cNotify) AliPay(ctx context.Context, _ *pay.NotifyAliPayReq) (res *pay.NotifyAliPayRes, err error) { _, err = service.Pay().Notify(ctx, payin.PayNotifyInp{PayType: consts.PayTypeAliPay}) if err != nil { return nil, err @@ -30,7 +30,7 @@ func (c *cNotify) AliPay(ctx context.Context, req *pay.NotifyAliPayReq) (res *pa } // WxPay 微信支付回调 -func (c *cNotify) WxPay(ctx context.Context, req *pay.NotifyWxPayReq) (res *pay.NotifyWxPayRes, err error) { +func (c *cNotify) WxPay(ctx context.Context, _ *pay.NotifyWxPayReq) (res *pay.NotifyWxPayRes, err error) { _, err = service.Pay().Notify(ctx, payin.PayNotifyInp{PayType: consts.PayTypeWxPay}) if err != nil { return nil, err @@ -42,7 +42,7 @@ func (c *cNotify) WxPay(ctx context.Context, req *pay.NotifyWxPayReq) (res *pay. } // QQPay QQ支付回调 -func (c *cNotify) QQPay(ctx context.Context, req *pay.NotifyQQPayReq) (res *pay.NotifyQQPayRes, err error) { +func (c *cNotify) QQPay(ctx context.Context, _ *pay.NotifyQQPayReq) (res *pay.NotifyQQPayRes, err error) { _, err = service.Pay().Notify(ctx, payin.PayNotifyInp{PayType: consts.PayTypeQQPay}) if err != nil { return nil, err diff --git a/server/internal/controller/api/user/hello.go b/server/internal/controller/api/user/hello.go index 7e05631..8ce539d 100644 --- a/server/internal/controller/api/user/hello.go +++ b/server/internal/controller/api/user/hello.go @@ -3,7 +3,6 @@ // @Copyright Copyright (c) 2023 HotGo CLI // @Author Ms <133814250@qq.com> // @License https://github.com/bufanyun/hotgo/blob/master/LICENSE -// package user import ( @@ -18,7 +17,7 @@ var ( type cHello struct{} -func (c *cHello) Hello(ctx context.Context, req *user.HelloReq) (res *user.HelloRes, err error) { +func (c *cHello) Hello(ctx context.Context, _ *user.HelloReq) (res *user.HelloRes, err error) { g.RequestFromCtx(ctx).Response.Writeln("Hello World api member!") return } diff --git a/server/internal/controller/home/base/site.go b/server/internal/controller/home/base/site.go index 1d10620..34ff311 100644 --- a/server/internal/controller/home/base/site.go +++ b/server/internal/controller/home/base/site.go @@ -3,7 +3,6 @@ // @Copyright Copyright (c) 2023 HotGo CLI // @Author Ms <133814250@qq.com> // @License https://github.com/bufanyun/hotgo/blob/master/LICENSE -// package base import ( @@ -20,7 +19,7 @@ var Site = cSite{} type cSite struct{} -func (a *cSite) Index(ctx context.Context, req *base.SiteIndexReq) (res *base.SiteIndexRes, err error) { +func (a *cSite) Index(ctx context.Context, _ *base.SiteIndexReq) (res *base.SiteIndexRes, err error) { service.View().Render(ctx, model.View{Data: g.Map{ "name": "HotGo", "version": consts.VersionApp, diff --git a/server/internal/logic/admin/member.go b/server/internal/logic/admin/member.go index 9ae2a08..e1efa79 100644 --- a/server/internal/logic/admin/member.go +++ b/server/internal/logic/admin/member.go @@ -437,6 +437,11 @@ func (s *sAdminMember) Edit(ctx context.Context, in adminin.MemberEditInp) (err return } + config, err := service.SysConfig().GetLogin(ctx) + if err != nil { + return + } + // 修改 if in.Id > 0 { if s.VerifySuperId(ctx, in.Id) { @@ -462,17 +467,20 @@ func (s *sAdminMember) Edit(ctx context.Context, in adminin.MemberEditInp) (err return g.DB().Transaction(ctx, func(ctx context.Context, tx gdb.TX) (err error) { if _, err = mod.Where("id", in.Id).Data(in).Update(); err != nil { + err = gerror.Wrap(err, consts.ErrorORM) return } // 更新岗位 - return dao.AdminMemberPost.UpdatePostIds(ctx, in.Id, in.PostIds) + if err = dao.AdminMemberPost.UpdatePostIds(ctx, in.Id, in.PostIds); err != nil { + err = gerror.Wrap(err, consts.ErrorORM) + } + return }) } // 新增用户时的额外属性 var data adminin.MemberAddInp - data.MemberEditInp = in data.Salt = grand.S(6) data.InviteCode = grand.S(12) data.PasswordHash = gmd5.MustEncryptString(data.Password + data.Salt) @@ -484,14 +492,24 @@ func (s *sAdminMember) Edit(ctx context.Context, in adminin.MemberEditInp) (err return } + // 默认头像 + if in.Avatar == "" { + in.Avatar = config.Avatar + } + data.MemberEditInp = in + return g.DB().Transaction(ctx, func(ctx context.Context, tx gdb.TX) (err error) { id, err := dao.AdminMember.Ctx(ctx).Data(data).InsertAndGetId() if err != nil { + err = gerror.Wrap(err, consts.ErrorORM) return } // 更新岗位 - return dao.AdminMemberPost.UpdatePostIds(ctx, id, in.PostIds) + if err = dao.AdminMemberPost.UpdatePostIds(ctx, id, in.PostIds); err != nil { + err = gerror.Wrap(err, consts.ErrorORM) + } + return }) } diff --git a/server/internal/logic/admin/site.go b/server/internal/logic/admin/site.go index 1e77e44..082c734 100644 --- a/server/internal/logic/admin/site.go +++ b/server/internal/logic/admin/site.go @@ -32,8 +32,17 @@ func init() { // Register 账号注册 func (s *sAdminSite) Register(ctx context.Context, in adminin.RegisterInp) (err error) { - var data adminin.MemberAddInp + config, err := service.SysConfig().GetLogin(ctx) + if err != nil { + return + } + if config.ForceInvite == 1 && in.InviteCode == "" { + err = gerror.New("请填写邀请码") + return + } + + var data adminin.MemberAddInp // 默认上级 data.Pid = 1 @@ -52,11 +61,6 @@ func (s *sAdminSite) Register(ctx context.Context, in adminin.RegisterInp) (err data.Pid = pmb.Id } - config, err := service.SysConfig().GetLogin(ctx) - if err != nil { - return - } - if config.RegisterSwitch != 1 { err = gerror.New("管理员未开放注册") return @@ -123,10 +127,15 @@ func (s *sAdminSite) Register(ctx context.Context, in adminin.RegisterInp) (err return g.DB().Transaction(ctx, func(ctx context.Context, tx gdb.TX) (err error) { id, err := dao.AdminMember.Ctx(ctx).Data(data).InsertAndGetId() if err != nil { + err = gerror.Wrap(err, consts.ErrorORM) return } - return dao.AdminMemberPost.UpdatePostIds(ctx, id, config.PostIds) + // 更新岗位 + if err = dao.AdminMemberPost.UpdatePostIds(ctx, id, config.PostIds); err != nil { + err = gerror.Wrap(err, consts.ErrorORM) + } + return }) } @@ -252,6 +261,7 @@ func (s *sAdminSite) handleLogin(ctx context.Context, mb *entity.AdminMember) (r // 更新登录信息 if _, err = dao.AdminMember.Ctx(ctx).Data(update).Where(do.AdminMember{Id: mb.Id}).Update(); err != nil { + err = gerror.Wrap(err, consts.ErrorORM) return } diff --git a/server/internal/model/config.go b/server/internal/model/config.go index d90f252..9a7ff09 100644 --- a/server/internal/model/config.go +++ b/server/internal/model/config.go @@ -162,11 +162,13 @@ type LoginConfig struct { RegisterSwitch int `json:"loginRegisterSwitch"` CaptchaSwitch int `json:"loginCaptchaSwitch"` Avatar string `json:"loginAvatar"` - Protocol string `json:"loginProtocol"` - Policy string `json:"loginPolicy"` RoleId int64 `json:"loginRoleId"` DeptId int64 `json:"loginDeptId"` PostIds []int64 `json:"loginPostIds"` + Protocol string `json:"loginProtocol"` + Policy string `json:"loginPolicy"` + AutoOpenId int `json:"loginAutoOpenId"` + ForceInvite int `json:"loginForceInvite"` } ///////////// 以下是本地配置 diff --git a/server/storage/data/hotgo.sql b/server/storage/data/hotgo.sql index 1755261..bc1eff6 100644 --- a/server/storage/data/hotgo.sql +++ b/server/storage/data/hotgo.sql @@ -1,13 +1,14 @@ -- phpMyAdmin SQL Dump --- version 5.2.1 +-- version 4.9.0.1 -- https://www.phpmyadmin.net/ -- --- 主机: localhost --- 生成日期: 2023-05-14 08:51:30 --- 服务器版本: 5.7.41 --- PHP 版本: 7.3.33 +-- 主机: localhost:3306 +-- 生成日期: 2023-05-15 10:04:47 +-- 服务器版本: 5.7.38-log +-- PHP 版本: 5.6.40 SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO"; +SET AUTOCOMMIT = 0; START TRANSACTION; SET time_zone = "+00:00"; @@ -72,8 +73,8 @@ CREATE TABLE `hg_addon_hgexample_table` ( -- INSERT INTO `hg_addon_hgexample_table` (`id`, `category_id`, `flag`, `title`, `description`, `content`, `image`, `images`, `attachfile`, `attachfiles`, `map`, `star`, `price`, `views`, `activity_at`, `start_at`, `end_at`, `switch`, `sort`, `avatar`, `sex`, `qq`, `email`, `mobile`, `hobby`, `channel`, `city_id`, `pid`, `level`, `tree`, `remark`, `status`, `created_by`, `updated_by`, `created_at`, `updated_at`, `deleted_at`) VALUES -(1, 1, '[1, 2]', '测试标题', '描述', '
这是内容............
', 'http://bufanyun.cn-bj.ufileos.com/hotgo/attachment/2023-02-09/cqdqamvhlq4w3ki6bl.webp', '[\"http://bufanyun.cn-bj.ufileos.com/hotgo/attachment/2023-02-09/cqdqap5l9brk2lkavu.jpg\", \"http://bufanyun.cn-bj.ufileos.com/hotgo/attachment/2023-02-09/cqdqaqua7fw8ukbbp5.jpg\"]', 'http://bufanyun.cn-bj.ufileos.com/hotgo/attachment/2023-02-09/cqdqaup19k9oznyixz.doc', '[\"http://bufanyun.cn-bj.ufileos.com/hotgo/attachment/2023-02-09/cqdqawg96ba4cuezvv.xlsx\", \"http://bufanyun.cn-bj.ufileos.com/hotgo/attachment/2023-02-09/cqdqaup19k9oznyixz.doc\"]', '[{\"key\": \"qwe\", \"value\": \"123\"}, {\"key\": \"asd\", \"value\": \"456\"}]', 3.0, 88.00, 10, '2022-12-23', '2022-12-01 00:00:00', '2022-12-31 23:59:59', 1, 20, '', 15, '133814250', '133814250@qq.com', '15303830571', '[3, 2, 1]', 1, 140406, 0, 1, '', '备注!', 1, 1, 3, '2022-12-15 19:30:14', '2023-04-28 16:46:17', NULL), -(2, 0, '[1]', '测试2', '描述', '这是内容............
', 'http://bufanyun.cn-bj.ufileos.com/hotgo/attachment/2023-02-09/cqdqamvhlq4w3ki6bl.webp', '[\"http://bufanyun.cn-bj.ufileos.com/hotgo/attachment/2023-02-09/cqdqap5l9brk2lkavu.jpg\", \"http://bufanyun.cn-bj.ufileos.com/hotgo/attachment/2023-02-09/cqdqaqua7fw8ukbbp5.jpg\"]', 'http://bufanyun.cn-bj.ufileos.com/hotgo/attachment/2023-02-09/cqdqaup19k9oznyixz.doc', '[\"http://bufanyun.cn-bj.ufileos.com/hotgo/attachment/2023-02-09/cqdqawg96ba4cuezvv.xlsx\", \"http://bufanyun.cn-bj.ufileos.com/hotgo/attachment/2023-02-09/cqdqaup19k9oznyixz.doc\"]', '[{\"key\": \"qwe\", \"value\": \"123\"}, {\"key\": \"asd\", \"value\": \"456\"}]', '3.0', '88.00', 10, '2022-12-23', '2022-12-01 00:00:00', '2022-12-31 23:59:59', 1, 20, '', 15, '133814250', '133814250@qq.com', '15303830571', '[3, 2, 1]', 1, 140406, 0, 1, '', '备注!', 1, 1, 3, '2022-12-15 19:30:14', '2023-04-28 16:46:17', NULL), +(2, 0, '[1]', '测试2', '描述', '用户协议..
', '', 1120, '', 1, 1, '2021-09-29 23:51:21', '2023-05-14 16:35:46'), -(115, 'login', '隐私权政策', 'string', 'loginPolicy', '隐私权政策..
', '', 1130, '', 1, 1, '2021-09-29 23:51:21', '2023-05-14 16:35:46'), -(116, 'login', '默认注册角色', 'int64', 'loginRoleId', '202', '', 1140, '', 1, 1, '2021-09-29 23:51:21', '2023-05-14 16:35:46'), -(117, 'login', '默认注册部门', 'int64', 'loginDeptId', '112', '', 1150, '', 1, 1, '2021-09-29 23:51:21', '2023-05-14 16:35:46'), -(118, 'login', '默认注册岗位', '[]int64', 'loginPostIds', '[4,6]', '', 1160, '', 1, 1, '2021-09-29 23:51:21', '2023-05-14 16:35:46'), -(119, 'login', '默认注册头像', 'string', 'loginAvatar', 'http://localhost:8000/attachment/2023-05-14/csltf747yrr4gd4kc5.png', '', 1170, '', 1, 1, '2021-09-29 23:51:21', '2023-05-14 16:35:46'); +(112, 'login', '注册开关', 'int', 'loginRegisterSwitch', '1', '1', 1100, '', 1, 1, '2021-09-29 23:51:21', '2023-05-15 09:46:09'), +(113, 'login', '验证码开关', 'int', 'loginCaptchaSwitch', '1', '1', 1110, '', 1, 1, '2021-09-29 23:51:21', '2023-05-15 09:46:09'), +(114, 'login', '用户协议', 'string', 'loginProtocol', '用户协议..
', '', 1120, '', 1, 1, '2021-09-29 23:51:21', '2023-05-15 09:46:09'), +(115, 'login', '隐私权政策', 'string', 'loginPolicy', '隐私权政策..
', '', 1130, '', 1, 1, '2021-09-29 23:51:21', '2023-05-15 09:46:09'), +(116, 'login', '默认注册角色', 'int64', 'loginRoleId', '202', '', 1140, '', 1, 1, '2021-09-29 23:51:21', '2023-05-15 09:46:09'), +(117, 'login', '默认注册部门', 'int64', 'loginDeptId', '112', '', 1150, '', 1, 1, '2021-09-29 23:51:21', '2023-05-15 09:46:09'), +(118, 'login', '默认注册岗位', '[]int64', 'loginPostIds', '[6]', '', 1160, '', 1, 1, '2021-09-29 23:51:21', '2023-05-15 09:46:09'), +(119, 'login', '默认注册头像', 'string', 'loginAvatar', 'http://localhost:8000/attachment/2023-05-14/csltf747yrr4gd4kc5.png', '', 1170, '', 1, 1, '2021-09-29 23:51:21', '2023-05-15 09:46:09'), +(120, 'login', '强制邀请', 'int', 'loginForceInvite', '2', '1', 1190, '', 1, 1, '2021-09-29 23:51:21', '2023-05-15 09:46:09'), +(121, 'login', '自动获取openId', 'int', 'loginAutoOpenId', '2', '1', 1195, '', 1, 1, '2021-09-29 23:51:21', '2023-05-15 09:46:09'); -- -------------------------------------------------------- @@ -5941,7 +5944,7 @@ ALTER TABLE `hg_sys_blacklist` -- 使用表AUTO_INCREMENT `hg_sys_config` -- ALTER TABLE `hg_sys_config` - MODIFY `id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '配置ID', AUTO_INCREMENT=120; + MODIFY `id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '配置ID', AUTO_INCREMENT=122; -- -- 使用表AUTO_INCREMENT `hg_sys_cron` diff --git a/server/utility/file/mime.go b/server/utility/file/mime.go index b6f59ca..7857ba6 100644 --- a/server/utility/file/mime.go +++ b/server/utility/file/mime.go @@ -3,7 +3,6 @@ // @Copyright Copyright (c) 2023 HotGo CLI // @Author Ms <133814250@qq.com> // @License https://github.com/bufanyun/hotgo/blob/master/LICENSE -// package file import ( @@ -11,7 +10,7 @@ import ( "github.com/gogf/gf/v2/frame/g" "github.com/gogf/gf/v2/net/ghttp" "github.com/gogf/gf/v2/text/gstr" - "io/ioutil" + "io" "path" ) @@ -139,7 +138,7 @@ func UploadFileByte(file *ghttp.UploadFile) (b []byte, err error) { if err != nil { return } - all, err := ioutil.ReadAll(open) + all, err := io.ReadAll(open) if err != nil { return } diff --git a/web/src/router/router-guards.ts b/web/src/router/router-guards.ts index b22f793..52b33ce 100644 --- a/web/src/router/router-guards.ts +++ b/web/src/router/router-guards.ts @@ -1,13 +1,13 @@ import type { RouteRecordRaw } from 'vue-router'; import { isNavigationFailure, Router } from 'vue-router'; -import { UserInfoState, useUserStoreWidthOut } from '@/store/modules/user'; +import { useUserStoreWidthOut } from '@/store/modules/user'; import { useAsyncRouteStoreWidthOut } from '@/store/modules/asyncRoute'; import { ACCESS_TOKEN } from '@/store/mutation-types'; import { storage } from '@/utils/Storage'; import { PageEnum } from '@/enums/pageEnum'; import { ErrorPageRoute } from '@/router/base'; -import { isWechatBrowser } from '@/utils/is'; import { jump } from '@/utils/http/axios'; +import { getNowUrl } from '@/utils/urlUtils'; const LOGIN_PATH = PageEnum.BASE_LOGIN; const whitePathList = [LOGIN_PATH]; // no redirect whitelist @@ -64,21 +64,20 @@ export function createRouterGuards(router: Router) { const redirect = decodeURIComponent(redirectPath); const nextData = to.path === redirect ? { ...to, replace: true } : { path: redirect }; const userInfo = await userStore.GetInfo(); + await userStore.LoadLoginConfig(); - // 如果是微信访问,则记录本次登录的openid - if (isWechatBrowser() && (userInfo as UserInfoState).openId === '') { + // 是否允许获取微信openid + if (userStore.allowWxOpenId()) { let path = nextData.path; if (path === LOGIN_PATH) { path = PageEnum.BASE_HOME_REDIRECT; } - const w = window.location; - const URI = w.protocol + '//' + w.host + w.pathname + '#' + path; + const URI = getNowUrl() + '#' + path; jump('/wechat/authorize', { type: 'openId', syncRedirect: URI }); return; } - await userStore.LoadLoginConfig(); await userStore.GetConfig(); const routes = await asyncRouteStore.generateRoutes(userInfo); diff --git a/web/src/store/modules/user.ts b/web/src/store/modules/user.ts index 419a8e5..ea4bdac 100644 --- a/web/src/store/modules/user.ts +++ b/web/src/store/modules/user.ts @@ -17,6 +17,7 @@ import { logout, mobileLogin, } from '@/api/system/user'; +import { isWechatBrowser } from '@/utils/is'; const Storage = createStorage({ storage: localStorage }); export interface UserInfoState { @@ -59,6 +60,7 @@ export interface ConfigState { export interface LoginConfigState { loginRegisterSwitch: number; loginCaptchaSwitch: number; + loginAutoOpenId: number; loginProtocol: string; loginPolicy: string; } @@ -218,6 +220,18 @@ export const useUserStore = defineStore({ }); }); }, + // 是否允许获取微信openid + allowWxOpenId(): boolean { + if (!isWechatBrowser()) { + return false; + } + + if (this.loginConfig?.loginAutoOpenId !== 1) { + return false; + } + + return this.info?.openId === ''; + }, // 登出 async logout() { try { diff --git a/web/src/utils/urlUtils.ts b/web/src/utils/urlUtils.ts index d0d6216..584b156 100644 --- a/web/src/utils/urlUtils.ts +++ b/web/src/utils/urlUtils.ts @@ -41,3 +41,11 @@ export function getFileExt(fileName: string) { } return fileName.substring(fileName.lastIndexOf('.') + 1); } + +/** + * 获取当访问的url,不含参数 + */ +export function getNowUrl(): string { + const w = window.location; + return w.protocol + '//' + w.host + w.pathname; +} diff --git a/web/src/views/login/components/form-other.vue b/web/src/views/login/components/form-other.vue index 7aae11f..dbe11ea 100644 --- a/web/src/views/login/components/form-other.vue +++ b/web/src/views/login/components/form-other.vue @@ -18,7 +18,11 @@ - @@ -27,9 +31,8 @@