mirror of
https://github.com/dqjdda/Aurora.git
synced 2018-11-06 05:33:29 +00:00
修复设置主题,刷新后失效的bug
This commit is contained in:
@@ -153,8 +153,7 @@ public class UserController {
|
||||
@PutMapping(value = "/updateEnabled")
|
||||
public ResponseEntity updateEnabled(@RequestParam Long id){
|
||||
log.warn("REST request to updateEnabled");
|
||||
User user = (User) SecurityUtils.getSubject().getPrincipal();
|
||||
userService.updateEnabled(id,user);
|
||||
userService.updateEnabled(userService.findById(id));
|
||||
return ResponseEntity.ok();
|
||||
}
|
||||
|
||||
@@ -168,7 +167,7 @@ public class UserController {
|
||||
@DeleteMapping(value = "/delete")
|
||||
public ResponseEntity delete(@RequestParam Long id) {
|
||||
log.warn("REST request to deleteUser");
|
||||
userService.delete(id);
|
||||
userService.delete(userService.findById(id));
|
||||
return ResponseEntity.ok();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
package me.aurora.domain;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import javax.persistence.*;
|
||||
import java.io.Serializable;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@Entity
|
||||
@Table(name = "picture")
|
||||
public class Picture implements Serializable {
|
||||
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
private Long id;
|
||||
|
||||
|
||||
}
|
||||
@@ -2,7 +2,6 @@ package me.aurora.service;
|
||||
|
||||
import me.aurora.domain.User;
|
||||
import me.aurora.repository.spec.UserSpec;
|
||||
import me.aurora.config.exception.AuroraException;
|
||||
import org.springframework.cache.annotation.CacheConfig;
|
||||
import org.springframework.cache.annotation.CacheEvict;
|
||||
import org.springframework.cache.annotation.Cacheable;
|
||||
@@ -80,13 +79,13 @@ public interface UserService {
|
||||
* @return
|
||||
*/
|
||||
@CacheEvict(allEntries = true)
|
||||
void delete(Long id);
|
||||
void delete(User id);
|
||||
|
||||
/**
|
||||
* 是否允许登录
|
||||
* @param id
|
||||
* @param user
|
||||
* @return
|
||||
*/
|
||||
@CacheEvict(allEntries = true)
|
||||
void updateEnabled(Long id, User user);
|
||||
void updateEnabled(User user);
|
||||
}
|
||||
|
||||
@@ -135,21 +135,27 @@ public class UserServiceImpl implements UserService {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void delete(Long id) {
|
||||
User user = (User) SecurityUtils.getSubject().getPrincipal();
|
||||
if(user.getId().equals(id)){
|
||||
public void delete(User user) {
|
||||
if(user == null){
|
||||
throw new AuroraException(HttpStatus.HTTP_NOT_FOUND,"用户不存在,请检查缓存!!");
|
||||
}
|
||||
User u = (User) SecurityUtils.getSubject().getPrincipal();
|
||||
if(u.getId().equals(user.getId())){
|
||||
throw new AuroraException(HttpStatus.HTTP_BAD_REQUEST,"这么狠,自己都删!!");
|
||||
}
|
||||
userRepo.deleteById(id);
|
||||
userRepo.delete(user);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateEnabled(Long id, User user) {
|
||||
if(id.equals(user.getId())){
|
||||
public void updateEnabled(User user) {
|
||||
if(user == null){
|
||||
throw new AuroraException(HttpStatus.HTTP_NOT_FOUND,"用户不存在,请检查缓存!!");
|
||||
}
|
||||
User u = (User) SecurityUtils.getSubject().getPrincipal();
|
||||
if(user.getId().equals(u.getId())){
|
||||
throw new AuroraException(HttpStatus.HTTP_BAD_REQUEST,"不能禁用自己");
|
||||
}
|
||||
User user1 = userRepo.findById(id).get();
|
||||
user1.setEnabled(user1.getEnabled()==1?0:1);
|
||||
userRepo.save(user1);
|
||||
user.setEnabled(user.getEnabled()==1?0:1);
|
||||
userRepo.save(user);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user