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 | 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 | 318 | @RequestMapping(value = "/register", method = RequestMethod.POST) |
| 307 | 319 | public Map<String, Object> register(SysUser u) { |
| 308 | 320 | return sysUserService.register(u); | ... | ... |
src/main/java/com/bsth/service/sys/SysUserService.java
| ... | ... | @@ -7,13 +7,19 @@ import java.util.List; |
| 7 | 7 | import java.util.Map; |
| 8 | 8 | |
| 9 | 9 | public interface SysUserService extends BaseService<SysUser, Integer>{ |
| 10 | - | |
| 10 | + | |
| 11 | 11 | SysUser findByUserName(String name); |
| 12 | - | |
| 12 | + | |
| 13 | 13 | int changeEnabled(int id,int enabled); |
| 14 | - | |
| 14 | + | |
| 15 | 15 | int changePWD(int id,String newPWD); |
| 16 | 16 | |
| 17 | + /** | |
| 18 | + * 检测指定用户密码是否过期 | |
| 19 | + * @param userName 用户名 | |
| 20 | + */ | |
| 21 | + boolean validPWDExpired(String userName); | |
| 22 | + | |
| 17 | 23 | void resetPWD(int id, String newPWD, int validperiod); |
| 18 | 24 | |
| 19 | 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 | 5 | import com.bsth.repository.sys.SysUserRepository; |
| 6 | 6 | import com.bsth.service.impl.BaseServiceImpl; |
| 7 | 7 | import com.bsth.service.sys.SysUserService; |
| 8 | +import org.joda.time.DateTime; | |
| 9 | +import org.joda.time.Days; | |
| 8 | 10 | import org.slf4j.Logger; |
| 9 | 11 | import org.slf4j.LoggerFactory; |
| 10 | 12 | import org.springframework.beans.factory.annotation.Autowired; |
| ... | ... | @@ -22,15 +24,15 @@ public class SysUserServiceImpl extends BaseServiceImpl<SysUser, Integer> implem |
| 22 | 24 | SysUserRepository sysUserRepository; |
| 23 | 25 | |
| 24 | 26 | Logger logger = LoggerFactory.getLogger(this.getClass()); |
| 25 | - | |
| 27 | + | |
| 26 | 28 | @Override |
| 27 | 29 | public SysUser findByUserName(String name) { |
| 28 | 30 | return sysUserRepository.findByUserName(name); |
| 29 | 31 | } |
| 30 | - | |
| 32 | + | |
| 31 | 33 | @Override |
| 32 | 34 | public Map<String, Object> save(SysUser t) { |
| 33 | - // | |
| 35 | + // | |
| 34 | 36 | if(t.getPassword() == null || t.getPassword().trim().equals("")){ |
| 35 | 37 | SysUser user = sysUserRepository.findOne(t.getId()); |
| 36 | 38 | t.setPassword(user.getPassword()); |
| ... | ... | @@ -52,6 +54,32 @@ public class SysUserServiceImpl extends BaseServiceImpl<SysUser, Integer> implem |
| 52 | 54 | } |
| 53 | 55 | |
| 54 | 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 | 83 | public void resetPWD(int id, String newPWD, int validperiod) { |
| 56 | 84 | SysUser user = sysUserRepository.findOne(id); |
| 57 | 85 | user.setPwdValidPeriod(validperiod); | ... | ... |
src/main/resources/static/pages/home.html
| ... | ... | @@ -81,3 +81,24 @@ |
| 81 | 81 | <li><span class="label s_c_change">修复</span>3、修复基础中线路站点的序号问题。</li> |
| 82 | 82 | </ul> |
| 83 | 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 | 64 | <td> |
| 65 | 65 | <button class="btn btn-sm green btn-outline filter-submit margin-bottom" > |
| 66 | 66 | <i class="fa fa-search"></i> 搜索</button> |
| 67 | - | |
| 67 | + | |
| 68 | 68 | <button class="btn btn-sm red btn-outline filter-cancel"> |
| 69 | 69 | <i class="fa fa-times"></i> 重置</button> |
| 70 | 70 | </td> |
| ... | ... | @@ -134,15 +134,15 @@ $(function(){ |
| 134 | 134 | checkboxClass: 'icheckbox_flat-blue', |
| 135 | 135 | increaseArea: '20%' |
| 136 | 136 | }; |
| 137 | - | |
| 137 | + | |
| 138 | 138 | jsDoQuery(null,true); |
| 139 | - | |
| 139 | + | |
| 140 | 140 | //重置 |
| 141 | 141 | $('tr.filter .filter-cancel').on('click', function(){ |
| 142 | 142 | $('tr.filter input, select').val('').change(); |
| 143 | 143 | jsDoQuery(null, true); |
| 144 | 144 | }); |
| 145 | - | |
| 145 | + | |
| 146 | 146 | //提交 |
| 147 | 147 | $('tr.filter .filter-submit').on('click', function(){ |
| 148 | 148 | var cells = $('tr.filter')[0].cells |
| ... | ... | @@ -160,7 +160,7 @@ $(function(){ |
| 160 | 160 | page = 0; |
| 161 | 161 | jsDoQuery(params, true); |
| 162 | 162 | }); |
| 163 | - | |
| 163 | + | |
| 164 | 164 | /* |
| 165 | 165 | * 获取数据 p: 要提交的参数, pagination: 是否重新分页 |
| 166 | 166 | */ |
| ... | ... | @@ -208,20 +208,20 @@ $(function(){ |
| 208 | 208 | |
| 209 | 209 | }); |
| 210 | 210 | } |
| 211 | - | |
| 211 | + | |
| 212 | 212 | function iCheckChange(){ |
| 213 | 213 | var tr = $(this).parents('tr'); |
| 214 | 214 | if(this.checked) |
| 215 | 215 | tr.addClass('row-active'); |
| 216 | 216 | else |
| 217 | 217 | tr.removeClass('row-active'); |
| 218 | - | |
| 218 | + | |
| 219 | 219 | if($('#datatable_resource input.icheck:checked').length == 1) |
| 220 | 220 | $('#removeButton').removeAttr('disabled'); |
| 221 | 221 | else |
| 222 | 222 | $('#removeButton').attr('disabled', 'disabled'); |
| 223 | 223 | } |
| 224 | - | |
| 224 | + | |
| 225 | 225 | function showPagination(data){ |
| 226 | 226 | //分页 |
| 227 | 227 | $('#pagination').jqPaginator({ |
| ... | ... | @@ -237,15 +237,15 @@ $(function(){ |
| 237 | 237 | if(initPagination){ |
| 238 | 238 | initPagination = false; |
| 239 | 239 | return; |
| 240 | - } | |
| 241 | - | |
| 242 | - | |
| 240 | + } | |
| 241 | + | |
| 242 | + | |
| 243 | 243 | page = num - 1; |
| 244 | 244 | jsDoQuery(null, false); |
| 245 | 245 | } |
| 246 | 246 | }); |
| 247 | 247 | } |
| 248 | - | |
| 248 | + | |
| 249 | 249 | function openAllotWindow() { |
| 250 | 250 | var id = $(this).data('id'); |
| 251 | 251 | $.get('/pages/permission/user/controlAllot.html', function (content) { |
| ... | ... | @@ -262,14 +262,14 @@ $(function(){ |
| 262 | 262 | }); |
| 263 | 263 | }); |
| 264 | 264 | } |
| 265 | - | |
| 265 | + | |
| 266 | 266 | //删除 |
| 267 | 267 | $('#removeButton').on('click', function(){ |
| 268 | 268 | if($(this).attr('disabled')) |
| 269 | 269 | return; |
| 270 | - | |
| 270 | + | |
| 271 | 271 | var id = $('#datatable_resource input.icheck:checked').data('id'); |
| 272 | - | |
| 272 | + | |
| 273 | 273 | removeConfirm('确定要删除选中的数据?', '/resource/' + id ,function(){ |
| 274 | 274 | $('tr.filter .filter-submit').click(); |
| 275 | 275 | }); |
| ... | ... | @@ -294,9 +294,10 @@ function resetPassword(userId, ld) { |
| 294 | 294 | success: function (layero, index) { |
| 295 | 295 | $(layero).find('#user_id').val(userId); |
| 296 | 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 | 303 | \ No newline at end of file |
| 304 | +</script> | ... | ... |
src/main/resources/static/pages/permission/user/resetPWD.html
| ... | ... | @@ -2,6 +2,7 @@ |
| 2 | 2 | <div class="col-md-12"> |
| 3 | 3 | <!-- BEGIN VALIDATION STATES--> |
| 4 | 4 | <div class="portlet light portlet-fit portlet-form bordered"> |
| 5 | + <input type="hidden" id="window_index" name="window_index"> | |
| 5 | 6 | <div class="portlet-body"> |
| 6 | 7 | <form class="form-horizontal" id="resetPWDForm"> |
| 7 | 8 | <input type="hidden" id="user_id" name="user_id"> |
| ... | ... | @@ -37,7 +38,7 @@ |
| 37 | 38 | <div class="row"> |
| 38 | 39 | <div class="col-md-offset-5 col-md-7"> |
| 39 | 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 | 42 | </div> |
| 42 | 43 | </div> |
| 43 | 44 | </div> |
| ... | ... | @@ -58,5 +59,10 @@ |
| 58 | 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 | 68 | \ No newline at end of file |
| 69 | +</script> | ... | ... |