UserController.java 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260
  1. package com.bofeng.controller;
  2. import com.bofeng.service.*;
  3. import lombok.extern.slf4j.Slf4j;
  4. import me.chanjar.weixin.mp.api.WxMpService;
  5. import org.springframework.beans.factory.annotation.Autowired;
  6. import org.springframework.web.bind.annotation.GetMapping;
  7. import org.springframework.web.bind.annotation.RestController;
  8. import org.springframework.web.servlet.ModelAndView;
  9. @RestController
  10. @Slf4j
  11. public class UserController {
  12. @Autowired
  13. private UserService userService;
  14. @Autowired
  15. private SecurityService securityService;
  16. @Autowired
  17. private WxMpService mpService;
  18. @Autowired
  19. private UserOpenService userOpenService;
  20. @Autowired
  21. private UserPlaceService userPlaceService;
  22. @Autowired
  23. private PlaceService placeService;
  24. // @GetMapping("/index.html")
  25. // public ModelAndView index() {
  26. // return new ModelAndView("/index.html");
  27. // }
  28. // @GetMapping("/user/logout.html")
  29. // @PostMapping("/user/logout.html")
  30. // public ModelAndView logout() {
  31. // HttpUtils.removeCookie(JwtHelper.AUTH_COOKIE_NAME, "/");
  32. // SecurityUtils.getSubject().logout();
  33. // return new ModelAndView(new RedirectViewJs("/"));
  34. // }
  35. //
  36. // @GetMapping("/user/login.html")
  37. // public ModelAndView login() {
  38. // return new ModelAndView("/user/login.ftl");
  39. // }
  40. //
  41. // @PostMapping("/whepi/user/login.json")
  42. // public Model<LoginResult> loginPost(HttpServletResponse response,
  43. // HttpServletRequest request,
  44. // @Pd(name = "loginName") final String loginName,
  45. // @Pd(name = "loginPwd") final String loginPwd) {
  46. //
  47. // User user;
  48. // try {
  49. // user = userService.login(loginName);
  50. // //校验密码
  51. // String secretPwd = securityService.createPassword(user, loginPwd);
  52. // if (!secretPwd.equals(user.getLoginPwd())) {
  53. // throw new IncorrectCredentialsException();
  54. // }
  55. //
  56. // } catch (Exception e) {
  57. // return processException(e);
  58. // }
  59. //
  60. // //生成 Auth
  61. // String jwt = securityService.createJwt(user, false);
  62. //
  63. // //写入头部和cookie
  64. // HttpUtils.currentResponse().addHeader(JwtHelper.AUTH_HEADER_NAME, jwt);
  65. //
  66. // //返回客户端
  67. // LoginResult loginResult = new LoginResult();
  68. // loginResult.setUser(user);
  69. // loginResult.setToken(jwt);
  70. // if (Consts.USER_TYPE_ADMIN.equals(user.getUserType())) {
  71. // loginResult.setHref("/admin/index.html");
  72. // } else if (Consts.USER_TYPE_CASHIER.equals(user.getUserType())) {
  73. // loginResult.setHref("/cashier/customer_accounts.html");
  74. // } else if (Consts.USER_TYPE_WORKER.equals(user.getUserType())) {
  75. // loginResult.setHref("/worker/room_manage.html");
  76. // }
  77. //
  78. //
  79. // response.setHeader("Access-Control-Expose-Headers", JwtHelper.AUTH_HEADER_NAME);
  80. // response.setHeader(JwtHelper.AUTH_HEADER_NAME, JwtHelper.getAuthHeader(request));
  81. //
  82. // return Model.newSuccess(loginResult).setMsg("登录成功");
  83. // }
  84. //
  85. // @PostMapping("/user/reset_password.json")
  86. // public ModelOps resetPassword(@RequestBody Map map) {
  87. // String userId = JwtHelper.getUserId();
  88. // if (Strings.isNullOrEmpty(userId)) {
  89. // return ModelOps.newFail("用户不存在或登录已经过期");
  90. // }
  91. // if (Strings.isNullOrEmpty(Conv.NS(map.get("password")))) {
  92. // return ModelOps.newFail("密码不能为空");
  93. // }
  94. // if (Strings.isNullOrEmpty(Conv.NS(map.get("newPassword")))) {
  95. // return ModelOps.newFail("新密码不能为空");
  96. // }
  97. // if (!Conv.NS(map.get("newPassword")).equals(Conv.NS(map.get("repeatPassword")))) {
  98. // return ModelOps.newFail("两次密码不一致");
  99. // }
  100. // int result = userService.updatePassword(Conv.NL(userId), Conv.NS(map.get("password")),Conv.NS(map.get("newPassword")));
  101. // if (result<=0) {
  102. // return ModelOps.newFail("修改失败");
  103. // }
  104. // HttpUtils.removeCookie(JwtHelper.AUTH_COOKIE_NAME, "/");
  105. // SecurityUtils.getSubject().logout();
  106. // return ModelOps.newSuccess(result).setMsg("密码修改成功,请重新登录");
  107. // }
  108. //
  109. // private Model<LoginResult> processException(Exception e) {
  110. // Model<LoginResult> r = new Model<LoginResult>().setSuccess(false);
  111. //
  112. // if (e instanceof UnknownAccountException) {
  113. // return r.setMsg("登录账号不存在!");
  114. // }
  115. // if (e instanceof LockedAccountException) {
  116. // return r.setMsg("用户已经被锁定不能登录,请与管理员联系!");
  117. // }
  118. // if (e instanceof DisabledAccountException) {
  119. // return r.setMsg("用户已经被禁用,请与管理员联系!");
  120. // }
  121. // if (e instanceof ExcessiveAttemptsException) {
  122. // return r.setMsg("登录失败次数过多!");
  123. // }
  124. // if (e instanceof ExpiredCredentialsException) {
  125. // return r.setMsg("凭证过期!");
  126. // }
  127. // if (e instanceof IncorrectCredentialsException) {
  128. // return r.setMsg("密码错误!");
  129. // }
  130. // if (e instanceof AuthenticationException) {
  131. // return r.setMsg("用户或密码不正确!");
  132. // }
  133. //
  134. // log.error("e", e);
  135. // return r.setMsg("未知错误:" + e.getMessage());
  136. // }
  137. //
  138. // @GetMapping("/cust/user_bind.html")
  139. // public ModelAndView userBind(@RequestParam(name = "userType", required = false, defaultValue = "") String userType,
  140. // @RequestParam(name = "higherId", required = false, defaultValue = "") String higherId,
  141. // @RequestParam(name = "placeId", required = false, defaultValue = "") String placeId,
  142. // @RequestParam(name = "code", required = false, defaultValue = "") String code,
  143. // ModelMap model) throws WxErrorException {
  144. // if (!Strings.isNullOrEmpty(code)) {
  145. // WxMpOAuth2AccessToken accessToken = mpService.oauth2getAccessToken(code);
  146. // WxMpUser wxMpUser = mpService.oauth2getUserInfo(accessToken, null);
  147. //// model.put("user", user);
  148. // UserOpen userOpen = userOpenService.getUserByOpenId(wxMpUser.getOpenId());
  149. // UserPlace userPlace = null;
  150. // User user = null;
  151. //
  152. // if (userOpen != null) {
  153. // userPlace = userPlaceService.getByUserIdAndPlaceId(userOpen.getUserId(), Conv.NL(placeId));
  154. // user = userService.getUserById(userOpen.getUserId());
  155. // if (user != null) {
  156. // model.put("user", user);
  157. // }
  158. //
  159. // }
  160. // if (userPlace == null) {
  161. // Place place = placeService.getById(Conv.NL(placeId));
  162. // model.put("placeName", place.getPlaceName());
  163. // model.put("placeId", placeId);
  164. // model.put("userType", userType);
  165. // model.put("higherId", higherId);
  166. // model.put("openId", wxMpUser.getOpenId());
  167. // model.put("nickName", wxMpUser.getNickname());
  168. // model.put("sexDesc", wxMpUser.getSexDesc());
  169. // model.put("sex", wxMpUser.getSex());
  170. // model.put("city", wxMpUser.getCity());
  171. // model.put("province", wxMpUser.getProvince());
  172. // model.put("country", wxMpUser.getCountry());
  173. // model.put("headImgUrl", wxMpUser.getHeadImgUrl());
  174. // return new ModelAndView("/cust/user_bind.ftl", model);
  175. //
  176. // } else {
  177. // model.put("title", "您已经绑定过账号了!");
  178. // if (userPlace.getUserType().equals(Consts.USER_TYPE_L1)) {
  179. // model.put("message", "一级分销");
  180. // } else if (userPlace.getUserType().equals(Consts.USER_TYPE_L2)) {
  181. // model.put("message", "二级分销");
  182. // }
  183. // }
  184. // return new ModelAndView("/prompt/prompt.ftl", model);
  185. //
  186. // } else {
  187. // User user = new User();
  188. // user.setUserType("1");
  189. // model.put("user", user);
  190. // model.put("openId", "2345");
  191. // return new ModelAndView("/cust/user_bind.ftl");
  192. //
  193. // }
  194. //
  195. // }
  196. //
  197. // @PostMapping("/admin/deleteOpenId.json")
  198. // public ModelOps bindUser(@RequestParam("userId") Long userId) {
  199. // return ModelOps.newSuccess(userService.deleteOpenId(userId));
  200. // }
  201. //
  202. // @PostMapping("/cust/user_bind.json")
  203. // public ModelOps bindUser(HttpServletResponse response,
  204. // HttpServletRequest request,
  205. // @RequestBody Map map) {
  206. //
  207. //
  208. // UserOpen userOpen = userOpenService.getUserByOpenId((String) map.get("openId"));
  209. // if (userOpen == null) {
  210. // userOpen = new UserOpen();
  211. // userOpen.setUserId(IdWorker.getId());
  212. // userOpen.setBeActive("Y");
  213. // userOpen.setOpenId((String) map.get("openId"));
  214. // userOpen.setNickName((String) map.get("nickName"));
  215. // userOpen.setSex(Integer.valueOf((String) map.get("sex")));
  216. // userOpen.setSexDesc((String) map.get("sexDesc"));
  217. // userOpen.setCity((String) map.get("city"));
  218. // userOpen.setProvince((String) map.get("province"));
  219. // userOpen.setCountry((String) map.get("country"));
  220. // userOpen.setHeadImgUrl((String) map.get("headImgUrl"));
  221. // }
  222. // User user = userService.getUserById(userOpen.getUserId());
  223. // UserPlace userPlace = userPlaceService.getByUserIdAndPlaceId(userOpen.getUserId(), Conv.NL(map.get("placeId")));
  224. // if (user == null) {
  225. // user = new User();
  226. // user.setUserId(userOpen.getUserId());
  227. // user.setBeActive("Y");
  228. // user.setUserType("S");
  229. // user.setStaffName((String) map.get("staffName"));
  230. //// user.setPhone((String) map.get("phone"));
  231. //// user.setLoginName("");
  232. //// user.setVersion("1.1");
  233. //// return ModelOps.newSuccess(userOpenService.bindUserOpen(userOpen, user));
  234. // }
  235. // if (userPlace == null) {
  236. // userPlace = new UserPlace();
  237. // userPlace.setHigherId(Conv.NL(map.get("higherId")));
  238. // userPlace.setPlaceId(Conv.NL(map.get("placeId")));
  239. // userPlace.setUserId(userOpen.getUserId());
  240. // userPlace.setUserType(Conv.NS(map.get("userType")));
  241. // } else {
  242. //
  243. // return ModelOps.newFail("已经绑定");
  244. // }
  245. //
  246. // return ModelOps.newSuccess(userOpenService.bindUser(userOpen, user, userPlace));
  247. //
  248. // }
  249. }