Commit 0bcd353832d2fe41b13b26f5ba28ee6798100eb4
1 parent
a83ee6e3
嘉定公交调度系统计划调度功能优化2
1、用户登录系统后,提示密码过期(过期前3天提示)
Showing
6 changed files
with
98 additions
and
24 deletions
src/main/java/com/bsth/controller/sys/UserController.java
| @@ -303,6 +303,18 @@ public class UserController extends BaseController<SysUser, Integer> { | @@ -303,6 +303,18 @@ public class UserController extends BaseController<SysUser, Integer> { | ||
| 303 | } | 303 | } |
| 304 | } | 304 | } |
| 305 | 305 | ||
| 306 | + @RequestMapping(value = "/validPWDExpired", method = RequestMethod.GET) | ||
| 307 | + public String validPWDExpired() { | ||
| 308 | + try { | ||
| 309 | + SysUser sysUser = SecurityUtils.getCurrentUser(); | ||
| 310 | + this.sysUserService.validPWDExpired(sysUser.getUserName()); | ||
| 311 | + return "ok"; | ||
| 312 | + } catch (Exception exp) { | ||
| 313 | + exp.printStackTrace(); | ||
| 314 | + return exp.getMessage(); | ||
| 315 | + } | ||
| 316 | + } | ||
| 317 | + | ||
| 306 | @RequestMapping(value = "/register", method = RequestMethod.POST) | 318 | @RequestMapping(value = "/register", method = RequestMethod.POST) |
| 307 | public Map<String, Object> register(SysUser u) { | 319 | public Map<String, Object> register(SysUser u) { |
| 308 | return sysUserService.register(u); | 320 | return sysUserService.register(u); |
src/main/java/com/bsth/service/sys/SysUserService.java
| @@ -7,13 +7,19 @@ import java.util.List; | @@ -7,13 +7,19 @@ import java.util.List; | ||
| 7 | import java.util.Map; | 7 | import java.util.Map; |
| 8 | 8 | ||
| 9 | public interface SysUserService extends BaseService<SysUser, Integer>{ | 9 | public interface SysUserService extends BaseService<SysUser, Integer>{ |
| 10 | - | 10 | + |
| 11 | SysUser findByUserName(String name); | 11 | SysUser findByUserName(String name); |
| 12 | - | 12 | + |
| 13 | int changeEnabled(int id,int enabled); | 13 | int changeEnabled(int id,int enabled); |
| 14 | - | 14 | + |
| 15 | int changePWD(int id,String newPWD); | 15 | int changePWD(int id,String newPWD); |
| 16 | 16 | ||
| 17 | + /** | ||
| 18 | + * 检测指定用户密码是否过期 | ||
| 19 | + * @param userName 用户名 | ||
| 20 | + */ | ||
| 21 | + boolean validPWDExpired(String userName); | ||
| 22 | + | ||
| 17 | void resetPWD(int id, String newPWD, int validperiod); | 23 | void resetPWD(int id, String newPWD, int validperiod); |
| 18 | 24 | ||
| 19 | Map<String,Object> register(SysUser u); | 25 | Map<String,Object> register(SysUser u); |
src/main/java/com/bsth/service/sys/impl/SysUserServiceImpl.java
| @@ -5,6 +5,8 @@ import com.bsth.entity.sys.SysUser; | @@ -5,6 +5,8 @@ import com.bsth.entity.sys.SysUser; | ||
| 5 | import com.bsth.repository.sys.SysUserRepository; | 5 | import com.bsth.repository.sys.SysUserRepository; |
| 6 | import com.bsth.service.impl.BaseServiceImpl; | 6 | import com.bsth.service.impl.BaseServiceImpl; |
| 7 | import com.bsth.service.sys.SysUserService; | 7 | import com.bsth.service.sys.SysUserService; |
| 8 | +import org.joda.time.DateTime; | ||
| 9 | +import org.joda.time.Days; | ||
| 8 | import org.slf4j.Logger; | 10 | import org.slf4j.Logger; |
| 9 | import org.slf4j.LoggerFactory; | 11 | import org.slf4j.LoggerFactory; |
| 10 | import org.springframework.beans.factory.annotation.Autowired; | 12 | import org.springframework.beans.factory.annotation.Autowired; |
| @@ -22,15 +24,15 @@ public class SysUserServiceImpl extends BaseServiceImpl<SysUser, Integer> implem | @@ -22,15 +24,15 @@ public class SysUserServiceImpl extends BaseServiceImpl<SysUser, Integer> implem | ||
| 22 | SysUserRepository sysUserRepository; | 24 | SysUserRepository sysUserRepository; |
| 23 | 25 | ||
| 24 | Logger logger = LoggerFactory.getLogger(this.getClass()); | 26 | Logger logger = LoggerFactory.getLogger(this.getClass()); |
| 25 | - | 27 | + |
| 26 | @Override | 28 | @Override |
| 27 | public SysUser findByUserName(String name) { | 29 | public SysUser findByUserName(String name) { |
| 28 | return sysUserRepository.findByUserName(name); | 30 | return sysUserRepository.findByUserName(name); |
| 29 | } | 31 | } |
| 30 | - | 32 | + |
| 31 | @Override | 33 | @Override |
| 32 | public Map<String, Object> save(SysUser t) { | 34 | public Map<String, Object> save(SysUser t) { |
| 33 | - // | 35 | + // |
| 34 | if(t.getPassword() == null || t.getPassword().trim().equals("")){ | 36 | if(t.getPassword() == null || t.getPassword().trim().equals("")){ |
| 35 | SysUser user = sysUserRepository.findOne(t.getId()); | 37 | SysUser user = sysUserRepository.findOne(t.getId()); |
| 36 | t.setPassword(user.getPassword()); | 38 | t.setPassword(user.getPassword()); |
| @@ -52,6 +54,32 @@ public class SysUserServiceImpl extends BaseServiceImpl<SysUser, Integer> implem | @@ -52,6 +54,32 @@ public class SysUserServiceImpl extends BaseServiceImpl<SysUser, Integer> implem | ||
| 52 | } | 54 | } |
| 53 | 55 | ||
| 54 | @Override | 56 | @Override |
| 57 | + public boolean validPWDExpired(String userName) { | ||
| 58 | + SysUser sysUser = this.sysUserRepository.findByUserName(userName); | ||
| 59 | + if (sysUser == null) { | ||
| 60 | + throw new RuntimeException("用户[" + userName + "]不存在!"); | ||
| 61 | + } | ||
| 62 | + if (sysUser.getPwdValidPeriod() == null || sysUser.getLastPwdDate() == null) { | ||
| 63 | + // 如果没有设定密码过期时间,判定为不过期 | ||
| 64 | + return true; | ||
| 65 | + } | ||
| 66 | + DateTime now = new DateTime(); | ||
| 67 | + DateTime lastPwdDate = new DateTime(sysUser.getLastPwdDate()); | ||
| 68 | + Integer now_period_days = Days.daysBetween(lastPwdDate, now).getDays(); | ||
| 69 | + Integer expiredTipDays = 3; // 密码过期提前提示天数 | ||
| 70 | + if (now_period_days < (sysUser.getPwdValidPeriod() - expiredTipDays)) { | ||
| 71 | + return true; | ||
| 72 | + } else if (now_period_days >= (sysUser.getPwdValidPeriod() - expiredTipDays) && | ||
| 73 | + now_period_days < sysUser.getPwdValidPeriod()) { | ||
| 74 | + // 快过期前提示 | ||
| 75 | + throw new RuntimeException("当前用户密码还有[" + (sysUser.getPwdValidPeriod() - now_period_days) + "]天过期!"); | ||
| 76 | + } else { | ||
| 77 | + throw new RuntimeException("当前用户密码已过期!"); | ||
| 78 | + } | ||
| 79 | + | ||
| 80 | + } | ||
| 81 | + | ||
| 82 | + @Override | ||
| 55 | public void resetPWD(int id, String newPWD, int validperiod) { | 83 | public void resetPWD(int id, String newPWD, int validperiod) { |
| 56 | SysUser user = sysUserRepository.findOne(id); | 84 | SysUser user = sysUserRepository.findOne(id); |
| 57 | user.setPwdValidPeriod(validperiod); | 85 | user.setPwdValidPeriod(validperiod); |
src/main/resources/static/pages/home.html
| @@ -81,3 +81,24 @@ | @@ -81,3 +81,24 @@ | ||
| 81 | <li><span class="label s_c_change">修复</span>3、修复基础中线路站点的序号问题。</li> | 81 | <li><span class="label s_c_change">修复</span>3、修复基础中线路站点的序号问题。</li> |
| 82 | </ul> | 82 | </ul> |
| 83 | </div> | 83 | </div> |
| 84 | + | ||
| 85 | +<script type="text/javascript"> | ||
| 86 | + $.get("/user/validPWDExpired", function(msg) { | ||
| 87 | + if ("ok" === msg) { | ||
| 88 | + return; | ||
| 89 | + } | ||
| 90 | + | ||
| 91 | + var htmlText = []; | ||
| 92 | + htmlText.push("<span style='font-weight: bold; font-style: italic; '>" + msg + "</span></br>"); | ||
| 93 | + swal({ | ||
| 94 | + title: "账户密码提示", | ||
| 95 | + text: htmlText.join("</br>"), | ||
| 96 | + html: true, | ||
| 97 | + type: "warning", | ||
| 98 | + showCancelButton: true, | ||
| 99 | + cancelButtonText: "关闭", | ||
| 100 | + confirmButtonColor: "#3598dc", | ||
| 101 | + closeOnConfirm: false | ||
| 102 | + }); | ||
| 103 | + }); | ||
| 104 | +</script> |
src/main/resources/static/pages/permission/user/list.html
| @@ -64,7 +64,7 @@ | @@ -64,7 +64,7 @@ | ||
| 64 | <td> | 64 | <td> |
| 65 | <button class="btn btn-sm green btn-outline filter-submit margin-bottom" > | 65 | <button class="btn btn-sm green btn-outline filter-submit margin-bottom" > |
| 66 | <i class="fa fa-search"></i> 搜索</button> | 66 | <i class="fa fa-search"></i> 搜索</button> |
| 67 | - | 67 | + |
| 68 | <button class="btn btn-sm red btn-outline filter-cancel"> | 68 | <button class="btn btn-sm red btn-outline filter-cancel"> |
| 69 | <i class="fa fa-times"></i> 重置</button> | 69 | <i class="fa fa-times"></i> 重置</button> |
| 70 | </td> | 70 | </td> |
| @@ -134,15 +134,15 @@ $(function(){ | @@ -134,15 +134,15 @@ $(function(){ | ||
| 134 | checkboxClass: 'icheckbox_flat-blue', | 134 | checkboxClass: 'icheckbox_flat-blue', |
| 135 | increaseArea: '20%' | 135 | increaseArea: '20%' |
| 136 | }; | 136 | }; |
| 137 | - | 137 | + |
| 138 | jsDoQuery(null,true); | 138 | jsDoQuery(null,true); |
| 139 | - | 139 | + |
| 140 | //重置 | 140 | //重置 |
| 141 | $('tr.filter .filter-cancel').on('click', function(){ | 141 | $('tr.filter .filter-cancel').on('click', function(){ |
| 142 | $('tr.filter input, select').val('').change(); | 142 | $('tr.filter input, select').val('').change(); |
| 143 | jsDoQuery(null, true); | 143 | jsDoQuery(null, true); |
| 144 | }); | 144 | }); |
| 145 | - | 145 | + |
| 146 | //提交 | 146 | //提交 |
| 147 | $('tr.filter .filter-submit').on('click', function(){ | 147 | $('tr.filter .filter-submit').on('click', function(){ |
| 148 | var cells = $('tr.filter')[0].cells | 148 | var cells = $('tr.filter')[0].cells |
| @@ -160,7 +160,7 @@ $(function(){ | @@ -160,7 +160,7 @@ $(function(){ | ||
| 160 | page = 0; | 160 | page = 0; |
| 161 | jsDoQuery(params, true); | 161 | jsDoQuery(params, true); |
| 162 | }); | 162 | }); |
| 163 | - | 163 | + |
| 164 | /* | 164 | /* |
| 165 | * 获取数据 p: 要提交的参数, pagination: 是否重新分页 | 165 | * 获取数据 p: 要提交的参数, pagination: 是否重新分页 |
| 166 | */ | 166 | */ |
| @@ -208,20 +208,20 @@ $(function(){ | @@ -208,20 +208,20 @@ $(function(){ | ||
| 208 | 208 | ||
| 209 | }); | 209 | }); |
| 210 | } | 210 | } |
| 211 | - | 211 | + |
| 212 | function iCheckChange(){ | 212 | function iCheckChange(){ |
| 213 | var tr = $(this).parents('tr'); | 213 | var tr = $(this).parents('tr'); |
| 214 | if(this.checked) | 214 | if(this.checked) |
| 215 | tr.addClass('row-active'); | 215 | tr.addClass('row-active'); |
| 216 | else | 216 | else |
| 217 | tr.removeClass('row-active'); | 217 | tr.removeClass('row-active'); |
| 218 | - | 218 | + |
| 219 | if($('#datatable_resource input.icheck:checked').length == 1) | 219 | if($('#datatable_resource input.icheck:checked').length == 1) |
| 220 | $('#removeButton').removeAttr('disabled'); | 220 | $('#removeButton').removeAttr('disabled'); |
| 221 | else | 221 | else |
| 222 | $('#removeButton').attr('disabled', 'disabled'); | 222 | $('#removeButton').attr('disabled', 'disabled'); |
| 223 | } | 223 | } |
| 224 | - | 224 | + |
| 225 | function showPagination(data){ | 225 | function showPagination(data){ |
| 226 | //分页 | 226 | //分页 |
| 227 | $('#pagination').jqPaginator({ | 227 | $('#pagination').jqPaginator({ |
| @@ -237,15 +237,15 @@ $(function(){ | @@ -237,15 +237,15 @@ $(function(){ | ||
| 237 | if(initPagination){ | 237 | if(initPagination){ |
| 238 | initPagination = false; | 238 | initPagination = false; |
| 239 | return; | 239 | return; |
| 240 | - } | ||
| 241 | - | ||
| 242 | - | 240 | + } |
| 241 | + | ||
| 242 | + | ||
| 243 | page = num - 1; | 243 | page = num - 1; |
| 244 | jsDoQuery(null, false); | 244 | jsDoQuery(null, false); |
| 245 | } | 245 | } |
| 246 | }); | 246 | }); |
| 247 | } | 247 | } |
| 248 | - | 248 | + |
| 249 | function openAllotWindow() { | 249 | function openAllotWindow() { |
| 250 | var id = $(this).data('id'); | 250 | var id = $(this).data('id'); |
| 251 | $.get('/pages/permission/user/controlAllot.html', function (content) { | 251 | $.get('/pages/permission/user/controlAllot.html', function (content) { |
| @@ -262,14 +262,14 @@ $(function(){ | @@ -262,14 +262,14 @@ $(function(){ | ||
| 262 | }); | 262 | }); |
| 263 | }); | 263 | }); |
| 264 | } | 264 | } |
| 265 | - | 265 | + |
| 266 | //删除 | 266 | //删除 |
| 267 | $('#removeButton').on('click', function(){ | 267 | $('#removeButton').on('click', function(){ |
| 268 | if($(this).attr('disabled')) | 268 | if($(this).attr('disabled')) |
| 269 | return; | 269 | return; |
| 270 | - | 270 | + |
| 271 | var id = $('#datatable_resource input.icheck:checked').data('id'); | 271 | var id = $('#datatable_resource input.icheck:checked').data('id'); |
| 272 | - | 272 | + |
| 273 | removeConfirm('确定要删除选中的数据?', '/resource/' + id ,function(){ | 273 | removeConfirm('确定要删除选中的数据?', '/resource/' + id ,function(){ |
| 274 | $('tr.filter .filter-submit').click(); | 274 | $('tr.filter .filter-submit').click(); |
| 275 | }); | 275 | }); |
| @@ -294,9 +294,10 @@ function resetPassword(userId, ld) { | @@ -294,9 +294,10 @@ function resetPassword(userId, ld) { | ||
| 294 | success: function (layero, index) { | 294 | success: function (layero, index) { |
| 295 | $(layero).find('#user_id').val(userId); | 295 | $(layero).find('#user_id').val(userId); |
| 296 | $(layero).find('#last_pwd_date').val(ld ? moment(ld).format("YYYY-MM-DD HH:mm:ss") : ''); | 296 | $(layero).find('#last_pwd_date').val(ld ? moment(ld).format("YYYY-MM-DD HH:mm:ss") : ''); |
| 297 | + $(layero).find('#window_index').val(index); | ||
| 297 | } | 298 | } |
| 298 | }); | 299 | }); |
| 299 | }); | 300 | }); |
| 300 | 301 | ||
| 301 | } | 302 | } |
| 302 | -</script> | ||
| 303 | \ No newline at end of file | 303 | \ No newline at end of file |
| 304 | +</script> |
src/main/resources/static/pages/permission/user/resetPWD.html
| @@ -2,6 +2,7 @@ | @@ -2,6 +2,7 @@ | ||
| 2 | <div class="col-md-12"> | 2 | <div class="col-md-12"> |
| 3 | <!-- BEGIN VALIDATION STATES--> | 3 | <!-- BEGIN VALIDATION STATES--> |
| 4 | <div class="portlet light portlet-fit portlet-form bordered"> | 4 | <div class="portlet light portlet-fit portlet-form bordered"> |
| 5 | + <input type="hidden" id="window_index" name="window_index"> | ||
| 5 | <div class="portlet-body"> | 6 | <div class="portlet-body"> |
| 6 | <form class="form-horizontal" id="resetPWDForm"> | 7 | <form class="form-horizontal" id="resetPWDForm"> |
| 7 | <input type="hidden" id="user_id" name="user_id"> | 8 | <input type="hidden" id="user_id" name="user_id"> |
| @@ -37,7 +38,7 @@ | @@ -37,7 +38,7 @@ | ||
| 37 | <div class="row"> | 38 | <div class="row"> |
| 38 | <div class="col-md-offset-5 col-md-7"> | 39 | <div class="col-md-offset-5 col-md-7"> |
| 39 | <button type="button" id="confirm" class="btn green">确定</button> | 40 | <button type="button" id="confirm" class="btn green">确定</button> |
| 40 | - <button type="button" class="btn default">取消</button> | 41 | + <button type="button" id="pwd_cancel" class="btn default">取消</button> |
| 41 | </div> | 42 | </div> |
| 42 | </div> | 43 | </div> |
| 43 | </div> | 44 | </div> |
| @@ -58,5 +59,10 @@ | @@ -58,5 +59,10 @@ | ||
| 58 | layer.alert(msg); | 59 | layer.alert(msg); |
| 59 | }); | 60 | }); |
| 60 | }); | 61 | }); |
| 62 | + | ||
| 63 | + $("#pwd_cancel").on("click", function() { | ||
| 64 | + var index = $("#window_index").val(); | ||
| 65 | + parent.layer.close(index); | ||
| 66 | + }); | ||
| 61 | }); | 67 | }); |
| 62 | -</script> | ||
| 63 | \ No newline at end of file | 68 | \ No newline at end of file |
| 69 | +</script> |