@Test public void testGetUserInfo() throws Exception { }
public CommonResult getUserInfo(String token){ try { Claims claims = JwtUtil.checkToken(token.substring(7)); Integer userId = Integer.parseInt(claims.getSubject()); User user = userMapper.getUserInfo(userId); JSONObject result = new JSONObject(); if(user != null){ result.put("userId", user.getId()); result.put("userName", user.getName()); result.put("avatar", user.getAvatar()); List<Role> roles = roleMapper.listRole(userId); result.put("roles", roles); return CommonResult.success(result); } else{ return CommonResult.fail(E_601); } }catch (UserLoginInvalidException e) { return CommonResult.fail(E_604); } catch (UserLoginException e) { return CommonResult.fail(E_603); } catch (IOException e){ e.printStackTrace(); return CommonResult.fail(E_603); } }
UserServiceImpl implements UserService { public CommonResult getUserInfo(String token){ try { Claims claims = JwtUtil.checkToken(token.substring(7)); Integer userId = Integer.parseInt(claims.getSubject()); User user = userMapper.getUserInfo(userId); JSONObject result = new JSONObject(); if(user != null){ result.put("userId", user.getId()); result.put("userName", user.getName()); result.put("avatar", user.getAvatar()); List<Role> roles = roleMapper.listRole(userId); result.put("roles", roles); return CommonResult.success(result); } else{ return CommonResult.fail(E_601); } }catch (UserLoginInvalidException e) { return CommonResult.fail(E_604); } catch (UserLoginException e) { return CommonResult.fail(E_603); } catch (IOException e){ e.printStackTrace(); return CommonResult.fail(E_603); } } }
UserServiceImpl implements UserService { public CommonResult getUserInfo(String token){ try { Claims claims = JwtUtil.checkToken(token.substring(7)); Integer userId = Integer.parseInt(claims.getSubject()); User user = userMapper.getUserInfo(userId); JSONObject result = new JSONObject(); if(user != null){ result.put("userId", user.getId()); result.put("userName", user.getName()); result.put("avatar", user.getAvatar()); List<Role> roles = roleMapper.listRole(userId); result.put("roles", roles); return CommonResult.success(result); } else{ return CommonResult.fail(E_601); } }catch (UserLoginInvalidException e) { return CommonResult.fail(E_604); } catch (UserLoginException e) { return CommonResult.fail(E_603); } catch (IOException e){ e.printStackTrace(); return CommonResult.fail(E_603); } }  }
UserServiceImpl implements UserService { public CommonResult getUserInfo(String token){ try { Claims claims = JwtUtil.checkToken(token.substring(7)); Integer userId = Integer.parseInt(claims.getSubject()); User user = userMapper.getUserInfo(userId); JSONObject result = new JSONObject(); if(user != null){ result.put("userId", user.getId()); result.put("userName", user.getName()); result.put("avatar", user.getAvatar()); List<Role> roles = roleMapper.listRole(userId); result.put("roles", roles); return CommonResult.success(result); } else{ return CommonResult.fail(E_601); } }catch (UserLoginInvalidException e) { return CommonResult.fail(E_604); } catch (UserLoginException e) { return CommonResult.fail(E_603); } catch (IOException e){ e.printStackTrace(); return CommonResult.fail(E_603); } }  CommonResult setUserAvatar(Integer id, String avatarUrl); CommonResult setUserPassword(Integer userId, String oldPassword, String newPassword); CommonResult getUserInfo(String  token); }
UserServiceImpl implements UserService { public CommonResult getUserInfo(String token){ try { Claims claims = JwtUtil.checkToken(token.substring(7)); Integer userId = Integer.parseInt(claims.getSubject()); User user = userMapper.getUserInfo(userId); JSONObject result = new JSONObject(); if(user != null){ result.put("userId", user.getId()); result.put("userName", user.getName()); result.put("avatar", user.getAvatar()); List<Role> roles = roleMapper.listRole(userId); result.put("roles", roles); return CommonResult.success(result); } else{ return CommonResult.fail(E_601); } }catch (UserLoginInvalidException e) { return CommonResult.fail(E_604); } catch (UserLoginException e) { return CommonResult.fail(E_603); } catch (IOException e){ e.printStackTrace(); return CommonResult.fail(E_603); } }  CommonResult setUserAvatar(Integer id, String avatarUrl); CommonResult setUserPassword(Integer userId, String oldPassword, String newPassword); CommonResult getUserInfo(String  token);  }