From f298fbcbcad469aa5443afa8b0caefe0a6faf302 Mon Sep 17 00:00:00 2001 From: qiaowei Date: Wed, 8 May 2019 15:55:30 +0800 Subject: [PATCH] =?utf8?q?=E4=BF=AE=E6=94=B9=E7=99=BB=E5=BD=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../framework/filter/ValidateCodeFilter.java | 14 ++- .../system/controller/OperatorController.java | 79 +++++++++++++-- .../dlpay/system/service/OperatorService.java | 3 + .../service/impl/OperatorServiceImpl.java | 10 ++ .../resources/static/custom/module/index.js | 19 +--- src/main/resources/templates/index.html | 15 +-- src/main/resources/templates/login.html | 4 +- .../templates/system/function/index.html | 2 +- .../templates/system/operator/logs.html | 2 +- .../templates/system/operator/setpwd.html | 81 ++++++++++++++++ .../templates/system/operator/userinfor.html | 97 +++++++++++++++++++ .../templates/system/role/index.html | 2 +- 12 files changed, 285 insertions(+), 43 deletions(-) create mode 100644 src/main/resources/templates/system/operator/setpwd.html create mode 100644 src/main/resources/templates/system/operator/userinfor.html diff --git a/src/main/java/com/supwisdom/dlpay/framework/filter/ValidateCodeFilter.java b/src/main/java/com/supwisdom/dlpay/framework/filter/ValidateCodeFilter.java index bd8e660e..77242b9f 100755 --- a/src/main/java/com/supwisdom/dlpay/framework/filter/ValidateCodeFilter.java +++ b/src/main/java/com/supwisdom/dlpay/framework/filter/ValidateCodeFilter.java @@ -1,11 +1,14 @@ package com.supwisdom.dlpay.framework.filter; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.supwisdom.dlpay.api.bean.JsonResult; import com.supwisdom.dlpay.exception.ValidateCodeException; import com.supwisdom.dlpay.framework.security.validate.ImageCodeUtil; import com.supwisdom.dlpay.framework.security.validate.VerifyCode; import com.supwisdom.dlpay.framework.util.StringUtil; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.HttpStatus; import org.springframework.security.web.authentication.AuthenticationFailureHandler; import org.springframework.security.web.authentication.AuthenticationSuccessHandler; import org.springframework.stereotype.Component; @@ -32,6 +35,8 @@ public class ValidateCodeFilter extends OncePerRequestFilter{ */ @Autowired private AuthenticationSuccessHandler myAuthenticationSuccessHandler; + @Autowired + private ObjectMapper objectMapper; @Override @@ -43,7 +48,12 @@ public class ValidateCodeFilter extends OncePerRequestFilter{ try { validate(request); } catch (ValidateCodeException e) { - myAuthenticationFailureHandler.onAuthenticationFailure(request, response, e); + response.setStatus(HttpStatus.OK.value()); + response.setContentType("application/json;charset=UTF-8"); + response.getWriter().write(objectMapper.writeValueAsString(JsonResult.error(400, e.getMessage()))); + //response.sendError(HttpStatus.UNAUTHORIZED.value(),e.getMessage()); + //myAuthenticationFailureHandler.onAuthenticationFailure(request, response, e); + return; } } filterChain.doFilter(request, response); @@ -58,7 +68,7 @@ public class ValidateCodeFilter extends OncePerRequestFilter{ throw new ValidateCodeException("获取验证码的值失败"); } if (StringUtil.isEmpty(inputCode)) { - throw new ValidateCodeException("验证码的值不能为空"); + throw new ValidateCodeException("验证码不能为空"); } if (null == imageCode) { throw new ValidateCodeException("验证码不存在"); diff --git a/src/main/java/com/supwisdom/dlpay/system/controller/OperatorController.java b/src/main/java/com/supwisdom/dlpay/system/controller/OperatorController.java index 173cc64f..dc0ef579 100644 --- a/src/main/java/com/supwisdom/dlpay/system/controller/OperatorController.java +++ b/src/main/java/com/supwisdom/dlpay/system/controller/OperatorController.java @@ -1,10 +1,8 @@ package com.supwisdom.dlpay.system.controller; import com.supwisdom.dlpay.api.bean.JsonResult; -import com.supwisdom.dlpay.framework.domain.TFunction; -import com.supwisdom.dlpay.framework.domain.TOperLog; -import com.supwisdom.dlpay.framework.domain.TOperRole; -import com.supwisdom.dlpay.framework.domain.TOperator; +import com.supwisdom.dlpay.framework.domain.*; +import com.supwisdom.dlpay.framework.security.OperUtil; import com.supwisdom.dlpay.framework.util.PageResult; import com.supwisdom.dlpay.framework.util.StringUtil; import com.supwisdom.dlpay.framework.util.WebConstant; @@ -18,6 +16,7 @@ import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; +import org.springframework.ui.ModelMap; import org.springframework.web.bind.annotation.*; import java.util.List; @@ -42,8 +41,7 @@ public class OperatorController { public PageResult getDataList(@RequestParam("page") Integer pageNo, @RequestParam("limit") Integer pageSize, @RequestParam(value = "searchkey", required = false) String searchKey, - @RequestParam(value = "searchvalue", required = false) String searchValue, - Model model) { + @RequestParam(value = "searchvalue", required = false) String searchValue) { try { if (null == pageNo || pageNo < 1) pageNo = WebConstant.PAGENO_DEFAULT; @@ -81,12 +79,13 @@ public class OperatorController { } return JsonResult.ok("success"); } + @PostMapping("/getoperatorrole") @ResponseBody - public JsonResult getoperatorrole( @RequestParam(value = "operid") String operid) { + public JsonResult getoperatorrole(@RequestParam(value = "operid") String operid) { List roles = operatorService.getOperRoleByOperId(operid); JsonResult ret = JsonResult.ok("success"); - ret.put("roles",roles); + ret.put("roles", roles); return ret; } @@ -125,16 +124,18 @@ public class OperatorController { return JsonResult.error("操作失败"); } } + @PostMapping("/updatestate") @PreAuthorize("hasPermission('/operator/updatestate','')") @ResponseBody - public JsonResult updatestate(@RequestParam("operid") String operid,@RequestParam("state") String state) { - if (operatorService.updateState(operid,state)) { + public JsonResult updatestate(@RequestParam("operid") String operid, @RequestParam("state") String state) { + if (operatorService.updateState(operid, state)) { return JsonResult.ok("操作成功"); } else { return JsonResult.error("操作失败"); } } + @GetMapping("/logs") public String logs() { return "system/operator/logs"; @@ -159,4 +160,62 @@ public class OperatorController { return new PageResult<>(99, "系统查询错误"); } } + + @GetMapping("/userinfor") + public String userinfor(ModelMap map) { + TOperator operator = OperUtil.getCurrentOper(); + if(operator!=null){ + operator = operatorService.getOperatorByCode(operator.getOpercode()); + } + map.put("user", operator); + return "system/operator/userinfor"; + } + + @PostMapping("/updateinfor") + @ResponseBody + public JsonResult updateinfor(@RequestBody TOperator oper) { + TOperator operator = OperUtil.getCurrentOper(); + if (oper != null) { + operator.setSex(oper.getSex()); + operator.setOpername(oper.getOpername()); + operator.setEmail(oper.getEmail()); + operator.setMobile(oper.getMobile()); + operatorService.saveOperator(operator); + } + return JsonResult.ok("操作成功"); + } + + @GetMapping("/setpwd") + public String setpwd(ModelMap map) { + return "system/operator/setpwd"; + } + + @PostMapping("/dosetpwd") + @ResponseBody + public JsonResult dosetpwd(@RequestParam String curpwd, + @RequestParam String newpwd, @RequestParam String renewpwd) { + if (StringUtil.isEmpty(curpwd) + || StringUtil.isEmpty(newpwd) + || StringUtil.isEmpty(renewpwd)) { + return JsonResult.error("参数粗错误"); + } + BCryptPasswordEncoder encoder = new BCryptPasswordEncoder(); + String encpwd = encoder.encode(curpwd); + TOperator operator = OperUtil.getCurrentOper(); + if (operator == null) { + return JsonResult.error(401, "登录已过期,请重新登录"); + } + if (!encoder.matches(curpwd,operator.getPassword())) { + return JsonResult.error("当前密码错误"); + } + if (!newpwd.equals(renewpwd)) { + return JsonResult.error("两次密码不一致"); + } + if(newpwd.length()<6||newpwd.length()>20){ + return JsonResult.error("密码6~20个字符"); + } + operator.setOperpwd(encoder.encode(newpwd)); + operatorService.saveOperator(operator); + return JsonResult.ok("密码修改成功,请重新登录"); + } } diff --git a/src/main/java/com/supwisdom/dlpay/system/service/OperatorService.java b/src/main/java/com/supwisdom/dlpay/system/service/OperatorService.java index a975eb21..39540455 100644 --- a/src/main/java/com/supwisdom/dlpay/system/service/OperatorService.java +++ b/src/main/java/com/supwisdom/dlpay/system/service/OperatorService.java @@ -38,4 +38,7 @@ public interface OperatorService { @Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class, readOnly = true) PageResult getOperLogs(LogBean param); + + @Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class) + boolean saveOperator(TOperator operator); } diff --git a/src/main/java/com/supwisdom/dlpay/system/service/impl/OperatorServiceImpl.java b/src/main/java/com/supwisdom/dlpay/system/service/impl/OperatorServiceImpl.java index 59909304..e58032ef 100644 --- a/src/main/java/com/supwisdom/dlpay/system/service/impl/OperatorServiceImpl.java +++ b/src/main/java/com/supwisdom/dlpay/system/service/impl/OperatorServiceImpl.java @@ -160,4 +160,14 @@ public class OperatorServiceImpl implements OperatorService { } return new PageResult<>(operLogDao.findAll(pageable)); } + + @Override + public boolean saveOperator(TOperator operator) { + Optional temp = operatorDao.findById(operator.getOperid()); + if (!temp.isPresent()) { + return false; + } + operatorDao.save(operator); + return true; + } } diff --git a/src/main/resources/static/custom/module/index.js b/src/main/resources/static/custom/module/index.js index 1217d02c..6b492961 100755 --- a/src/main/resources/static/custom/module/index.js +++ b/src/main/resources/static/custom/module/index.js @@ -8,9 +8,10 @@ layui.define(['admin', 'layer', 'element'], function (exports) { // 路由注册 initRouter: function () { // 自动扫描side菜单注册 - $('.layui-layout-admin .layui-side .layui-nav a[lay-href]').each(function () { + $('.layui-layout-admin .layui-nav a[lay-href]').each(function () { var menuName = $(this).text(); var menuPath = $(this).attr('lay-href'); + console.log(menuPath,menuName); if ('javascript:;' != menuPath && '' != menuPath) { var key = menuPath.replace(/[?:=&/]/g, '_'); $(this).attr('href', '#!' + key); @@ -25,6 +26,7 @@ layui.define(['admin', 'layer', 'element'], function (exports) { $(this).attr('href', 'javascript:;'); } }); + // 主页 Q.init({ index: 'home_console' @@ -136,21 +138,6 @@ layui.define(['admin', 'layer', 'element'], function (exports) { location.replace('logout'); }); }); - - // 修改密码点击事件 - $('#setPsw').click(function () { - admin.popupRight('home/password'); - }); - - // 个人信息点击事件 - $('#setInfo').click(function () { - - }); - - // 消息点击事件 - $('#btnMessage').click(function () { - admin.popupRight('home/message'); - }); } }; diff --git a/src/main/resources/templates/index.html b/src/main/resources/templates/index.html index 7dec8c5f..a9594517 100755 --- a/src/main/resources/templates/index.html +++ b/src/main/resources/templates/index.html @@ -39,21 +39,15 @@
  • - + [[${loginOper.opername}]]
    -
    - 个人信息 -
    -
    - 修改密码 -
    +
    基本资料
    +
    修改密码

    -
    - 退出 -
    +
    退出
  • @@ -153,6 +147,7 @@ index.checkPageTabs(true); // 检查多标签是否开启 index.initRouter(); // 导航栏和tab联动 index.bindEvent(); // 绑定事件 + }); diff --git a/src/main/resources/templates/login.html b/src/main/resources/templates/login.html index 81e84718..0cef69eb 100644 --- a/src/main/resources/templates/login.html +++ b/src/main/resources/templates/login.html @@ -97,6 +97,7 @@ data: field, type: 'POST', success: function (data) { + console.log(data); if (200 == data.code) { layer.msg('登录成功', {icon: 1, time: 1500}, function () { location.replace('./'); @@ -108,10 +109,9 @@ } }, error: function (xhr) { - console.log('error'); console.log(xhr); layer.closeAll('loading'); - layer.msg('登录失败,请按f12查看console错误信息', {icon: 5}); + layer.msg('登录失败', {icon: 5}); } }); }); diff --git a/src/main/resources/templates/system/function/index.html b/src/main/resources/templates/system/function/index.html index 245090cf..3696dc7f 100755 --- a/src/main/resources/templates/system/function/index.html +++ b/src/main/resources/templates/system/function/index.html @@ -2,7 +2,7 @@ diff --git a/src/main/resources/templates/system/operator/logs.html b/src/main/resources/templates/system/operator/logs.html index 4213ac00..125ce8d2 100644 --- a/src/main/resources/templates/system/operator/logs.html +++ b/src/main/resources/templates/system/operator/logs.html @@ -2,7 +2,7 @@ diff --git a/src/main/resources/templates/system/operator/setpwd.html b/src/main/resources/templates/system/operator/setpwd.html new file mode 100644 index 00000000..d5499461 --- /dev/null +++ b/src/main/resources/templates/system/operator/setpwd.html @@ -0,0 +1,81 @@ +
    +
    修改密码
    +
    +
    +
    +
    + +
    + +
    +
    +
    + +
    + +
    +
    +
    + +
    + +
    +
    +
    +
    + + +
    +
    +
    +
    +
    +
    + \ No newline at end of file diff --git a/src/main/resources/templates/system/operator/userinfor.html b/src/main/resources/templates/system/operator/userinfor.html new file mode 100644 index 00000000..8ca3c103 --- /dev/null +++ b/src/main/resources/templates/system/operator/userinfor.html @@ -0,0 +1,97 @@ +
    +
    设置我的资料
    +
    +
    +
    +
    + +
    + +
    +
    +
    + +
    + +
    +
    +
    + +
    + + +
    +
    +
    + +
    + +
    +
    +
    + +
    + +
    +
    +
    +
    + + +
    +
    +
    +
    +
    +
    + \ No newline at end of file diff --git a/src/main/resources/templates/system/role/index.html b/src/main/resources/templates/system/role/index.html index 2d3f1677..93c755d0 100644 --- a/src/main/resources/templates/system/role/index.html +++ b/src/main/resources/templates/system/role/index.html @@ -2,7 +2,7 @@ -- 2.17.1