修复用户可以禁用自己的bug

This commit is contained in:
郑杰
2018-09-19 17:50:07 +08:00
parent e6d6037e3f
commit 13d2750f75
6 changed files with 19 additions and 8 deletions
@@ -12,6 +12,7 @@ import me.aurora.service.UserService;
import me.aurora.service.mapper.UserMapper;
import me.aurora.util.HttpContextUtils;
import me.aurora.config.exception.AuroraException;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authz.annotation.Logical;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
@@ -152,7 +153,8 @@ public class UserController {
@PutMapping(value = "/updateEnabled")
public ResponseEntity updateEnabled(@RequestParam Long id){
log.warn("REST request to updateEnabled");
userService.updateEnabled(id);
User user = (User) SecurityUtils.getSubject().getPrincipal();
userService.updateEnabled(id,user);
return ResponseEntity.ok();
}
@@ -4,6 +4,7 @@ import lombok.extern.slf4j.Slf4j;
import me.aurora.config.AuroraProperties;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.io.ClassPathResource;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import java.io.BufferedReader;
import java.io.IOException;
@@ -88,5 +88,5 @@ public interface UserService {
* @return
*/
@CacheEvict(allEntries = true)
void updateEnabled(Long id);
void updateEnabled(Long id, User user);
}
@@ -144,8 +144,12 @@ public class UserServiceImpl implements UserService {
}
@Override
public void updateEnabled(Long id) {
User user = userRepo.findById(id).get();
user.setEnabled(user.getEnabled()==1?0:1);
public void updateEnabled(Long id, User user) {
if(id.equals(user.getId())){
throw new AuroraException(HttpStatus.HTTP_BAD_REQUEST,"不能禁用自己");
}
User user1 = userRepo.findById(id).get();
user1.setEnabled(user1.getEnabled()==1?0:1);
userRepo.save(user1);
}
}
+1 -1
View File
@@ -108,7 +108,7 @@
</div>
<!-- footer -->
<div class="layui-footer" kit-footer="true">
2017 © kit.zhengjinfan.cn MIT license
2018 © zhengjie.me MIT license
<div style="width:400px; height:400px;" class="load-container load1">
<div class="loader">Loading...</div>
</div>
+6 -2
View File
@@ -50,6 +50,7 @@
<label class="layui-form-label">状态</label>
<div class=layui-input-lump>
<select name="enabled" lay-verify="">
<option value="">请选择...</option>
<option value="1">允许登录</option>
<option value="0">禁止登录</option>
</select>
@@ -153,9 +154,12 @@
type: "PUT",
success: function(data){
if (data.code == 200) {
layer.msg(data.msg, {icon: 1, time: 1000});
layer.msg(data.msg, {icon: 6, time: 1500});
} else {
layer.msg(data.msg, {icon: 1, time: 1000});
layer.msg(data.msg, {icon: 5, time: 1500});
setTimeout(function () {
location.reload(true)
},1500);
}
}
});