package com.product.admin.controller; import com.alibaba.fastjson.JSONObject; import com.product.admin.config.CmnConst; import com.product.admin.config.SystemCode; import com.product.admin.service.PersonalCenterService; import com.product.admin.service.idel.IPersonalCenterService; import com.product.common.lang.StringUtils; import com.product.core.cache.DataPoolCacheImpl; import com.product.core.config.CoreConst; import com.product.core.config.Global; import com.product.core.controller.support.AbstractBaseController; import com.product.core.entity.FieldSetEntity; import com.product.core.entity.RequestParameterEntity; import com.product.core.exception.BaseException; import com.product.core.permission.PermissionService; import com.product.core.rsa.GenerateRSAKey; import com.product.core.spring.context.SpringMVCContextHolder; import com.product.core.sso.SingleSignOnOauthService; import com.product.module.sys.config.SystemErrorCode; import com.product.module.sys.service.UserService; import com.product.module.sys.version.ApiVersion; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RestController; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpSession; import java.io.IOException; import java.text.ParseException; import java.util.Date; /** * Copyright LX-BASE * * @Title: PersonalCenterController * @Project: LX-BASE-SERVER * @Date: 2020-05-30 17:25 * @Author: ZhouJie * @Description: 个人中心、及密码问题 */ @RestController @RequestMapping("/api/personalcenter") public class PersonalCenterController extends AbstractBaseController { @Autowired private PersonalCenterService personalCenterService; @Autowired UserService userService; @Autowired SingleSignOnOauthService singleSignOnOauthService; @Autowired IPersonalCenterService ipersonalCenterService; /** * 数据权限验证 */ @Autowired PermissionService permissionService; @PostMapping("/update-user-avatar/{version}") @ApiVersion(1) public String updateUserAvatar(HttpServletRequest request) { try { FieldSetEntity fse = null; Object bean = request.getAttribute(CoreConst.API_POST_REQUEST_DATA); if (bean != null) { RequestParameterEntity reqp = (RequestParameterEntity) bean; fse = reqp.getFormData(); } if (bean == null || fse == null) { SpringMVCContextHolder.getSystemLogger().error(SystemCode.SYSTEM_FORM_NODATA.getValue(), SystemCode.SYSTEM_FORM_NODATA.getText()); return this.error(SystemCode.SYSTEM_FORM_NODATA.getValue(), SystemCode.SYSTEM_FORM_NODATA.getText()); } // 判断表名是否正常 if (fse.getTableName() == null || !CmnConst.PRODUCT_SYS_USERS.equals(fse.getTableName())) { SpringMVCContextHolder.getSystemLogger().error(SystemCode.SYSTEM_TABLE_NODATA.getValue(), SystemCode.SYSTEM_TABLE_NODATA.getText()); return this.error(SystemCode.SYSTEM_TABLE_NODATA.getValue(), SystemCode.SYSTEM_TABLE_NODATA.getText()); } String uuid = SpringMVCContextHolder.getCurrentUser().getUuid(); fse.setValue(CmnConst.UUID, uuid); personalCenterService.updateUserAvatar(fse); return OK(); } catch (BaseException e) { SpringMVCContextHolder.getSystemLogger().error(e); return error(e.getCode(), e.getMessageInfo()); } catch (Exception e) { e.printStackTrace(); SpringMVCContextHolder.getSystemLogger().error(e); return error(SystemCode.GET_USER_INFO_FIAL.getValue(), SystemCode.GET_USER_INFO_FIAL.getText() + e.getMessage()); } } @PostMapping("/update-personal-info/{version}") @ApiVersion(1) public String updatePersonalInfo(HttpServletRequest request) { try { FieldSetEntity fse = null; Object bean = request.getAttribute(CoreConst.API_POST_REQUEST_DATA); if (bean != null) { RequestParameterEntity reqp = (RequestParameterEntity) bean; fse = reqp.getFormData(); } if (bean == null || fse == null) { SpringMVCContextHolder.getSystemLogger().error(SystemCode.SYSTEM_FORM_NODATA.getValue(), SystemCode.SYSTEM_FORM_NODATA.getText()); return this.error(SystemCode.SYSTEM_FORM_NODATA.getValue(), SystemCode.SYSTEM_FORM_NODATA.getText()); } // 判断表名是否正常 if (fse.getTableName() == null || !CmnConst.PRODUCT_SYS_USERS.equals(fse.getTableName())) { SpringMVCContextHolder.getSystemLogger().error(SystemCode.SYSTEM_TABLE_NODATA.getValue(), SystemCode.SYSTEM_TABLE_NODATA.getText()); return this.error(SystemCode.SYSTEM_TABLE_NODATA.getValue(), SystemCode.SYSTEM_TABLE_NODATA.getText()); } IPersonalCenterService service = (IPersonalCenterService) getProxyInstance(this.personalCenterService); service.updatePersonalInfo(fse); return OK(); } catch (BaseException e) { SpringMVCContextHolder.getSystemLogger().error(e); return error(e.getCode(), e.getMessageInfo()); } catch (Exception e) { e.printStackTrace(); SpringMVCContextHolder.getSystemLogger().error(e); return error(SystemCode.GET_USER_INFO_FIAL.getValue(), SystemCode.GET_USER_INFO_FIAL.getText() + e.getMessage()); } } @PostMapping("/personal-info/{version}") @ApiVersion(1) public String personalCenterInfo(HttpServletRequest request) { try { return OK_List(personalCenterService.personalCenterInfo()); } catch (BaseException e) { SpringMVCContextHolder.getSystemLogger().error(e); return error(e.getCode(), e.getMessageInfo()); } catch (Exception e) { e.printStackTrace(); SpringMVCContextHolder.getSystemLogger().error(e); return error(SystemCode.GET_USER_INFO_FIAL.getValue(), SystemCode.GET_USER_INFO_FIAL.getText() + e.getMessage()); } } /** * @Date: 2020-05-30 13:58 * @Author: ZhouJie * @Description: 查询个人基本信息 */ @RequestMapping(value = "/find-userinfo/{version}", method = RequestMethod.POST) @ApiVersion(1) public String findUerInfo(HttpServletRequest request) { try { FieldSetEntity fse = null; Object bean = request.getAttribute(CoreConst.API_POST_REQUEST_DATA); if (bean != null) { RequestParameterEntity reqp = (RequestParameterEntity) bean; fse = reqp.getFormData(); } if (bean == null || fse == null) { SpringMVCContextHolder.getSystemLogger().error(SystemCode.SYSTEM_FORM_NODATA.getValue(), SystemCode.SYSTEM_FORM_NODATA.getText()); return this.error(SystemCode.SYSTEM_FORM_NODATA.getValue(), SystemCode.SYSTEM_FORM_NODATA.getText()); } String uuid = SpringMVCContextHolder.getCurrentUser().getUuid(); //判断是否获取到当前登录用户ID //周杰 2020年12月17日 上午11:16 if (StringUtils.isEmpty(uuid)) { SpringMVCContextHolder.getSystemLogger().error(SystemCode.SYSTEM_FORM_NODATA.getValue(), SystemCode.SYSTEM_FORM_NODATA.getText()); return this.error(SystemCode.SYSTEM_FORM_NODATA.getValue(), SystemCode.SYSTEM_FORM_NODATA.getText()); } //数据操作的权限验证 if (!permissionService.validDataPermission(CmnConst.PRODUCT_SYS_USERS, uuid, CoreConst.DATA_PERMISSION_VALID_TYPE_USER)) { SpringMVCContextHolder.getSystemLogger().error(SystemErrorCode.SYSTEM_NOT_OPER_PERMISSION.getValue(), SystemErrorCode.SYSTEM_NOT_OPER_PERMISSION.getText()); return this.error(SystemErrorCode.SYSTEM_NOT_OPER_PERMISSION.getValue(), SystemErrorCode.SYSTEM_NOT_OPER_PERMISSION.getText()); } FieldSetEntity fs = personalCenterService.findUserInfoByUserUuid(fse.getString("uuid")); return OK_List(fs); } catch (BaseException e) { SpringMVCContextHolder.getSystemLogger().error(e); return this.error(e); } catch (Exception e) { SpringMVCContextHolder.getSystemLogger().error(e); return this.error(SystemCode.SYSTEM_ACQUIRE_PARAM_FAIL.getValue(), SystemCode.SYSTEM_ACQUIRE_PARAM_FAIL.getText()); } } /** * @Date: 2020-05-30 13:59 * @Author: ZhouJie * @Description: 修改个人基本信息 */ @RequestMapping(value = "/update-userinfo/{version}", method = RequestMethod.POST) @ApiVersion(1) public String updateUserInfo(HttpServletRequest request) { try { FieldSetEntity fse = null; Object bean = request.getAttribute(CoreConst.API_POST_REQUEST_DATA); if (bean != null) { RequestParameterEntity reqp = (RequestParameterEntity) bean; fse = reqp.getFormData(); } //判断传参是否为空 if (bean == null || fse == null) { SpringMVCContextHolder.getSystemLogger().error(SystemCode.SYSTEM_FORM_NODATA.getValue(), SystemCode.SYSTEM_FORM_NODATA.getText()); return this.error(SystemCode.SYSTEM_FORM_NODATA.getValue(), SystemCode.SYSTEM_FORM_NODATA.getText()); } //数据操作的权限验证 if (!permissionService.validDataPermission(fse, CoreConst.DATA_PERMISSION_VALID_TYPE_USER)) { SpringMVCContextHolder.getSystemLogger().error(SystemErrorCode.SYSTEM_NOT_OPER_PERMISSION.getValue(), SystemErrorCode.SYSTEM_NOT_OPER_PERMISSION.getText()); return this.error(SystemErrorCode.SYSTEM_NOT_OPER_PERMISSION.getValue(), SystemErrorCode.SYSTEM_NOT_OPER_PERMISSION.getText()); } //增加创建者和创建时间 fse.setValue("updated_by", SpringMVCContextHolder.getCurrentUser().getUser_id());// 获取登录帐号 fse.setValue("updated_utc_datetime", new Date());// 创建时间 boolean success = personalCenterService.update(fse); if (success) { return OK(); } SpringMVCContextHolder.getSystemLogger().error(SystemCode.SYSTEM_USER_UPDATE_FAIL.getValue(), SystemCode.SYSTEM_USER_UPDATE_FAIL.getText()); return error(SystemCode.SYSTEM_USER_UPDATE_FAIL.getValue(), SystemCode.SYSTEM_USER_UPDATE_FAIL.getText()); } catch (BaseException e) { SpringMVCContextHolder.getSystemLogger().error(e); return this.error(e); } catch (Exception e) { SpringMVCContextHolder.getSystemLogger().error(e); return this.error(SystemCode.SYSTEM_USER_UPDATE_FAIL.getValue(), SystemCode.SYSTEM_USER_UPDATE_FAIL.getText()); } } /** * @Date: 2020-05-30 13:59 * @Author: ZhouJie * @Description: 修改密码(发送修改邮件) 后端通过token和userId 生成一个接口链接,发送给用户邮箱 */ @RequestMapping(value = "/send-updatePwdEmail/{version}", method = {RequestMethod.POST}) @ApiVersion(1) public String sendUpdatePwdEmail(HttpServletRequest request) { try { FieldSetEntity fse = null; Object userName = null; Object bean = request.getAttribute(CoreConst.API_POST_REQUEST_DATA); if (bean != null) { RequestParameterEntity reqp = (RequestParameterEntity) bean; fse = reqp.getFormData(); userName = reqp.getFormData().getObject(CmnConst.USER_ACCOUNT); //是否启用登录用户名密码的非对称加密 boolean isEnable = Global.getPropertyToBoolean("login.ecc.isEnable", "false"); if (userName != null && isEnable) { //用户名解密 userName = GenerateRSAKey.decrypt_str(userName.toString()); reqp.getFormData().setValue(CmnConst.USER_ACCOUNT, userName); } } //判断传参是否为空 if (bean == null || fse == null) { SpringMVCContextHolder.getSystemLogger().error(SystemCode.SYSTEM_FORM_NODATA.getValue(), SystemCode.SYSTEM_FORM_NODATA.getText()); return this.error(SystemCode.SYSTEM_FORM_NODATA.getValue(), SystemCode.SYSTEM_FORM_NODATA.getText()); } //发送修改密码邮件请求 personalCenterService.sendPasswordResetEmail(fse); JSONObject result = new JSONObject(); result.put("data", fse.getString(CmnConst.USER_ACCOUNT)); result.put("code", "200"); result.put("status", "success"); result.put("msg", SystemCode.SYSTEM_OPERATION_SUCCESS.getText()); return result.toJSONString(); } catch (BaseException e) { SpringMVCContextHolder.getSystemLogger().error(e); return this.error(e); } catch (Exception e) { SpringMVCContextHolder.getSystemLogger().error(e); return this.error(SystemCode.SYSTEM_PASSWORD_EMAIL_FAIL.getValue(), SystemCode.SYSTEM_PASSWORD_EMAIL_FAIL.getText()); } } /** * @Date: 2020-08-19 18:59 * @Author: ZhouJie * @Description: token验证 */ @RequestMapping(value = "/check-token/{version}", method = {RequestMethod.POST}) @ApiVersion(1) public String checkToken(HttpServletRequest request, HttpServletResponse response, HttpSession session) throws ParseException, IOException { Object bean = request.getAttribute(CoreConst.API_POST_REQUEST_DATA); String token = null; FieldSetEntity fse = null; try { RequestParameterEntity reqp = (RequestParameterEntity) bean; if (bean != null) { token = reqp.getToken(); fse = reqp.getFormData(); } if (bean == null || fse == null) { SpringMVCContextHolder.getSystemLogger().error(SystemCode.SYSTEM_FORM_NODATA.getValue(), SystemCode.SYSTEM_FORM_NODATA.getText()); return this.error(SystemCode.SYSTEM_FORM_NODATA.getValue(), SystemCode.SYSTEM_FORM_NODATA.getText()); } if (singleSignOnOauthService.oauth(token, request, response)) { return this.OKToken(response); } else { SpringMVCContextHolder.getSystemLogger().error(SystemCode.SYSTEM_AUTHENTICATION_ERROR.getValue(), SystemCode.SYSTEM_AUTHENTICATION_ERROR.getText()); return this.error(SystemCode.SYSTEM_AUTHENTICATION_ERROR.getValue(), SystemCode.SYSTEM_AUTHENTICATION_ERROR.getText()); } } catch (BaseException e) { SpringMVCContextHolder.getSystemLogger().error(e); return this.error(e); } catch (Exception e) { SpringMVCContextHolder.getSystemLogger().error(e); return this.error(SystemCode.SYSTEM_AUTHENTICATION_ERROR.getValue(), SystemCode.SYSTEM_AUTHENTICATION_ERROR.getText()); } } /** * 通用操作成功、修改成功、删除成功 */ public String OKToken(HttpServletResponse response) { JSONObject result = new JSONObject(); result.put(CoreConst.API_RETURN_KEY_CODE, CoreConst.API_RETURN_VALUE_CODE_200); result.put(CoreConst.API_RETURN_KEY_STATUS, CoreConst.API_RETURN_VALUE_STATUS_SUCCESS); result.put(CoreConst.API_RETURN_KEY_MSG, CoreConst.API_RETURN_VALUE_MSG_SUCCESS); result.put(CoreConst.ACCESS_TOKEN, response.getHeader(CoreConst.ACCESS_TOKEN)); result.put(CoreConst.REFRESH_TOKEN, response.getHeader(CoreConst.REFRESH_TOKEN)); return result.toJSONString(); } /** * @Date: 2020-05-30 15:30 * @Author: ZhouJie * @Description: 保存新密码(登录修改密码 , 需要输入旧密码验证) */ @RequestMapping(value = "/save-updatepwd/{version}", method = {RequestMethod.POST}) @ApiVersion(1) public String saveUpdatePwd(HttpServletRequest request) { Object userName = null; Object pwd = null; Object old_pwd = null; try { FieldSetEntity fse = null; Object bean = request.getAttribute(CoreConst.API_POST_REQUEST_DATA); RequestParameterEntity reqp = null; if (bean != null) { reqp = (RequestParameterEntity) bean; fse = reqp.getFormData(); userName = reqp.getFormData().getObject(CmnConst.USER_ACCOUNT); //是否启用登录用户名密码的非对称加密 boolean isEnable = Global.getPropertyToBoolean("login.ecc.isEnable", "false"); if (userName != null && isEnable) { //用户名解密 userName = GenerateRSAKey.decrypt_str(userName.toString()); reqp.getFormData().setValue(CmnConst.USER_ACCOUNT, userName); } pwd = reqp.getFormData().getObject("user_pwd"); if (pwd != null && isEnable) { //密码解密 pwd = GenerateRSAKey.decrypt_str(pwd.toString()); reqp.getFormData().setValue("user_pwd", pwd); } old_pwd = reqp.getFormData().getObject("old_pwd"); if (old_pwd != null && isEnable) { //旧密码解密 old_pwd = GenerateRSAKey.decrypt_str(old_pwd.toString()); reqp.getFormData().setValue("old_pwd", old_pwd); } } if (bean == null || fse == null) { SpringMVCContextHolder.getSystemLogger().error(SystemCode.SYSTEM_FORM_NODATA.getValue(), SystemCode.SYSTEM_FORM_NODATA.getText()); return this.error(SystemCode.SYSTEM_FORM_NODATA.getValue(), SystemCode.SYSTEM_FORM_NODATA.getText()); } IPersonalCenterService service = (IPersonalCenterService) getProxyInstance(ipersonalCenterService); boolean success = service.saveUpdatePwd(fse); if (success) { //退出后清除缓存的中的用户信息 DataPoolCacheImpl.getInstance().removeSessionUser(); return OK(); } SpringMVCContextHolder.getSystemLogger().error(SystemCode.SYSTEM_PASSWORD_UPDATE_FAIL.getValue(), SystemCode.SYSTEM_PASSWORD_UPDATE_FAIL.getText()); return error(SystemCode.SYSTEM_PASSWORD_UPDATE_FAIL.getValue(), SystemCode.SYSTEM_PASSWORD_UPDATE_FAIL.getText()); } catch (BaseException e) { SpringMVCContextHolder.getSystemLogger().error(e); return this.error(e); } catch (Exception e) { SpringMVCContextHolder.getSystemLogger().error(e); return this.error(SystemCode.SYSTEM_PASSWORD_UPDATE_FAIL.getValue(), SystemCode.SYSTEM_PASSWORD_UPDATE_FAIL.getText()); } } /** * @Date: 2020-08-18 17:30 * @Author: ZhouJie * @Description: 保存新密码(忘记密码 , 直接保存新密码) */ @RequestMapping(value = "/save-newpwd/{version}", method = {RequestMethod.POST}) @ApiVersion(1) public String saveNewPwd(HttpServletRequest request) { try { FieldSetEntity fse = null; Object pwd = null; Object bean = request.getAttribute(CoreConst.API_POST_REQUEST_DATA); RequestParameterEntity reqp = null; if (bean != null) { reqp = (RequestParameterEntity) bean; fse = reqp.getFormData(); //是否启用登录密码的非对称加密 boolean isEnable = Global.getPropertyToBoolean("login.ecc.isEnable", "false"); pwd = reqp.getFormData().getObject("user_pwd"); if (pwd != null && isEnable) { //密码解密 pwd = GenerateRSAKey.decrypt_str(pwd.toString()); reqp.getFormData().setValue("user_pwd", pwd); } } if (bean == null || fse == null) { SpringMVCContextHolder.getSystemLogger().error(SystemCode.SYSTEM_FORM_NODATA.getValue(), SystemCode.SYSTEM_FORM_NODATA.getText()); return this.error(SystemCode.SYSTEM_FORM_NODATA.getValue(), SystemCode.SYSTEM_FORM_NODATA.getText()); } IPersonalCenterService service = (IPersonalCenterService) getProxyInstance(ipersonalCenterService); boolean success = service.saveNewPwd(fse); if (success) { //清除用户登录失败的锁定信息 userService.loginSuccessProcess(SpringMVCContextHolder.getCurrentUser()); //退出后清除缓存的中的用户信息 DataPoolCacheImpl.getInstance().removeSessionUser(); return OK(); } SpringMVCContextHolder.getSystemLogger().error(SystemCode.SYSTEM_PASSWORD_UPDATE_FAIL.getValue(), SystemCode.SYSTEM_PASSWORD_UPDATE_FAIL.getText()); return error(SystemCode.SYSTEM_PASSWORD_UPDATE_FAIL.getValue(), SystemCode.SYSTEM_PASSWORD_UPDATE_FAIL.getText()); } catch (BaseException e) { SpringMVCContextHolder.getSystemLogger().error(e); return this.error(e); } catch (Exception e) { SpringMVCContextHolder.getSystemLogger().error(e); return this.error(SystemCode.SYSTEM_PASSWORD_UPDATE_FAIL.getValue(), SystemCode.SYSTEM_PASSWORD_UPDATE_FAIL.getText()); } } /** * @Date: 2020-08-24 18:30 * @Author: ZhouJie * @Description: 返回密码强度正则表达式 */ @RequestMapping(value = "/return-security/{version}", method = {RequestMethod.POST}) @ApiVersion(1) public String returnPwdSecurity(HttpServletRequest request) { try { FieldSetEntity fse = null; Object language_uuid = null; Object bean = request.getAttribute(CoreConst.API_POST_REQUEST_DATA); if (bean != null) { RequestParameterEntity reqp = (RequestParameterEntity) bean; language_uuid = reqp.getOther().get(CoreConst.SYSTEM_LANGUAGE_CODE_); fse = reqp.getFormData(); } //判断参数是否为空 if (bean == null || fse == null) { SpringMVCContextHolder.getSystemLogger().error(SystemCode.SYSTEM_FORM_NODATA.getValue(), SystemCode.SYSTEM_FORM_NODATA.getText()); return this.error(SystemCode.SYSTEM_FORM_NODATA.getValue(), SystemCode.SYSTEM_FORM_NODATA.getText()); } FieldSetEntity returnPasswordSecurity = personalCenterService.returnPwdSecurity(language_uuid); if (returnPasswordSecurity == null) { SpringMVCContextHolder.getSystemLogger().error(SystemCode.SYSTEM_ACQUIRE_PARAM_FAIL.getValue(), SystemCode.SYSTEM_ACQUIRE_PARAM_FAIL.getText()); return this.error(SystemCode.SYSTEM_ACQUIRE_PARAM_FAIL.getValue(), SystemCode.SYSTEM_ACQUIRE_PARAM_FAIL.getText()); } return OK_List(returnPasswordSecurity); } catch (BaseException e) { SpringMVCContextHolder.getSystemLogger().error(e); return this.error(e); } catch (Exception e) { e.printStackTrace(); SpringMVCContextHolder.getSystemLogger().error(e); return this.error(SystemCode.SYSTEM_ACQUIRE_PARAM_FAIL.getValue(), SystemCode.SYSTEM_ACQUIRE_PARAM_FAIL.getText()); } } }