Commit cb89a8d2de6febd4dd5fbd9e2b20a03445b2ec26

Authored by 徐烜
1 parent d08cb9ee

添加管理员重置密码,密码有效期功能

src/main/java/com/bsth/controller/sys/UserController.java
@@ -107,9 +107,13 @@ public class UserController extends BaseController<SysUser, Integer> { @@ -107,9 +107,13 @@ public class UserController extends BaseController<SysUser, Integer> {
107 // 检验密码有效期 107 // 检验密码有效期
108 Date lastPwdDate = user.getLastPwdDate(); 108 Date lastPwdDate = user.getLastPwdDate();
109 if (lastPwdDate != null) { 109 if (lastPwdDate != null) {
  110 + Integer validPeriod = user.getPwdValidPeriod();
  111 + if (validPeriod == null) {
  112 + validPeriod = 180; // 默认180天
  113 + }
110 Period p = new Period(new DateTime(lastPwdDate), new DateTime(new Date()), PeriodType.days()); 114 Period p = new Period(new DateTime(lastPwdDate), new DateTime(new Date()), PeriodType.days());
111 - if (p.getDays() > 30) { // 30天不更新密码,不能登录  
112 - return put(rs, "msg", "30天没有修改密码,不能登录,请联系管理员"); 115 + if (p.getDays() > validPeriod) {
  116 + return put(rs, "msg", validPeriod + "天没有修改密码,不能登录,请联系管理员");
113 } 117 }
114 } 118 }
115 119
@@ -282,6 +286,16 @@ public class UserController extends BaseController<SysUser, Integer> { @@ -282,6 +286,16 @@ public class UserController extends BaseController<SysUser, Integer> {
282 return msg; 286 return msg;
283 } 287 }
284 288
  289 + @RequestMapping(value = "/resetPWD", method = RequestMethod.POST)
  290 + public String resetPWD(@RequestParam Integer user_id, @RequestParam Integer reset_day, @RequestParam String reset_passord) {
  291 + try {
  292 + sysUserService.resetPWD(user_id, reset_passord, reset_day);
  293 + return "修改成功!";
  294 + } catch (Exception exp) {
  295 + return exp.getMessage();
  296 + }
  297 + }
  298 +
285 @RequestMapping(value = "/register", method = RequestMethod.POST) 299 @RequestMapping(value = "/register", method = RequestMethod.POST)
286 public Map<String, Object> register(SysUser u) { 300 public Map<String, Object> register(SysUser u) {
287 return sysUserService.register(u); 301 return sysUserService.register(u);
src/main/java/com/bsth/entity/sys/SysUser.java
@@ -35,6 +35,8 @@ public class SysUser { @@ -35,6 +35,8 @@ public class SysUser {
35 35
36 /** 最近密码更新时间 */ 36 /** 最近密码更新时间 */
37 private Date lastPwdDate; 37 private Date lastPwdDate;
  38 + /** 密码有效期 */
  39 + private Integer pwdValidPeriod;
38 40
39 private String agencies; 41 private String agencies;
40 42
@@ -123,4 +125,12 @@ public class SysUser { @@ -123,4 +125,12 @@ public class SysUser {
123 public void setLastPwdDate(Date lastPwdDate) { 125 public void setLastPwdDate(Date lastPwdDate) {
124 this.lastPwdDate = lastPwdDate; 126 this.lastPwdDate = lastPwdDate;
125 } 127 }
  128 +
  129 + public Integer getPwdValidPeriod() {
  130 + return pwdValidPeriod;
  131 + }
  132 +
  133 + public void setPwdValidPeriod(Integer pwdValidPeriod) {
  134 + this.pwdValidPeriod = pwdValidPeriod;
  135 + }
126 } 136 }
src/main/java/com/bsth/service/sys/SysUserService.java
@@ -14,6 +14,8 @@ public interface SysUserService extends BaseService&lt;SysUser, Integer&gt;{ @@ -14,6 +14,8 @@ public interface SysUserService extends BaseService&lt;SysUser, Integer&gt;{
14 14
15 int changePWD(int id,String newPWD); 15 int changePWD(int id,String newPWD);
16 16
  17 + void resetPWD(int id, String newPWD, int validperiod);
  18 +
17 Map<String,Object> register(SysUser u); 19 Map<String,Object> register(SysUser u);
18 20
19 List<SysUser> findAll_distinct(); 21 List<SysUser> findAll_distinct();
src/main/java/com/bsth/service/sys/impl/SysUserServiceImpl.java
@@ -51,7 +51,14 @@ public class SysUserServiceImpl extends BaseServiceImpl&lt;SysUser, Integer&gt; implem @@ -51,7 +51,14 @@ public class SysUserServiceImpl extends BaseServiceImpl&lt;SysUser, Integer&gt; implem
51 return sysUserRepository.changePWD(id,new BCryptPasswordEncoder(4).encode(newPWD)); 51 return sysUserRepository.changePWD(id,new BCryptPasswordEncoder(4).encode(newPWD));
52 } 52 }
53 53
54 - @Override 54 + @Override
  55 + public void resetPWD(int id, String newPWD, int validperiod) {
  56 + SysUser user = sysUserRepository.findOne(id);
  57 + user.setPwdValidPeriod(validperiod);
  58 + sysUserRepository.changePWD(id, new BCryptPasswordEncoder(4).encode(newPWD));
  59 + }
  60 +
  61 + @Override
55 public Map<String, Object> register(SysUser u) { 62 public Map<String, Object> register(SysUser u) {
56 Map<String, Object> rs = new HashMap(); 63 Map<String, Object> rs = new HashMap();
57 try{ 64 try{
src/main/resources/static/pages/permission/user/list.html
@@ -115,6 +115,7 @@ @@ -115,6 +115,7 @@
115 115
116 <td> 116 <td>
117 <a class="btn btn-sm blue btn-outline" href="edit.html?no={{obj.id}}" data-pjax><i class="fa fa-edit"></i> 编辑</a> 117 <a class="btn btn-sm blue btn-outline" href="edit.html?no={{obj.id}}" data-pjax><i class="fa fa-edit"></i> 编辑</a>
  118 + <a class="btn btn-sm blue btn-outline resetpwd" style="display: {{obj.showpdc}}" onclick="resetPassword({{obj.id}}, {{obj.lastPwdDate}});"><i class="fa fa-edit"></i> 重置密码</a>
118 <!--<button type="button" class="btn btn-sm line_allot_btn" data-id="{{obj.id}}">线调线路分配</button>--> 119 <!--<button type="button" class="btn btn-sm line_allot_btn" data-id="{{obj.id}}">线调线路分配</button>-->
119 </td> 120 </td>
120 </tr> 121 </tr>
@@ -171,23 +172,40 @@ $(function(){ @@ -171,23 +172,40 @@ $(function(){
171 params['order'] = 'lastLoginDate'; 172 params['order'] = 'lastLoginDate';
172 params['page'] = page; 173 params['page'] = page;
173 var i = layer.load(2); 174 var i = layer.load(2);
174 - $get('/user' ,params, function(data){  
175 - $.each(data.content, function(i, obj) {  
176 - obj.lastLoginDate = moment(obj.lastLoginDate).format("YYYY-MM-DD HH:mm:ss"); 175 + $get('/user' ,params, function(data) {
  176 + // 获取当前登录用户
  177 + $get('/user/currentUser',{}, function(user) {
  178 + var b_isAdmin = false; // 是否是管理员用户
  179 + $.each(user.authorities, function(i, obj) {
  180 + if (obj.authority === 'ROLE_ADMIN') {
  181 + b_isAdmin = true;
  182 + }
  183 + });
  184 +
  185 + $.each(data.content, function(i, obj) {
  186 + obj.lastLoginDate = moment(obj.lastLoginDate).format("YYYY-MM-DD HH:mm:ss");
  187 + if (b_isAdmin) {
  188 + obj.showpdc = ''; // 显示重置密码按钮
  189 + } else {
  190 + obj.showpdc = 'none';
  191 + }
  192 + });
  193 + var bodyHtm = template('user_list_temp', {list: data.content});
  194 +
  195 + $('#datatable_user tbody').html(bodyHtm)
  196 + .find('.icheck').iCheck(icheckOptions)
  197 + .on('ifChanged', iCheckChange);
  198 + if(pagination && data.content.length > 0){
  199 + //重新分页
  200 + initPagination = true;
  201 + showPagination(data);
  202 + }
  203 + layer.close(i);
  204 +
  205 + $('.line_allot_btn').on('click', openAllotWindow);
  206 +
177 }); 207 });
178 - var bodyHtm = template('user_list_temp', {list: data.content});  
179 -  
180 - $('#datatable_user tbody').html(bodyHtm)  
181 - .find('.icheck').iCheck(icheckOptions)  
182 - .on('ifChanged', iCheckChange);  
183 - if(pagination && data.content.length > 0){  
184 - //重新分页  
185 - initPagination = true;  
186 - showPagination(data);  
187 - }  
188 - layer.close(i);  
189 208
190 - $('.line_allot_btn').on('click', openAllotWindow);  
191 }); 209 });
192 } 210 }
193 211
@@ -263,4 +281,22 @@ function changeEnabled(id,enabled){ @@ -263,4 +281,22 @@ function changeEnabled(id,enabled){
263 jsDoQuery(null, true); 281 jsDoQuery(null, true);
264 }) 282 })
265 } 283 }
  284 +// 重置密码
  285 +function resetPassword(userId, ld) {
  286 + $.get('/pages/permission/user/resetPWD.html', function (content) {
  287 + layer.open({
  288 + type: 1,
  289 + area: ['600px', '360px'],
  290 + content: content,
  291 + title: '修改密码',
  292 + shift: 5,
  293 + scrollbar: false,
  294 + success: function (layero, index) {
  295 + $(layero).find('#user_id').val(userId);
  296 + $(layero).find('#last_pwd_date').val(ld ? moment(ld).format("YYYY-MM-DD HH:mm:ss") : '');
  297 + }
  298 + });
  299 + });
  300 +
  301 +}
266 </script> 302 </script>
267 \ No newline at end of file 303 \ No newline at end of file
src/main/resources/static/pages/permission/user/resetPWD.html 0 → 100644
  1 +<div class="row">
  2 + <div class="col-md-12">
  3 + <!-- BEGIN VALIDATION STATES-->
  4 + <div class="portlet light portlet-fit portlet-form bordered">
  5 + <div class="portlet-body">
  6 + <form class="form-horizontal" id="resetPWDForm">
  7 + <input type="hidden" id="user_id" name="user_id">
  8 + <div class="form-group" style="margin-top: 60px">
  9 + <label class="control-label col-md-4">最近密码更新时间:
  10 + </label>
  11 + <div class="col-md-6">
  12 + <div class="input-icon right">
  13 + <i class="fa"></i>
  14 + <input type="text" readonly class="form-control" name="last_pwd_date" id="last_pwd_date" value="" /> </div>
  15 + </div>
  16 + </div>
  17 +
  18 + <div class="form-group" >
  19 + <label class="control-label col-md-4">密码有效期(天):
  20 + </label>
  21 + <div class="col-md-6">
  22 + <div class="input-icon right">
  23 + <i class="fa"></i>
  24 + <input type="number" class="form-control" name="reset_day" id="reset_day" value="180" /> </div>
  25 + </div>
  26 + </div>
  27 + <div class="form-group">
  28 + <label class="control-label col-md-4">默认密码:
  29 + </label>
  30 + <div class="col-md-6">
  31 + <div class="input-icon right">
  32 + <i class="fa"></i>
  33 + <input type="text" class="form-control" name="reset_passord" id="reset_passord" value="123456" /> </div>
  34 + </div>
  35 + </div>
  36 + <div class="form-actions">
  37 + <div class="row">
  38 + <div class="col-md-offset-5 col-md-7">
  39 + <button type="button" id="confirm" class="btn green">确定</button>
  40 + <button type="button" class="btn default">取消</button>
  41 + </div>
  42 + </div>
  43 + </div>
  44 + </form>
  45 + </div>
  46 + </div>
  47 + </div>
  48 +</div>
  49 +
  50 +
  51 +<script>
  52 + $(function(){
  53 +
  54 + $("#confirm").on("click",function(){
  55 + var data = $('#resetPWDForm').serializeJSON();
  56 + console.log(data);
  57 + $.post('/user/resetPWD',data,function(msg){
  58 + layer.alert(msg);
  59 + });
  60 + });
  61 + });
  62 +</script>
0 \ No newline at end of file 63 \ No newline at end of file