mirror of
https://github.com/dqjdda/Aurora.git
synced 2018-11-06 05:33:29 +00:00
修复用户可以禁用自己的bug
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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>
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user