|
|
@@ -12,6 +12,7 @@ import org.springframework.security.core.Authentication;
|
|
|
import org.springframework.security.core.AuthenticationException;
|
|
|
import org.springframework.security.core.context.SecurityContextHolder;
|
|
|
import org.springframework.security.core.userdetails.UserDetails;
|
|
|
+import org.springframework.web.bind.annotation.PathVariable;
|
|
|
import org.springframework.web.bind.annotation.RequestBody;
|
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
import org.springframework.web.bind.annotation.RequestMethod;
|
|
|
@@ -19,6 +20,7 @@ import org.springframework.web.bind.annotation.RestController;
|
|
|
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
import com.xintong.visualinspection.bean.User;
|
|
|
+import com.xintong.visualinspection.err.BusinessException;
|
|
|
import com.xintong.visualinspection.pojo.JwtAuthenticationResponse;
|
|
|
import com.xintong.visualinspection.securityTools.RedisCacheUtil;
|
|
|
import com.xintong.visualinspection.service.AuthService;
|
|
|
@@ -44,25 +46,28 @@ public class UserController extends BaseController {
|
|
|
@Value("${jwt.header}")
|
|
|
private String tokenHeader;
|
|
|
|
|
|
- @RequestMapping(value = "/auth/login",method=RequestMethod.POST)
|
|
|
+ @RequestMapping(value = "/auth/login",method=RequestMethod.POST,produces="application/json;charset=UTF-8")
|
|
|
public String login(@RequestBody User user){
|
|
|
User u = authService.login(user.getUsername(), user.getPassword());
|
|
|
return returnSuccessResult("登陆成功", u);
|
|
|
}
|
|
|
|
|
|
- @RequestMapping(value = "/logout",method=RequestMethod.POST)
|
|
|
+ @RequestMapping(value = "/logout",method=RequestMethod.POST,produces="application/json;charset=UTF-8")
|
|
|
public String logout(){
|
|
|
//获取用户名
|
|
|
String username = SecurityContextHolder.getContext().getAuthentication().getName();
|
|
|
if(username!=null){
|
|
|
redisCacheUtil.removeForUserName(username);
|
|
|
}
|
|
|
- //返回参数
|
|
|
- return returnSuccessResult("退出成功");
|
|
|
+ throw new BusinessException(20002);
|
|
|
+ //返回成功
|
|
|
+// return returnSuccessResult("退出成功");
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
+
|
|
|
+
|
|
|
/**
|
|
|
* 添加用户
|
|
|
* @return
|
|
|
@@ -71,11 +76,11 @@ public class UserController extends BaseController {
|
|
|
* @since 1.0.0
|
|
|
*/
|
|
|
@PreAuthorize("hasRole('ADMIN')")
|
|
|
- @RequestMapping(value = "/addUser")
|
|
|
+ @RequestMapping(value = "/addUser",method=RequestMethod.POST,produces="application/json;charset=UTF-8")
|
|
|
public String addUser(@RequestBody User user) throws Exception{
|
|
|
user.setPassword(new Md5PasswordEncoder().encodePassword(user.getPassword(), null));
|
|
|
userService.insert(user);
|
|
|
- return super.returnResult(0, "添加成功", null);
|
|
|
+ return returnResult(0, "添加成功", null);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -102,13 +107,14 @@ public class UserController extends BaseController {
|
|
|
* @exception
|
|
|
* @since 1.0.0
|
|
|
*/
|
|
|
- @RequestMapping(value = "/deleteUser")
|
|
|
- public String deleteUser(@RequestBody String id){
|
|
|
+ @PreAuthorize("hasRole('ADMIN')")
|
|
|
+ @RequestMapping(value = "/deleteUser/{userid}",method=RequestMethod.POST,produces="application/json;charset=UTF-8")
|
|
|
+ public String deleteUser(@PathVariable String userid){
|
|
|
try{
|
|
|
- userService.delete(Long.parseLong(id));
|
|
|
- return super.returnResult(0, "删除成功", null);
|
|
|
+ userService.delete(Long.parseLong(userid));
|
|
|
+ return returnResult(0, "删除成功", null);
|
|
|
}catch(Exception e){
|
|
|
- return super.returnResult(-1, "删除失败", null);
|
|
|
+ throw new BusinessException(20002);
|
|
|
}
|
|
|
}
|
|
|
|