@@ -38,9 +38,6 @@ public class AuthorizationInterceptor extends HandlerInterceptorAdapter { | |||||
@Override | @Override | ||||
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception { | public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception { | ||||
if (true) { | |||||
return true; | |||||
} | |||||
response.setHeader("Content-type", "application/json;charset=UTF-8"); | response.setHeader("Content-type", "application/json;charset=UTF-8"); | ||||
@@ -0,0 +1,55 @@ | |||||
package com.iformall.config; | |||||
import org.apache.shiro.authc.AuthenticationToken; | |||||
public class MyAuthenticationToken implements AuthenticationToken{ | |||||
private Integer projectType; | |||||
private String username; | |||||
private char[] password; | |||||
public Integer getProjectType() { | |||||
return projectType; | |||||
} | |||||
public void setProjectType(Integer projectType) { | |||||
this.projectType = projectType; | |||||
} | |||||
public String getUsername() { | |||||
return username; | |||||
} | |||||
public void setUsername(String username) { | |||||
this.username = username; | |||||
} | |||||
public char[] getPassword() { | |||||
return password; | |||||
} | |||||
public void setPassword(char[] password) { | |||||
this.password = password; | |||||
} | |||||
@Override | |||||
public Object getPrincipal() { | |||||
return getUsername(); | |||||
} | |||||
@Override | |||||
public Object getCredentials() { | |||||
return getPassword(); | |||||
} | |||||
public MyAuthenticationToken() { | |||||
} | |||||
public MyAuthenticationToken(Integer projectType, String username, char[] password) { | |||||
this.projectType = projectType; | |||||
this.username = username; | |||||
this.password = password; | |||||
} | |||||
} |
@@ -426,10 +426,10 @@ public class WxProjectConfigController extends BaseController { | |||||
} | } | ||||
boolean bChangedPhone = false; | boolean bChangedPhone = false; | ||||
if(userInfo.getId() == null){ | if(userInfo.getId() == null){ | ||||
if(userInfoService.cntByUserName(userInfo.getUsername()) > 0){ | |||||
if(userInfoService.cntByUserName(userInfo.getUsername(),EnumProject.PROJECT_2.getCode()) > 0){ | |||||
return new ResultData(ErrorCode.USER_NAME_IS_FOUND.getCode(),"用户名已存在"); | return new ResultData(ErrorCode.USER_NAME_IS_FOUND.getCode(),"用户名已存在"); | ||||
} | } | ||||
if(userInfoService.cntByUserPhone(userInfo.getPhone()) > 0){ | |||||
if(userInfoService.cntByUserPhone(userInfo.getPhone(),EnumProject.PROJECT_2.getCode()) > 0){ | |||||
return new ResultData(ErrorCode.USER_PHONE_IS_FOUND.getCode(),"手机号已存在"); | return new ResultData(ErrorCode.USER_PHONE_IS_FOUND.getCode(),"手机号已存在"); | ||||
} | } | ||||
Assert.notNull(userInfo.getPassword(), "密码不能为空"); | Assert.notNull(userInfo.getPassword(), "密码不能为空"); | ||||
@@ -442,12 +442,12 @@ public class WxProjectConfigController extends BaseController { | |||||
}else{ | }else{ | ||||
MallUserInfo oldUser = userInfoService.getById(userInfo.getId()); | MallUserInfo oldUser = userInfoService.getById(userInfo.getId()); | ||||
if (!oldUser.getUsername().equals(userInfo.getUsername())) { | if (!oldUser.getUsername().equals(userInfo.getUsername())) { | ||||
if(userInfoService.cntByUserName(userInfo.getUsername()) > 0){ | |||||
if(userInfoService.cntByUserName(userInfo.getUsername(),EnumProject.PROJECT_2.getCode()) > 0){ | |||||
return new ResultData(ErrorCode.USER_NAME_IS_FOUND.getCode(),"用户名已存在"); | return new ResultData(ErrorCode.USER_NAME_IS_FOUND.getCode(),"用户名已存在"); | ||||
} | } | ||||
} | } | ||||
if (!oldUser.getPhone().equals(userInfo.getPhone())) { | if (!oldUser.getPhone().equals(userInfo.getPhone())) { | ||||
if(userInfoService.cntByUserPhone(userInfo.getPhone()) > 0){ | |||||
if(userInfoService.cntByUserPhone(userInfo.getPhone(),EnumProject.PROJECT_2.getCode()) > 0){ | |||||
return new ResultData(ErrorCode.USER_PHONE_IS_FOUND.getCode(),"手机号已存在"); | return new ResultData(ErrorCode.USER_PHONE_IS_FOUND.getCode(),"手机号已存在"); | ||||
} | } | ||||
bChangedPhone = true; | bChangedPhone = true; | ||||
@@ -7,6 +7,7 @@ import com.iformall.common.ResultData; | |||||
import com.iformall.controller.base.BaseController; | import com.iformall.controller.base.BaseController; | ||||
import com.iformall.domain.po.WxMsgValidationcode; | import com.iformall.domain.po.WxMsgValidationcode; | ||||
import com.iformall.domain.po.base.TenantEntity; | import com.iformall.domain.po.base.TenantEntity; | ||||
import com.iformall.enums.EnumProject; | |||||
import com.iformall.service.WxMsgValidationcodeService; | import com.iformall.service.WxMsgValidationcodeService; | ||||
import io.swagger.annotations.ApiImplicitParam; | import io.swagger.annotations.ApiImplicitParam; | ||||
import io.swagger.annotations.ApiImplicitParams; | import io.swagger.annotations.ApiImplicitParams; | ||||
@@ -87,7 +88,7 @@ public class WxMsgValidationcodeController extends BaseController { | |||||
wxMsgValidationcode.setParentTenantId(parentTenantId); | wxMsgValidationcode.setParentTenantId(parentTenantId); | ||||
wxMsgValidationcode.setPhone(phone); | wxMsgValidationcode.setPhone(phone); | ||||
wxMsgValidationcode.setType(type); | wxMsgValidationcode.setType(type); | ||||
return wxMsgValidationcodeService.sendvalidationcode(wxMsgValidationcode); | |||||
return wxMsgValidationcodeService.sendvalidationcode(wxMsgValidationcode,EnumProject.PROJECT_2.getCode()); | |||||
} | } | ||||
@GetMapping("hasvalidationcode") | @GetMapping("hasvalidationcode") | ||||
@@ -10,8 +10,10 @@ import com.iformall.controller.base.BaseController; | |||||
import com.iformall.domain.dto.sm.SaveServiceInfoDTO; | import com.iformall.domain.dto.sm.SaveServiceInfoDTO; | ||||
import com.iformall.domain.dto.sm.UpdateServiceInfoDTO; | import com.iformall.domain.dto.sm.UpdateServiceInfoDTO; | ||||
import com.iformall.domain.dto.sm.UpdateServiceInfoStatusDTO; | import com.iformall.domain.dto.sm.UpdateServiceInfoStatusDTO; | ||||
import com.iformall.domain.po.MallUserInfo; | |||||
import com.iformall.domain.po.sm.ServiceInfo; | import com.iformall.domain.po.sm.ServiceInfo; | ||||
import com.iformall.exception.BizException; | import com.iformall.exception.BizException; | ||||
import com.iformall.service.MallUserInfoService; | |||||
import com.iformall.service.sm.ServiceInfoService; | import com.iformall.service.sm.ServiceInfoService; | ||||
import io.swagger.annotations.Api; | import io.swagger.annotations.Api; | ||||
import io.swagger.annotations.ApiOperation; | import io.swagger.annotations.ApiOperation; | ||||
@@ -27,6 +29,9 @@ public class ServiceInfoController extends BaseController { | |||||
@Autowired | @Autowired | ||||
private ServiceInfoService serviceInfoService; | private ServiceInfoService serviceInfoService; | ||||
@Autowired | |||||
private MallUserInfoService mallUserInfoService; | |||||
@ApiVersion(group = SwaggerConstant.V_1_0_0) | @ApiVersion(group = SwaggerConstant.V_1_0_0) | ||||
@ApiOperation("分页查询合作商") | @ApiOperation("分页查询合作商") | ||||
@@ -52,6 +57,14 @@ public class ServiceInfoController extends BaseController { | |||||
serviceInfoService.saveServiceInfo(dto); | serviceInfoService.saveServiceInfo(dto); | ||||
return R.ok(); | return R.ok(); | ||||
} | } | ||||
@ApiVersion(group = SwaggerConstant.V_1_0_0) | |||||
@ApiOperation("新增登录账号") | |||||
@PostMapping("/saveMallUserInfo") | |||||
public R<Void> saveMallUserInfo(@RequestBody MallUserInfo dto) { | |||||
mallUserInfoService.saveOrUpdate(dto); | |||||
return R.ok(); | |||||
} | |||||
@ApiVersion(group = SwaggerConstant.V_1_0_0) | @ApiVersion(group = SwaggerConstant.V_1_0_0) | ||||
@ApiOperation("修改合作商") | @ApiOperation("修改合作商") | ||||
@@ -8,6 +8,7 @@ import com.iformall.common.Result; | |||||
import com.iformall.common.ResultData; | import com.iformall.common.ResultData; | ||||
import com.iformall.constant.SwaggerConstant; | import com.iformall.constant.SwaggerConstant; | ||||
import com.iformall.controller.base.BaseController; | import com.iformall.controller.base.BaseController; | ||||
import com.iformall.controller.sys.mallUserInfo.MallUserInfoBaseController; | |||||
import com.iformall.domain.po.*; | import com.iformall.domain.po.*; | ||||
import com.iformall.domain.po.base.TenantEntity; | import com.iformall.domain.po.base.TenantEntity; | ||||
import com.iformall.domain.vo.MallUserInfoVo; | import com.iformall.domain.vo.MallUserInfoVo; | ||||
@@ -54,7 +55,7 @@ import java.util.Map; | |||||
@RestController | @RestController | ||||
@Api(description = "登录相关接口") | @Api(description = "登录相关接口") | ||||
public class HomeController extends BaseController { | |||||
public class HomeController extends MallUserInfoBaseController { | |||||
private final Logger logger = LoggerFactory.getLogger(this.getClass()); | private final Logger logger = LoggerFactory.getLogger(this.getClass()); | ||||
@Value("${version}") | @Value("${version}") | ||||
@@ -63,16 +64,6 @@ public class HomeController extends BaseController { | |||||
@Autowired | @Autowired | ||||
private Producer producer; | private Producer producer; | ||||
@Autowired | |||||
private MallUserInfoService mallUserInfoService; | |||||
@Autowired | |||||
private WxMsgValidationcodeService wxMsgValidationcodeService; | |||||
@Autowired | |||||
private MallUserActionService mallUserActionService; | |||||
@Autowired | @Autowired | ||||
@Qualifier("objectCommonRedisTemplate") | @Qualifier("objectCommonRedisTemplate") | ||||
RedisTemplate<String, Object> redisTemplate; | RedisTemplate<String, Object> redisTemplate; | ||||
@@ -90,9 +81,9 @@ public class HomeController extends BaseController { | |||||
//生成图片验证码 | //生成图片验证码 | ||||
BufferedImage image = producer.createImage(text); | BufferedImage image = producer.createImage(text); | ||||
//保存到shiro session | //保存到shiro session | ||||
// ShiroUtils.setSessionAttribute(Constants.KAPTCHA_SESSION_KEY, text); | |||||
String key = Constant.captchaPrev + ":" + getIpAddr(); | |||||
RedisCacheUtils.cache(redisTemplate, key, text, 60); | |||||
ShiroUtils.setSessionAttribute(Constants.KAPTCHA_SESSION_KEY, text); | |||||
// String key = Constant.captchaPrev + ":" + getIpAddr(); | |||||
// RedisCacheUtils.cache(redisTemplate, key, text, 60); | |||||
logger.info("验证码接口-生成的验证码:{}", text); | logger.info("验证码接口-生成的验证码:{}", text); | ||||
ServletOutputStream out = response.getOutputStream(); | ServletOutputStream out = response.getOutputStream(); | ||||
@@ -101,181 +92,24 @@ public class HomeController extends BaseController { | |||||
} | } | ||||
@ApiVersion(group = SwaggerConstant.V_1_0_0) | @ApiVersion(group = SwaggerConstant.V_1_0_0) | ||||
@ApiOperation("登录") | |||||
@ApiOperation("慧影登录") | |||||
@PostMapping("/doLogin") | @PostMapping("/doLogin") | ||||
public ResultData login(@RequestBody MallUserInfo user, HttpServletResponse response) { | public ResultData login(@RequestBody MallUserInfo user, HttpServletResponse response) { | ||||
String ipaddress = getIpAddr(); | |||||
logger.debug("[" + ipaddress + "] HomeController::doLogin"); | |||||
// try { | |||||
// String kaptcha = ShiroUtils.getKaptcha(Constants.KAPTCHA_SESSION_KEY); | |||||
// logger.info("登录接口-验证码:{}", user.getCaptcha()); | |||||
// logger.info("登录接口-生成的验证码:{}", kaptcha); | |||||
// if(!user.getCaptcha().equalsIgnoreCase(kaptcha)){ | |||||
// return new ResultData(ErrorCode.KAPCHA_NOT_EQUAL); | |||||
// } | |||||
// } catch (MallinkException e) { | |||||
// logger.error("验证码" + e.getMessage()); | |||||
// return new ResultData(ErrorCode.KAPCHA_NOT_VALID.getCode(), e.getMessage()); | |||||
// } | |||||
String key = Constant.captchaPrev + ":" + getIpAddr(); | |||||
String code = RedisCacheUtils.getCacheString(redisTemplate, key); | |||||
if (StringUtils.isBlank(code)) { | |||||
return new ResultData(ErrorCode.SYS_PARAMETER_ERROR.getCode(), "验证码已过期"); | |||||
} | |||||
if (!code.equals(user.getCaptcha())) { | |||||
return new ResultData(ErrorCode.SYS_PARAMETER_ERROR.getCode(), "验证码不正确"); | |||||
} | |||||
if (StringUtils.isBlank(user.getUsername()) || StringUtils.isBlank(user.getPassword())) { | |||||
return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL); | |||||
} | |||||
// check user | |||||
MallUserInfo userCheck = mallUserInfoService.getByUsername(user.getUsername()); | |||||
if(userCheck == null) { | |||||
logger.error(ErrorCode.USER_IS_EMPTY.getMessage()); | |||||
return new ResultData(ErrorCode.USER_IS_EMPTY); | |||||
} | |||||
if(userCheck.getStatus().equals(EnumMallUserStatus.NOT_VALID.getCode())) { | |||||
logger.error(ErrorCode.USER_IS_LOCKED.getMessage()); | |||||
return new ResultData(ErrorCode.USER_IS_LOCKED); | |||||
} | |||||
boolean isLogin = false; | |||||
try { | |||||
Subject subject = SecurityUtils.getSubject(); | |||||
UsernamePasswordToken token = new UsernamePasswordToken(user.getUsername(), user.getPassword()); | |||||
subject.login(token); | |||||
isLogin = true; | |||||
logger.info("ADMIN USER:"+user.getUsername() + ", password:" + user.getPassword()); | |||||
} catch (UnknownAccountException e) { | |||||
logger.error(e.getMessage()); | |||||
return new ResultData(ErrorCode.USER_IS_EMPTY); | |||||
} catch (DisabledAccountException e) { | |||||
logger.error(e.getMessage()); | |||||
return new ResultData(ErrorCode.USER_IS_LOCKED); | |||||
} catch (Exception e) { | |||||
logger.error(e.getMessage()); | |||||
return new ResultData(ErrorCode.USER_PASSWD_ERR); | |||||
} | |||||
if(isLogin) { | |||||
MallUserInfo info = (MallUserInfo) SecurityUtils.getSubject().getSession().getAttribute(UserSession.userInfo); | |||||
info.protectInfos(); | |||||
mallUserActionService.saveActionInfo(info, EnumMallUserAction.CONTROLLER.getCode(), ipaddress, info.getId(), "用户登录"); | |||||
try { | |||||
String cookieName = URLEncoder.encode(info.getUsername(), "utf-8"); | |||||
Cookie unameCookie = new Cookie("uname", cookieName); | |||||
unameCookie.setPath("/"); | |||||
unameCookie.setMaxAge(3600); | |||||
response.addCookie(unameCookie); | |||||
return new ResultData(); | |||||
} catch (Exception e) { | |||||
logger.error(e.getMessage()); | |||||
return new ResultData(Result.ERROR, e.getMessage()); | |||||
} | |||||
} | |||||
return new ResultData(Result.ERROR,"登陆失败"); | |||||
return doLogin(user, response, EnumProject.PROJECT_2); | |||||
} | } | ||||
@ApiOperation("发送手机验证码") | |||||
@ApiOperation("慧影发送手机验证码") | |||||
@GetMapping("sendLoginPhoneCode") | @GetMapping("sendLoginPhoneCode") | ||||
@ApiImplicitParams({ | @ApiImplicitParams({ | ||||
@ApiImplicitParam(name = "phone", value = "手机号", dataType = "String", paramType = "query", required = true)}) | @ApiImplicitParam(name = "phone", value = "手机号", dataType = "String", paramType = "query", required = true)}) | ||||
public ResultData sendLoginPhoneCode(String phone) { | public ResultData sendLoginPhoneCode(String phone) { | ||||
logger.debug("[" + getIpAddr() + "] HomeController::sendlogincode"); | |||||
// 1. 检查手机号是否在用户列表里, 是否只有一个 | |||||
// 2. 发送手机验证码, 直接发 | |||||
List<MallUserInfoVo> users = mallUserInfoService.getUserByPhone(phone); | |||||
if(users.size() <= 0) { | |||||
logger.error(ErrorCode.USER_IS_EMPTY.getMessage()); | |||||
return new ResultData(ErrorCode.USER_IS_EMPTY); | |||||
} | |||||
if(users.size() > 1) { | |||||
logger.error(ErrorCode.USER_IS_MULTI.getMessage()); | |||||
return new ResultData(ErrorCode.USER_IS_MULTI); | |||||
} | |||||
MallUserInfoVo user = users.get(0); | |||||
if (user==null) { | |||||
logger.error("用户不存在, userName: " + user.getUsername()); | |||||
return new ResultData(ErrorCode.USER_IS_EMPTY); | |||||
} | |||||
if(user.getStatus() == EnumMallUserStatus.NOT_VALID.getCode()){ | |||||
logger.error("用户已停用, userName: " + user.getUsername()); | |||||
return new ResultData(ErrorCode.USER_IS_LOCKED); | |||||
} | |||||
WxMsgValidationcode wxMsgValidationcode = new WxMsgValidationcode(); | |||||
wxMsgValidationcode.setPhone(phone); | |||||
wxMsgValidationcode.updateTenantInfo(user); | |||||
wxMsgValidationcode.setType(EnumMsgModel.VALIDATION_CODE.getCode()); | |||||
return wxMsgValidationcodeService.sendvalidationcode(wxMsgValidationcode); | |||||
return doSendLoginPhoneCode(phone, EnumProject.PROJECT_2); | |||||
} | } | ||||
@ApiOperation(value = "手机验证码登录", notes = "{\"phone\",\"string\",\"code\",\"string\"}") | |||||
@ApiOperation(value = "慧影手机验证码登录", notes = "{\"phone\",\"string\",\"code\",\"string\"}") | |||||
@PostMapping("/doLoginByPhone") | @PostMapping("/doLoginByPhone") | ||||
public ResultData doLoginByPhone(@RequestBody Map<String, String> params, HttpServletResponse response) { | public ResultData doLoginByPhone(@RequestBody Map<String, String> params, HttpServletResponse response) { | ||||
String ipaddress = getIpAddr(); | |||||
logger.debug("[" + ipaddress + "] HomeController::doLoginByPhone"); | |||||
// String phone,String code,String pwd | |||||
String phone = params.get("phone"); | |||||
String code = params.get("code"); | |||||
if (StringUtils.isBlank(phone)) { | |||||
return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), "userName不能为空"); | |||||
} | |||||
if (StringUtils.isBlank(code)) { | |||||
return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), "验证码不能为空"); | |||||
} | |||||
// 获取用户信息列表 | |||||
List<MallUserInfoVo> userList = mallUserInfoService.getUserByPhone(phone); | |||||
if(userList.size() == 1) { | |||||
MallUserInfoVo user = userList.get(0); | |||||
if (user == null) { | |||||
logger.error(ErrorCode.USER_IS_EMPTY.getMessage()); | |||||
return new ResultData(ErrorCode.USER_IS_EMPTY); | |||||
} | |||||
if (user.getStatus()==null ||!EnumMallUserStatus.VALID.getCode().equals(user.getStatus())) { | |||||
logger.error(ErrorCode.USER_IS_LOCKED.getMessage()); | |||||
return new ResultData(ErrorCode.USER_IS_LOCKED); | |||||
} | |||||
// check 验证码正确 | |||||
boolean isValidCode = false; | |||||
try { | |||||
isValidCode = wxMsgValidationcodeService.checkCodeValid(user.getPhone(),code); | |||||
} catch (Exception e) { | |||||
return new ResultData(Result.ERROR, e.getMessage()); | |||||
} | |||||
if(isValidCode) { | |||||
// 验证码正确,直接登录 | |||||
try { | |||||
Subject subject = SecurityUtils.getSubject(); | |||||
UseriFormallToken token = new UseriFormallToken(user.getUsername()); | |||||
subject.login(token); | |||||
MallUserInfo info = (MallUserInfo) SecurityUtils.getSubject().getSession().getAttribute(UserSession.userInfo); | |||||
info.protectInfos(); | |||||
mallUserActionService.saveActionInfo(info, EnumMallUserAction.CONTROLLER.getCode(), ipaddress, info.getId(), "用户手机号登录"); | |||||
String cookieName = URLEncoder.encode(info.getUsername(), "utf-8"); | |||||
Cookie unameCookie = new Cookie("uname", cookieName); | |||||
unameCookie.setPath("/"); | |||||
unameCookie.setMaxAge(3600); | |||||
response.addCookie(unameCookie); | |||||
return new ResultData(); | |||||
} catch (MallinkException e) { | |||||
return new ResultData(e.getErrorCode(), e.getMessage()); | |||||
} catch (Exception e) { | |||||
return new ResultData(ErrorCode.USER_PASSWD_ERR); | |||||
} | |||||
} else { | |||||
return new ResultData(ErrorCode.MSG_VERIFY_CODE_NOT_FOUND); | |||||
} | |||||
} else { | |||||
return new ResultData(ErrorCode.USER_IS_EMPTY); | |||||
} | |||||
return doLoginByPhone(params, response, EnumProject.PROJECT_2); | |||||
} | } | ||||
@ApiOperation("登出") | @ApiOperation("登出") | ||||
@@ -8,9 +8,11 @@ import com.iformall.common.Result; | |||||
import com.iformall.common.ResultData; | import com.iformall.common.ResultData; | ||||
import com.iformall.constant.SwaggerConstant; | import com.iformall.constant.SwaggerConstant; | ||||
import com.iformall.controller.base.BaseController; | import com.iformall.controller.base.BaseController; | ||||
import com.iformall.controller.sys.mallUserInfo.MallUserInfoBaseController; | |||||
import com.iformall.domain.po.*; | import com.iformall.domain.po.*; | ||||
import com.iformall.domain.po.base.BaseEntity; | import com.iformall.domain.po.base.BaseEntity; | ||||
import com.iformall.enums.EnumMallUserStatus; | import com.iformall.enums.EnumMallUserStatus; | ||||
import com.iformall.enums.EnumProject; | |||||
import com.iformall.enums.EnumUserAdmin; | import com.iformall.enums.EnumUserAdmin; | ||||
import com.iformall.service.*; | import com.iformall.service.*; | ||||
import com.iformall.shiro.PasswordHelper; | import com.iformall.shiro.PasswordHelper; | ||||
@@ -37,18 +39,10 @@ import java.util.Map; | |||||
@Api(value = "API - UserInfoController", description = "用户接口") | @Api(value = "API - UserInfoController", description = "用户接口") | ||||
@RestController | @RestController | ||||
@RequestMapping("user") | @RequestMapping("user") | ||||
public class MallUserInfoController extends BaseController { | |||||
public class MallUserInfoController extends MallUserInfoBaseController { | |||||
private final Logger logger = LoggerFactory.getLogger(this.getClass()); | private final Logger logger = LoggerFactory.getLogger(this.getClass()); | ||||
@Autowired | |||||
MallUserInfoService userInfoService; | |||||
@Autowired | |||||
MallUserRoleService userRoleService; | |||||
@Autowired | |||||
MallRoleService mallRoleService; | |||||
@Autowired | @Autowired | ||||
MallUserRoleService mallUserRoleService; | MallUserRoleService mallUserRoleService; | ||||
@@ -63,7 +57,7 @@ public class MallUserInfoController extends BaseController { | |||||
WxMsgValidationcodeService wxMsgValidationcodeService; | WxMsgValidationcodeService wxMsgValidationcodeService; | ||||
@ApiVersion(group = SwaggerConstant.V_1_0_0) | @ApiVersion(group = SwaggerConstant.V_1_0_0) | ||||
@ApiOperation(value = "用户分页接口", response = String.class) | |||||
@ApiOperation(value = "慧影-用户分页接口", response = String.class) | |||||
@GetMapping("lists") | @GetMapping("lists") | ||||
//@RequiresPermissions("sys:user:list") | //@RequiresPermissions("sys:user:list") | ||||
@ApiImplicitParams({ | @ApiImplicitParams({ | ||||
@@ -71,30 +65,7 @@ public class MallUserInfoController extends BaseController { | |||||
@ApiImplicitParam(name = "pageSize", value = "每页条数", dataType = "int", paramType = "query", required = true)}) | @ApiImplicitParam(name = "pageSize", value = "每页条数", dataType = "int", paramType = "query", required = true)}) | ||||
@SystemControllerLog(description = "用户管理-列表") | @SystemControllerLog(description = "用户管理-列表") | ||||
public ResultData listAsPage(MallUserInfo userInfo, Integer pageNum, Integer pageSize) { | public ResultData listAsPage(MallUserInfo userInfo, Integer pageNum, Integer pageSize) { | ||||
logger.debug("[" + getIpAddr() + "] MallUserInfoController::listAsPage"); | |||||
userInfo.updateTenantInfo(getTenantInfo()); | |||||
userInfo.setSortColumns(BaseEntity.SortField.CreateTime_DESC,BaseEntity.SortField.Id_DESC); | |||||
final PageInfo<MallUserInfo> page = userInfoService.listAsPage(userInfo, pageNum, pageSize); | |||||
for (MallUserInfo u : page.getList()) { | |||||
MallUserRole r = new MallUserRole(); | |||||
r.setUid(u.getId()); | |||||
PageInfo<MallUserRole> ur = userRoleService.listAsPage(r, 1, 1); | |||||
if (ur.getSize() > 0) { | |||||
MallRole role = mallRoleService.getById(ur.getList().get(0).getRoleId()); | |||||
if (role != null) { | |||||
u.setRoleName(role.getName()); | |||||
u.setRoleId(role.getId()); | |||||
} | |||||
} | |||||
// 保密 | |||||
u.setPassword(null); | |||||
u.setBopenId(null); | |||||
if(StringUtils.isNotBlank(u.getWebOpenId())) { | |||||
u.setWebOpenId("保密"); | |||||
} | |||||
} | |||||
return new ResultData(page); | |||||
return listAsPage(userInfo, pageNum, pageSize, EnumProject.PROJECT_2); | |||||
} | } | ||||
@ApiOperation(value = "用户详情接口", response = String.class) | @ApiOperation(value = "用户详情接口", response = String.class) | ||||
@@ -109,125 +80,25 @@ public class MallUserInfoController extends BaseController { | |||||
if(StringUtils.isNotBlank(user.getWebOpenId())) { | if(StringUtils.isNotBlank(user.getWebOpenId())) { | ||||
user.setWebOpenId("保密"); | user.setWebOpenId("保密"); | ||||
} | } | ||||
return new ResultData(user); | return new ResultData(user); | ||||
} | } | ||||
@ApiVersion(group = SwaggerConstant.V_1_0_0) | @ApiVersion(group = SwaggerConstant.V_1_0_0) | ||||
@ApiOperation(value = "创建用户接口", response = String.class) | |||||
@ApiOperation(value = "慧影-创建用户接口", response = String.class) | |||||
@PostMapping("add") | @PostMapping("add") | ||||
//@RequiresPermissions("sys:user:add") | //@RequiresPermissions("sys:user:add") | ||||
@SystemControllerLog(description = "用户管理-创建用户") | @SystemControllerLog(description = "用户管理-创建用户") | ||||
public ResultData createUser(@RequestBody MallUserInfo userInfo) { | public ResultData createUser(@RequestBody MallUserInfo userInfo) { | ||||
logger.debug("[" + getIpAddr() + "] MallUserInfoController::createUser"); | |||||
MallUserInfo currentUser = getUser(); | |||||
if(currentUser.getIsAdmin().equals(EnumUserAdmin.Normal.getCode())) { | |||||
return new ResultData(ErrorCode.USER_NOT_ADMIN.getCode(), "只有系统管理员才能添加用户"); | |||||
} | |||||
if(!getTenantInfo().getTenantId().equals(currentUser.getTenantId())){ | |||||
return new ResultData(ErrorCode.USER_NO_PERMISSION); | |||||
} | |||||
if(checkUniqueName(userInfo.getUsername()) > 0){ | |||||
return new ResultData(ErrorCode.USER_NAME_IS_FOUND.getCode(),"用户名已存在"); | |||||
} | |||||
if(checkUniquePhone(userInfo.getPhone()) > 0){ | |||||
return new ResultData(ErrorCode.USER_PHONE_IS_FOUND.getCode(),"手机号已存在"); | |||||
} | |||||
Assert.notNull(userInfo.getPassword(), "密码不能为空"); | |||||
PasswordHelper passwordHelper = new PasswordHelper(); | |||||
passwordHelper.encryptPassword(userInfo); | |||||
userInfo.updateTenantInfo(currentUser); | |||||
// 无法创建超管 | |||||
userInfo.setIsAdmin(EnumUserAdmin.Normal.getCode()); | |||||
userInfoService.saveOrUpdate(userInfo); | |||||
if (userInfo.getRoleId() != null) { | |||||
MallUserRole r = new MallUserRole(); | |||||
r.setRoleId(userInfo.getRoleId()); | |||||
r.setUid(userInfo.getId()); | |||||
userRoleService.saveOrUpdate(r); | |||||
} | |||||
return new ResultData(userInfo); | |||||
return doCreateUser(userInfo, EnumProject.PROJECT_2); | |||||
} | } | ||||
@ApiVersion(group = SwaggerConstant.V_1_0_0) | @ApiVersion(group = SwaggerConstant.V_1_0_0) | ||||
@ApiOperation(value = "修改用户接口", response = String.class) | |||||
@ApiOperation(value = "慧影-修改用户接口", response = String.class) | |||||
@PostMapping("update") | @PostMapping("update") | ||||
//@RequiresPermissions("sys:user:update") | //@RequiresPermissions("sys:user:update") | ||||
@SystemControllerLog(description = "用户管理-修改用户") | @SystemControllerLog(description = "用户管理-修改用户") | ||||
public ResultData updateUser(@RequestBody MallUserInfo userInfo) { | public ResultData updateUser(@RequestBody MallUserInfo userInfo) { | ||||
logger.debug("[" + getIpAddr() + "] MallUserInfoController::updateUser"); | |||||
boolean bChangedPhone = false; | |||||
MallUserInfo currentUser = getUser(); | |||||
// 只有超管和自己能更新信息 | |||||
if (!(currentUser.getId().equals(userInfo.getId()) || | |||||
currentUser.getIsAdmin().equals(EnumUserAdmin.ADMIN.getCode()))) { | |||||
return new ResultData(ErrorCode.USER_NO_PERMISSION.getCode(), "系统管理员和自己才能修改信息"); | |||||
} | |||||
if(!getTenantInfo().getTenantId().equals(currentUser.getTenantId())){ | |||||
return new ResultData(ErrorCode.USER_NO_PERMISSION); | |||||
} | |||||
MallUserInfo oldUser = userInfoService.getById(userInfo.getId()); | |||||
if (!oldUser.getUsername().equals(userInfo.getUsername())) { | |||||
if(checkUniqueName(userInfo.getUsername()) > 0){ | |||||
return new ResultData(ErrorCode.USER_NAME_IS_FOUND.getCode(),"用户名已存在"); | |||||
} | |||||
} | |||||
if (!oldUser.getPhone().equals(userInfo.getPhone())) { | |||||
if(checkUniquePhone(userInfo.getPhone()) > 0){ | |||||
return new ResultData(ErrorCode.USER_PHONE_IS_FOUND.getCode(),"手机号已存在"); | |||||
} | |||||
bChangedPhone = true; | |||||
} | |||||
userInfo.updateTenantInfo(currentUser); | |||||
if (StringUtils.isNotBlank(userInfo.getPassword()) && userInfo.getPassword().length() > 0) { | |||||
PasswordHelper passwordHelper = new PasswordHelper(); | |||||
passwordHelper.encryptPassword(userInfo); | |||||
} | |||||
// 系统内人员不能设置系统管理员 | |||||
userInfo.setIsAdmin(null); | |||||
/* | |||||
if (!currentUser.getIsAdmin().equals(EnumUserAdmin.ADMIN.getCode())) { | |||||
// 只有系统管理员才能设置系统管理员 | |||||
userInfo.setIsAdmin(null); | |||||
} | |||||
*/ | |||||
if (currentUser.getIsAdmin().equals(EnumUserAdmin.ADMIN.getCode()) && | |||||
currentUser.getId().equals(userInfo.getId())) { | |||||
// 超管 | |||||
MallUserInfo adminUser = new MallUserInfo(); | |||||
adminUser.setEmail(userInfo.getEmail()); | |||||
adminUser.setId(userInfo.getId()); | |||||
if (StringUtils.isNotBlank(userInfo.getPassword()) && userInfo.getPassword().length() > 0) { | |||||
adminUser.setPassword(userInfo.getPassword()); | |||||
} | |||||
if (StringUtils.isNotBlank(userInfo.getNickName())) { | |||||
adminUser.setNickName(userInfo.getNickName()); | |||||
} | |||||
if (StringUtils.isNotBlank(userInfo.getPhone())) { | |||||
adminUser.setPhone(userInfo.getPhone()); | |||||
} | |||||
adminUser.setInvestRule(userInfo.getInvestRule()); | |||||
userInfoService.saveOrUpdate(adminUser); | |||||
} else { | |||||
userInfoService.saveOrUpdate(userInfo); | |||||
if (userInfo.getRoleId() != null) { | |||||
userRoleService.deleteByUserId(userInfo.getId()); | |||||
MallUserRole r = new MallUserRole(); | |||||
r.setRoleId(userInfo.getRoleId()); | |||||
r.setUid(userInfo.getId()); | |||||
userRoleService.saveOrUpdate(r); | |||||
} | |||||
} | |||||
if(bChangedPhone) { | |||||
// 手机号修改,清除bopen_id, 清除web_open_id | |||||
userInfoService.cleanAllOpenId(userInfo); | |||||
} | |||||
return new ResultData(); | |||||
return doUpdateUser(userInfo,EnumProject.PROJECT_2); | |||||
} | } | ||||
@ApiVersion(group = SwaggerConstant.V_1_0_0) | @ApiVersion(group = SwaggerConstant.V_1_0_0) | ||||
@@ -241,9 +112,9 @@ public class MallUserInfoController extends BaseController { | |||||
if (currentUser.getIsAdmin().equals(EnumUserAdmin.Normal.getCode())) { | if (currentUser.getIsAdmin().equals(EnumUserAdmin.Normal.getCode())) { | ||||
return new ResultData(ErrorCode.USER_NOT_ADMIN.getCode(), "只有系统管理员才能删除用户"); | return new ResultData(ErrorCode.USER_NOT_ADMIN.getCode(), "只有系统管理员才能删除用户"); | ||||
} | } | ||||
if(!getTenantInfo().getTenantId().equals(currentUser.getTenantId())){ | |||||
return new ResultData(ErrorCode.USER_NO_PERMISSION); | |||||
} | |||||
// if(!getTenantInfo().getTenantId().equals(currentUser.getTenantId())){ | |||||
// return new ResultData(ErrorCode.USER_NO_PERMISSION); | |||||
// } | |||||
if (currentUser.getId().equals(userInfo.getId())) { | if (currentUser.getId().equals(userInfo.getId())) { | ||||
return new ResultData(ErrorCode.USER_NO_PERMISSION.getCode(), "用户不能删除自己"); | return new ResultData(ErrorCode.USER_NO_PERMISSION.getCode(), "用户不能删除自己"); | ||||
} | } | ||||
@@ -261,9 +132,9 @@ public class MallUserInfoController extends BaseController { | |||||
MallUserInfo currentUser = getUser(); | MallUserInfo currentUser = getUser(); | ||||
if (currentUser.getIsAdmin().equals(EnumUserAdmin.ADMIN.getCode())) { | if (currentUser.getIsAdmin().equals(EnumUserAdmin.ADMIN.getCode())) { | ||||
if(!getTenantInfo().getTenantId().equals(currentUser.getTenantId())){ | |||||
return new ResultData(ErrorCode.USER_NO_PERMISSION); | |||||
} | |||||
// if(!getTenantInfo().getTenantId().equals(currentUser.getTenantId())){ | |||||
// return new ResultData(ErrorCode.USER_NO_PERMISSION); | |||||
// } | |||||
MallUserInfo userInfo1 = userInfoService.getById(userInfo.getId()); | MallUserInfo userInfo1 = userInfoService.getById(userInfo.getId()); | ||||
if(userInfo1 == null) { | if(userInfo1 == null) { | ||||
@@ -281,14 +152,6 @@ public class MallUserInfoController extends BaseController { | |||||
} | } | ||||
} | } | ||||
private int checkUniqueName(String userName) { | |||||
return userInfoService.cntByUserName(userName); | |||||
} | |||||
private int checkUniquePhone(String phone) { | |||||
return userInfoService.cntByUserPhone(phone); | |||||
} | |||||
@ApiOperation(value = "用户权限检查") | @ApiOperation(value = "用户权限检查") | ||||
@GetMapping("hasButtonPermission") | @GetMapping("hasButtonPermission") | ||||
@@ -327,79 +190,21 @@ public class MallUserInfoController extends BaseController { | |||||
} | } | ||||
@ApiVersion(group = SwaggerConstant.V_1_0_0) | @ApiVersion(group = SwaggerConstant.V_1_0_0) | ||||
@ApiOperation(value = "用户密码发送验证码") | |||||
@ApiOperation(value = "慧影-用户密码发送验证码") | |||||
@GetMapping("sendvalidationcode") | @GetMapping("sendvalidationcode") | ||||
@ApiImplicitParams({ | @ApiImplicitParams({ | ||||
@ApiImplicitParam(name = "userName", value = "手机号", dataType = "String", paramType = "query", required = true), | @ApiImplicitParam(name = "userName", value = "手机号", dataType = "String", paramType = "query", required = true), | ||||
@ApiImplicitParam(name = "type", value = "场景(1:登录)", dataType = "Integer", paramType = "query", required = true)}) | @ApiImplicitParam(name = "type", value = "场景(1:登录)", dataType = "Integer", paramType = "query", required = true)}) | ||||
public ResultData sendvalidationcode(String userName, Integer type) { | public ResultData sendvalidationcode(String userName, Integer type) { | ||||
logger.debug("[" + getIpAddr() + "] MallUserInfoController::sendvalidationcode"); | |||||
MallUserInfo userQ = new MallUserInfo(); | |||||
userQ.setUsername(userName); | |||||
MallUserInfo user = userInfoService.getByUsername(userName); | |||||
if (user==null) { | |||||
logger.error("用户不存在, userName: " + userName); | |||||
return new ResultData(ErrorCode.USER_IS_EMPTY); | |||||
} | |||||
if(user.getStatus() == EnumMallUserStatus.NOT_VALID.getCode()){ | |||||
logger.error("用户已停用, userName: " + userName); | |||||
return new ResultData(ErrorCode.USER_IS_LOCKED); | |||||
} | |||||
if (StringUtils.isBlank(user.getPhone())) { | |||||
logger.error("用户手机号为空, userName: " + userName); | |||||
return new ResultData(ErrorCode.USER_PHONE_IS_NOT_FOUND); | |||||
} | |||||
WxMsgValidationcode wxMsgValidationcode = new WxMsgValidationcode(); | |||||
wxMsgValidationcode.updateTenantInfo(user); | |||||
wxMsgValidationcode.setPhone(user.getPhone()); | |||||
wxMsgValidationcode.setType(type); | |||||
return wxMsgValidationcodeService.sendvalidationcode(wxMsgValidationcode); | |||||
return doSendvalidationcode(userName,type,EnumProject.PROJECT_2); | |||||
} | } | ||||
@ApiVersion(group = SwaggerConstant.V_1_0_0) | @ApiVersion(group = SwaggerConstant.V_1_0_0) | ||||
@ApiOperation(value = "修改密码", notes = "{\"userName\",\"string\",\"code\",\"string\",\"pwd\",\"string\"}") | |||||
@ApiOperation(value = "慧影-修改密码", notes = "{\"userName\",\"string\",\"code\",\"string\",\"pwd\",\"string\"}") | |||||
@PostMapping("/updatepwd") | @PostMapping("/updatepwd") | ||||
@SystemControllerLog(description = "用户管理-修改密码") | @SystemControllerLog(description = "用户管理-修改密码") | ||||
public ResultData updatepwd(@RequestBody Map<String, String> params) { | public ResultData updatepwd(@RequestBody Map<String, String> params) { | ||||
logger.debug("[" + getIpAddr() + "] MallUserInfoController::updatepwd"); | |||||
// String phone,String code,String pwd | |||||
String userName = params.get("userName"); | |||||
String code = params.get("code"); | |||||
String pwd = params.get("pwd"); | |||||
if (StringUtils.isBlank(userName)) { | |||||
return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), "userName不能为空"); | |||||
} | |||||
if (StringUtils.isBlank(code)) { | |||||
return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), "验证码不能为空"); | |||||
} | |||||
if (StringUtils.isBlank(pwd)) { | |||||
return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), "密码不能为空"); | |||||
} | |||||
MallUserInfo userQ = new MallUserInfo(); | |||||
userQ.setUsername(userName); | |||||
MallUserInfo user = userInfoService.getByUsername(userName); | |||||
if (user==null) { | |||||
logger.error("用户不存在, userName: " + userName); | |||||
return new ResultData(ErrorCode.USER_IS_EMPTY); | |||||
} | |||||
user.setPassword(pwd); | |||||
PasswordHelper passwordHelper = new PasswordHelper(); | |||||
passwordHelper.encryptPassword(user); | |||||
try { | |||||
return userInfoService.updatepwd(user, code); | |||||
} catch (Exception e) { | |||||
return new ResultData(Result.ERROR, e.getMessage()); | |||||
} | |||||
return doUpdatepwd(params, EnumProject.PROJECT_2); | |||||
} | } | ||||
@@ -287,155 +287,155 @@ public class WechatLoginController extends BaseController { | |||||
} | } | ||||
} | } | ||||
@ApiOperation(value = "微信用户登录") | |||||
@GetMapping("weChatUserLogin") | |||||
@ApiImplicitParams({ | |||||
@ApiImplicitParam(name = "key", value = "key", dataType = "String", paramType = "query", required = true), | |||||
@ApiImplicitParam(name = "userName", value = "userName", dataType = "String", paramType = "query", required = true)}) | |||||
public ResultData weChatUserLogin(String key, String userName, HttpServletRequest request, HttpServletResponse response) { | |||||
String ipaddress = getIpAddr(); | |||||
log.debug("[" + ipaddress + "] MallUserInfoController::weChatUserLogin"); | |||||
String host = request.getHeader("host"); | |||||
log.debug("Host: " + host); | |||||
if(StringUtils.isBlank(userName)) { | |||||
log.error("请选择要登录的用户"); | |||||
return new ResultData(ErrorCode.WECHAT_LOGIN_USER_SELECT); | |||||
} | |||||
String openKey = WECHAT_PREV + key; | |||||
// 限时时间内查找到此用户openId | |||||
if (openRedisTemplate.hasKey(openKey)){ | |||||
log.info(openKey + " - 找不到"); | |||||
String openId = openRedisTemplate.opsForValue().get(openKey); | |||||
openRedisTemplate.delete(openKey); | |||||
log.info("KEY: " + openKey + " deleted"); | |||||
MallUserInfo userInfo = mallUserInfoService.getByUsername(userName); | |||||
if (userInfo == null) { | |||||
return new ResultData(ErrorCode.USER_IS_EMPTY); | |||||
} | |||||
if (userInfo.getStatus()==null ||!EnumMallUserStatus.VALID.getCode().equals(userInfo.getStatus())) { | |||||
return new ResultData(ErrorCode.USER_IS_LOCKED); | |||||
} | |||||
if(userInfo.getWebOpenId().equals(openId)) { | |||||
boolean isLogin = false; | |||||
try { | |||||
Subject subject = SecurityUtils.getSubject(); | |||||
UseriFormallToken token = new UseriFormallToken(userInfo.getUsername()); | |||||
subject.login(token); | |||||
MallUserInfo info = (MallUserInfo) SecurityUtils.getSubject().getSession().getAttribute(UserSession.userInfo); | |||||
info.protectInfos(); | |||||
String menus = mallUserRoleService.getPermissionsByUser(info); | |||||
if(StringUtils.isNotBlank(menus)) { | |||||
info.setMenus(menus); | |||||
} | |||||
Map<String, Object> ret = new HashMap<>(); | |||||
WxMall mall = mallService.getByTenantInfo(info); | |||||
if (mall == null) { | |||||
ret.put("code", Result.ERROR); | |||||
ret.put("message", "未配置相应的mall"); | |||||
log.info("用户登录失败-4,返回登录"); | |||||
try { | |||||
String errCode = URLEncoder.encode(JSON.toJSONString(ret), "utf-8"); | |||||
response.sendRedirect("https://" + host + "/#/login?errcode=" + errCode); | |||||
} catch (Exception e) { | |||||
log.error(e.getMessage()); | |||||
} | |||||
} | |||||
if (!mall.isValid()) { | |||||
ret.put("code", Result.ERROR); | |||||
ret.put("message", "mall已过期"); | |||||
log.info("用户登录失败-5,返回登录"); | |||||
try { | |||||
String errCode = URLEncoder.encode(JSON.toJSONString(ret), "utf-8"); | |||||
response.sendRedirect("https://" + host + "/#/login?errcode=" + errCode); | |||||
} catch (Exception e) { | |||||
log.error(e.getMessage()); | |||||
} | |||||
} | |||||
// 登录cookie | |||||
String cookieName = URLEncoder.encode(info.getUsername(), "utf-8"); | |||||
Cookie unameCookie = new Cookie("uname", cookieName); | |||||
unameCookie.setPath("/"); | |||||
unameCookie.setMaxAge(3600); | |||||
response.addCookie(unameCookie); | |||||
MallUserAction action = new MallUserAction(); | |||||
action.updateTenantInfo(info); | |||||
action.setType(EnumMallUserAction.CONTROLLER.getCode()); | |||||
action.setIp(ipaddress); | |||||
action.setUserId(info.getId()); | |||||
action.setActionDesc("用户微信登录"); | |||||
action.setActionTime(new Date()); | |||||
mallUserActionService.saveOrUpdate(action); | |||||
return new ResultData(); | |||||
} catch (UnknownAccountException e) { | |||||
log.error(e.getMessage()); | |||||
return new ResultData(ErrorCode.USER_IS_EMPTY.getCode(), e.getMessage()); | |||||
} catch (DisabledAccountException e) { | |||||
log.error(e.getMessage()); | |||||
return new ResultData(ErrorCode.USER_IS_LOCKED.getCode(), e.getMessage()); | |||||
} catch (Exception e) { | |||||
log.error(e.getMessage()); | |||||
return new ResultData(Result.ERROR, e.getMessage()); | |||||
} | |||||
} else { | |||||
// 登录失败 | |||||
log.error("微信登录失败,用户微信未绑定:" + openId); | |||||
return new ResultData(ErrorCode.WECHAT_LOGIN_NOT_BIND); | |||||
} | |||||
} | |||||
log.error("微信登录失败,KEY已过期: "+ key); | |||||
return new ResultData(ErrorCode.WECHAT_LOGIN_KEY_OVERTIME); | |||||
} | |||||
@ApiOperation(value = "微信第三方登录绑定", notes = "请配置此callback到网页redirect_uri") | |||||
@GetMapping("bindWebOpenId") | |||||
@SystemControllerLog(description = "微信第三方登录绑定") | |||||
public void userBindWebOpenId(String code, String state, HttpServletRequest request, HttpServletResponse response) { | |||||
log.debug("[" + getIpAddr() + "] WechatLoginController::bindWebOpenId"); | |||||
String host = request.getHeader("host"); | |||||
String errCode = null; | |||||
try { | |||||
WxMpOAuth2AccessToken accessToken = wxMpService.oauth2getAccessToken(code); | |||||
log.debug("accessToken: " + accessToken.getAccessToken() + ", openId: " + accessToken.getOpenId() + ", unionId: " + accessToken.getUnionId()); | |||||
// 获取 用户信息 | |||||
WxMpUser mpUser = wxMpService.oauth2getUserInfo(accessToken, null); | |||||
if(mpUser != null) { | |||||
log.debug(mpUser.toString()); | |||||
} | |||||
String uname = state; | |||||
MallUserInfo user = mallUserInfoService.getByUsername(uname); | |||||
if(user != null) { | |||||
user.setWebOpenId(accessToken.getOpenId()); | |||||
mallUserInfoService.updateWebOpenId(user); | |||||
log.debug("https://" + host + "/#/layout"); | |||||
response.sendRedirect("https://" + host + "/#/layout"); | |||||
} else { | |||||
log.debug("https://" + host + "/#/layout?errcode=绑定失败"); | |||||
errCode = URLEncoder.encode("绑定失败", "utf-8"); | |||||
response.sendRedirect("https://" + host + "/#/layout?errcode="+errCode); | |||||
} | |||||
} catch (WxErrorException e) { | |||||
log.error(e.getMessage()); | |||||
errCode = e.getMessage(); | |||||
} catch (IOException e) { | |||||
log.error(e.getMessage()); | |||||
errCode = e.getMessage(); | |||||
} | |||||
// @ApiOperation(value = "微信用户登录") | |||||
// @GetMapping("weChatUserLogin") | |||||
// @ApiImplicitParams({ | |||||
// @ApiImplicitParam(name = "key", value = "key", dataType = "String", paramType = "query", required = true), | |||||
// @ApiImplicitParam(name = "userName", value = "userName", dataType = "String", paramType = "query", required = true)}) | |||||
// public ResultData weChatUserLogin(String key, String userName, HttpServletRequest request, HttpServletResponse response) { | |||||
// String ipaddress = getIpAddr(); | |||||
// log.debug("[" + ipaddress + "] MallUserInfoController::weChatUserLogin"); | |||||
// String host = request.getHeader("host"); | |||||
// log.debug("Host: " + host); | |||||
// if(StringUtils.isBlank(userName)) { | |||||
// log.error("请选择要登录的用户"); | |||||
// return new ResultData(ErrorCode.WECHAT_LOGIN_USER_SELECT); | |||||
// } | |||||
// | |||||
// String openKey = WECHAT_PREV + key; | |||||
// // 限时时间内查找到此用户openId | |||||
// if (openRedisTemplate.hasKey(openKey)){ | |||||
// log.info(openKey + " - 找不到"); | |||||
// String openId = openRedisTemplate.opsForValue().get(openKey); | |||||
// openRedisTemplate.delete(openKey); | |||||
// log.info("KEY: " + openKey + " deleted"); | |||||
// | |||||
// MallUserInfo userInfo = mallUserInfoService.getByUsername(userName); | |||||
// if (userInfo == null) { | |||||
// return new ResultData(ErrorCode.USER_IS_EMPTY); | |||||
// } | |||||
// if (userInfo.getStatus()==null ||!EnumMallUserStatus.VALID.getCode().equals(userInfo.getStatus())) { | |||||
// return new ResultData(ErrorCode.USER_IS_LOCKED); | |||||
// } | |||||
// if(userInfo.getWebOpenId().equals(openId)) { | |||||
// boolean isLogin = false; | |||||
// try { | |||||
// Subject subject = SecurityUtils.getSubject(); | |||||
// UseriFormallToken token = new UseriFormallToken(userInfo.getUsername()); | |||||
// subject.login(token); | |||||
// MallUserInfo info = (MallUserInfo) SecurityUtils.getSubject().getSession().getAttribute(UserSession.userInfo); | |||||
// info.protectInfos(); | |||||
// String menus = mallUserRoleService.getPermissionsByUser(info); | |||||
// if(StringUtils.isNotBlank(menus)) { | |||||
// info.setMenus(menus); | |||||
// } | |||||
// Map<String, Object> ret = new HashMap<>(); | |||||
// WxMall mall = mallService.getByTenantInfo(info); | |||||
// if (mall == null) { | |||||
// ret.put("code", Result.ERROR); | |||||
// ret.put("message", "未配置相应的mall"); | |||||
// log.info("用户登录失败-4,返回登录"); | |||||
// try { | |||||
// String errCode = URLEncoder.encode(JSON.toJSONString(ret), "utf-8"); | |||||
// response.sendRedirect("https://" + host + "/#/login?errcode=" + errCode); | |||||
// } catch (Exception e) { | |||||
// log.error(e.getMessage()); | |||||
// } | |||||
// } | |||||
// if (!mall.isValid()) { | |||||
// ret.put("code", Result.ERROR); | |||||
// ret.put("message", "mall已过期"); | |||||
// log.info("用户登录失败-5,返回登录"); | |||||
// try { | |||||
// String errCode = URLEncoder.encode(JSON.toJSONString(ret), "utf-8"); | |||||
// response.sendRedirect("https://" + host + "/#/login?errcode=" + errCode); | |||||
// } catch (Exception e) { | |||||
// log.error(e.getMessage()); | |||||
// } | |||||
// } | |||||
// // 登录cookie | |||||
// String cookieName = URLEncoder.encode(info.getUsername(), "utf-8"); | |||||
// Cookie unameCookie = new Cookie("uname", cookieName); | |||||
// unameCookie.setPath("/"); | |||||
// unameCookie.setMaxAge(3600); | |||||
// response.addCookie(unameCookie); | |||||
// | |||||
// MallUserAction action = new MallUserAction(); | |||||
// action.updateTenantInfo(info); | |||||
// action.setType(EnumMallUserAction.CONTROLLER.getCode()); | |||||
// action.setIp(ipaddress); | |||||
// action.setUserId(info.getId()); | |||||
// action.setActionDesc("用户微信登录"); | |||||
// action.setActionTime(new Date()); | |||||
// mallUserActionService.saveOrUpdate(action); | |||||
// | |||||
// return new ResultData(); | |||||
// } catch (UnknownAccountException e) { | |||||
// log.error(e.getMessage()); | |||||
// return new ResultData(ErrorCode.USER_IS_EMPTY.getCode(), e.getMessage()); | |||||
// } catch (DisabledAccountException e) { | |||||
// log.error(e.getMessage()); | |||||
// return new ResultData(ErrorCode.USER_IS_LOCKED.getCode(), e.getMessage()); | |||||
// } catch (Exception e) { | |||||
// log.error(e.getMessage()); | |||||
// return new ResultData(Result.ERROR, e.getMessage()); | |||||
// } | |||||
// } else { | |||||
// // 登录失败 | |||||
// log.error("微信登录失败,用户微信未绑定:" + openId); | |||||
// return new ResultData(ErrorCode.WECHAT_LOGIN_NOT_BIND); | |||||
// } | |||||
// } | |||||
// log.error("微信登录失败,KEY已过期: "+ key); | |||||
// return new ResultData(ErrorCode.WECHAT_LOGIN_KEY_OVERTIME); | |||||
// } | |||||
if(StringUtils.isNotBlank(errCode)) { | |||||
try { | |||||
errCode = URLEncoder.encode(errCode, "utf-8"); | |||||
response.sendRedirect("https://" + host + "/#/layout?errcode="+errCode); | |||||
} catch (Exception e) { | |||||
log.error(e.getMessage()); | |||||
} | |||||
} | |||||
} | |||||
// @ApiOperation(value = "微信第三方登录绑定", notes = "请配置此callback到网页redirect_uri") | |||||
// @GetMapping("bindWebOpenId") | |||||
// @SystemControllerLog(description = "微信第三方登录绑定") | |||||
// public void userBindWebOpenId(String code, String state, HttpServletRequest request, HttpServletResponse response) { | |||||
// log.debug("[" + getIpAddr() + "] WechatLoginController::bindWebOpenId"); | |||||
// String host = request.getHeader("host"); | |||||
// String errCode = null; | |||||
// try { | |||||
// WxMpOAuth2AccessToken accessToken = wxMpService.oauth2getAccessToken(code); | |||||
// log.debug("accessToken: " + accessToken.getAccessToken() + ", openId: " + accessToken.getOpenId() + ", unionId: " + accessToken.getUnionId()); | |||||
// | |||||
// // 获取 用户信息 | |||||
// WxMpUser mpUser = wxMpService.oauth2getUserInfo(accessToken, null); | |||||
// if(mpUser != null) { | |||||
// log.debug(mpUser.toString()); | |||||
// } | |||||
// | |||||
// String uname = state; | |||||
// MallUserInfo user = mallUserInfoService.getByUsername(uname); | |||||
// if(user != null) { | |||||
// user.setWebOpenId(accessToken.getOpenId()); | |||||
// mallUserInfoService.updateWebOpenId(user); | |||||
// log.debug("https://" + host + "/#/layout"); | |||||
// response.sendRedirect("https://" + host + "/#/layout"); | |||||
// } else { | |||||
// log.debug("https://" + host + "/#/layout?errcode=绑定失败"); | |||||
// errCode = URLEncoder.encode("绑定失败", "utf-8"); | |||||
// response.sendRedirect("https://" + host + "/#/layout?errcode="+errCode); | |||||
// } | |||||
// } catch (WxErrorException e) { | |||||
// log.error(e.getMessage()); | |||||
// errCode = e.getMessage(); | |||||
// } catch (IOException e) { | |||||
// log.error(e.getMessage()); | |||||
// errCode = e.getMessage(); | |||||
// } | |||||
// | |||||
// if(StringUtils.isNotBlank(errCode)) { | |||||
// try { | |||||
// errCode = URLEncoder.encode(errCode, "utf-8"); | |||||
// response.sendRedirect("https://" + host + "/#/layout?errcode="+errCode); | |||||
// } catch (Exception e) { | |||||
// log.error(e.getMessage()); | |||||
// } | |||||
// } | |||||
// } | |||||
@ApiOperation(value = "微信第三方登录解绑", notes = "请配置此callback到网页redirect_uri") | @ApiOperation(value = "微信第三方登录解绑", notes = "请配置此callback到网页redirect_uri") | ||||
@GetMapping("cleanWebOpenId") | @GetMapping("cleanWebOpenId") | ||||
@@ -0,0 +1,471 @@ | |||||
package com.iformall.controller.sys.mallUserInfo; | |||||
import com.github.pagehelper.PageInfo; | |||||
import com.google.code.kaptcha.Constants; | |||||
import com.google.code.kaptcha.Producer; | |||||
import com.iformall.annotation.ApiVersion; | |||||
import com.iformall.common.ErrorCode; | |||||
import com.iformall.common.Result; | |||||
import com.iformall.common.ResultData; | |||||
import com.iformall.config.MyAuthenticationToken; | |||||
import com.iformall.constant.SwaggerConstant; | |||||
import com.iformall.controller.base.BaseController; | |||||
import com.iformall.domain.po.*; | |||||
import com.iformall.domain.po.base.BaseEntity; | |||||
import com.iformall.domain.po.base.TenantEntity; | |||||
import com.iformall.domain.vo.MallUserInfoVo; | |||||
import com.iformall.enums.*; | |||||
import com.iformall.exception.MallinkException; | |||||
import com.iformall.annotation.SystemControllerLog; | |||||
import com.iformall.service.*; | |||||
import com.iformall.shiro.PasswordHelper; | |||||
import com.iformall.shiro.UserSession; | |||||
import com.iformall.shiro.UseriFormallToken; | |||||
import com.iformall.utils.Constant; | |||||
import com.iformall.utils.RedisCacheUtils; | |||||
import com.iformall.utils.ShiroUtils; | |||||
import io.swagger.annotations.Api; | |||||
import io.swagger.annotations.ApiImplicitParam; | |||||
import io.swagger.annotations.ApiImplicitParams; | |||||
import io.swagger.annotations.ApiOperation; | |||||
import org.apache.commons.io.IOUtils; | |||||
import org.apache.commons.lang3.StringUtils; | |||||
import org.apache.shiro.SecurityUtils; | |||||
import org.apache.shiro.authc.DisabledAccountException; | |||||
import org.apache.shiro.authc.UnknownAccountException; | |||||
import org.apache.shiro.authc.UsernamePasswordToken; | |||||
import org.apache.shiro.session.Session; | |||||
import org.apache.shiro.subject.Subject; | |||||
import org.slf4j.Logger; | |||||
import org.slf4j.LoggerFactory; | |||||
import org.springframework.beans.factory.annotation.Autowired; | |||||
import org.springframework.beans.factory.annotation.Qualifier; | |||||
import org.springframework.beans.factory.annotation.Value; | |||||
import org.springframework.data.redis.core.RedisTemplate; | |||||
import org.springframework.util.Assert; | |||||
import org.springframework.web.bind.annotation.*; | |||||
import javax.imageio.ImageIO; | |||||
import javax.servlet.ServletException; | |||||
import javax.servlet.ServletOutputStream; | |||||
import javax.servlet.http.Cookie; | |||||
import javax.servlet.http.HttpServletResponse; | |||||
import java.awt.image.BufferedImage; | |||||
import java.io.IOException; | |||||
import java.net.URLEncoder; | |||||
import java.util.HashMap; | |||||
import java.util.List; | |||||
import java.util.Map; | |||||
public class MallUserInfoBaseController extends BaseController{ | |||||
private final Logger logger = LoggerFactory.getLogger(this.getClass()); | |||||
@Autowired | |||||
public MallUserInfoService mallUserInfoService; | |||||
@Autowired | |||||
public WxMsgValidationcodeService wxMsgValidationcodeService; | |||||
@Autowired | |||||
public MallUserActionService mallUserActionService; | |||||
@Autowired | |||||
public MallUserInfoService userInfoService; | |||||
@Autowired | |||||
public MallUserRoleService userRoleService; | |||||
@Autowired | |||||
public MallRoleService mallRoleService; | |||||
@Autowired | |||||
@Qualifier("objectCommonRedisTemplate") | |||||
public RedisTemplate<String, Object> redisTemplate; | |||||
/** | |||||
* 登录 | |||||
* @param user | |||||
* @param response | |||||
* @param projectType | |||||
* @return | |||||
*/ | |||||
public ResultData doLogin(MallUserInfo user, HttpServletResponse response,EnumProject projectType) { | |||||
String ipaddress = getIpAddr(); | |||||
try { | |||||
String kaptcha = ShiroUtils.getKaptcha(Constants.KAPTCHA_SESSION_KEY); | |||||
logger.info("登录接口-验证码:{}", user.getCaptcha()); | |||||
logger.info("登录接口-生成的验证码:{}", kaptcha); | |||||
if(!user.getCaptcha().equalsIgnoreCase(kaptcha)){ | |||||
return new ResultData(ErrorCode.KAPCHA_NOT_EQUAL); | |||||
} | |||||
} catch (MallinkException e) { | |||||
logger.error("验证码" + e.getMessage()); | |||||
return new ResultData(ErrorCode.KAPCHA_NOT_VALID.getCode(), e.getMessage()); | |||||
} | |||||
// String key = Constant.captchaPrev + ":" + getIpAddr(); | |||||
// String code = RedisCacheUtils.getCacheString(redisTemplate, key); | |||||
// if (StringUtils.isBlank(code)) { | |||||
// return new ResultData(ErrorCode.SYS_PARAMETER_ERROR.getCode(), "验证码已过期"); | |||||
// } | |||||
// if (!code.equals(user.getCaptcha())) { | |||||
// return new ResultData(ErrorCode.SYS_PARAMETER_ERROR.getCode(), "验证码不正确"); | |||||
// } | |||||
if (StringUtils.isBlank(user.getUsername()) || StringUtils.isBlank(user.getPassword())) { | |||||
return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL); | |||||
} | |||||
// check user | |||||
MallUserInfo userCheck = mallUserInfoService.getByUsername(user.getUsername(),projectType.getCode()); | |||||
if(userCheck == null) { | |||||
logger.error(ErrorCode.USER_IS_EMPTY.getMessage()); | |||||
return new ResultData(ErrorCode.USER_IS_EMPTY); | |||||
} | |||||
if(userCheck.getStatus().equals(EnumMallUserStatus.NOT_VALID.getCode())) { | |||||
logger.error(ErrorCode.USER_IS_LOCKED.getMessage()); | |||||
return new ResultData(ErrorCode.USER_IS_LOCKED); | |||||
} | |||||
boolean isLogin = false; | |||||
try { | |||||
Subject subject = SecurityUtils.getSubject(); | |||||
//UsernamePasswordToken token = new UsernamePasswordToken(user.getUsername(), user.getPassword()); | |||||
//subject.login(token); | |||||
MyAuthenticationToken mytoken = new MyAuthenticationToken(projectType.getCode(),user.getUsername(),user.getPassword().toCharArray()); | |||||
subject.login(mytoken); | |||||
isLogin = true; | |||||
logger.info("ADMIN USER:"+user.getUsername() + ", password:" + user.getPassword()); | |||||
} catch (UnknownAccountException e) { | |||||
logger.error(e.getMessage()); | |||||
return new ResultData(ErrorCode.USER_IS_EMPTY); | |||||
} catch (DisabledAccountException e) { | |||||
logger.error(e.getMessage()); | |||||
return new ResultData(ErrorCode.USER_IS_LOCKED); | |||||
} catch (Exception e) { | |||||
logger.error(e.getMessage()); | |||||
return new ResultData(ErrorCode.USER_PASSWD_ERR); | |||||
} | |||||
if(isLogin) { | |||||
MallUserInfo info = (MallUserInfo) SecurityUtils.getSubject().getSession().getAttribute(UserSession.userInfo); | |||||
info.protectInfos(); | |||||
mallUserActionService.saveActionInfo(info, EnumMallUserAction.CONTROLLER.getCode(), ipaddress, info.getId(), "用户登录"); | |||||
try { | |||||
String cookieName = URLEncoder.encode(info.getUsername(), "utf-8"); | |||||
Cookie unameCookie = new Cookie("uname", cookieName); | |||||
unameCookie.setPath("/"); | |||||
unameCookie.setMaxAge(3600); | |||||
response.addCookie(unameCookie); | |||||
return new ResultData(); | |||||
} catch (Exception e) { | |||||
logger.error(e.getMessage()); | |||||
return new ResultData(Result.ERROR, e.getMessage()); | |||||
} | |||||
} | |||||
return new ResultData(Result.ERROR,"登陆失败"); | |||||
} | |||||
//登录发送手机验证码 | |||||
public ResultData doSendLoginPhoneCode(String phone,EnumProject projectType) { | |||||
List<MallUserInfoVo> users = mallUserInfoService.getUserByPhone(phone,projectType.getCode()); | |||||
if(users.size() <= 0) { | |||||
logger.error(ErrorCode.USER_IS_EMPTY.getMessage()); | |||||
return new ResultData(ErrorCode.USER_IS_EMPTY); | |||||
} | |||||
if(users.size() > 1) { | |||||
logger.error(ErrorCode.USER_IS_MULTI.getMessage()); | |||||
return new ResultData(ErrorCode.USER_IS_MULTI); | |||||
} | |||||
MallUserInfoVo user = users.get(0); | |||||
if (user==null) { | |||||
logger.error("用户不存在, userName: " + user.getUsername()); | |||||
return new ResultData(ErrorCode.USER_IS_EMPTY); | |||||
} | |||||
if(user.getStatus() == EnumMallUserStatus.NOT_VALID.getCode()){ | |||||
logger.error("用户已停用, userName: " + user.getUsername()); | |||||
return new ResultData(ErrorCode.USER_IS_LOCKED); | |||||
} | |||||
WxMsgValidationcode wxMsgValidationcode = new WxMsgValidationcode(); | |||||
wxMsgValidationcode.setPhone(phone); | |||||
wxMsgValidationcode.updateTenantInfo(user); | |||||
wxMsgValidationcode.setType(EnumMsgModel.VALIDATION_CODE.getCode()); | |||||
return wxMsgValidationcodeService.sendvalidationcode(wxMsgValidationcode,projectType.getCode()); | |||||
} | |||||
//手机验证码登录 | |||||
public ResultData doLoginByPhone(Map<String, String> params, HttpServletResponse response,EnumProject projectType) { | |||||
String ipaddress = getIpAddr(); | |||||
logger.debug("[" + ipaddress + "] HomeController::doLoginByPhone"); | |||||
// String phone,String code,String pwd | |||||
String phone = params.get("phone"); | |||||
String code = params.get("code"); | |||||
if (StringUtils.isBlank(phone)) { | |||||
return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), "userName不能为空"); | |||||
} | |||||
if (StringUtils.isBlank(code)) { | |||||
return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), "验证码不能为空"); | |||||
} | |||||
// 获取用户信息列表 | |||||
List<MallUserInfoVo> userList = mallUserInfoService.getUserByPhone(phone,projectType.getCode()); | |||||
if(userList.size() == 1) { | |||||
MallUserInfoVo user = userList.get(0); | |||||
if (user == null) { | |||||
logger.error(ErrorCode.USER_IS_EMPTY.getMessage()); | |||||
return new ResultData(ErrorCode.USER_IS_EMPTY); | |||||
} | |||||
if (user.getStatus()==null ||!EnumMallUserStatus.VALID.getCode().equals(user.getStatus())) { | |||||
logger.error(ErrorCode.USER_IS_LOCKED.getMessage()); | |||||
return new ResultData(ErrorCode.USER_IS_LOCKED); | |||||
} | |||||
// check 验证码正确 | |||||
boolean isValidCode = false; | |||||
try { | |||||
isValidCode = wxMsgValidationcodeService.checkCodeValid(user.getPhone(),code,projectType.getCode()); | |||||
} catch (Exception e) { | |||||
return new ResultData(Result.ERROR, e.getMessage()); | |||||
} | |||||
if(isValidCode) { | |||||
// 验证码正确,直接登录 | |||||
try { | |||||
Subject subject = SecurityUtils.getSubject(); | |||||
UseriFormallToken token = new UseriFormallToken(user.getUsername()); | |||||
subject.login(token); | |||||
MallUserInfo info = (MallUserInfo) SecurityUtils.getSubject().getSession().getAttribute(UserSession.userInfo); | |||||
info.protectInfos(); | |||||
mallUserActionService.saveActionInfo(info, EnumMallUserAction.CONTROLLER.getCode(), ipaddress, info.getId(), "用户手机号登录"); | |||||
String cookieName = URLEncoder.encode(info.getUsername(), "utf-8"); | |||||
Cookie unameCookie = new Cookie("uname", cookieName); | |||||
unameCookie.setPath("/"); | |||||
unameCookie.setMaxAge(3600); | |||||
response.addCookie(unameCookie); | |||||
return new ResultData(); | |||||
} catch (MallinkException e) { | |||||
return new ResultData(e.getErrorCode(), e.getMessage()); | |||||
} catch (Exception e) { | |||||
return new ResultData(ErrorCode.USER_PASSWD_ERR); | |||||
} | |||||
} else { | |||||
return new ResultData(ErrorCode.MSG_VERIFY_CODE_NOT_FOUND); | |||||
} | |||||
} else { | |||||
return new ResultData(ErrorCode.USER_IS_EMPTY); | |||||
} | |||||
} | |||||
//分页查询用户 | |||||
public ResultData listAsPage(MallUserInfo userInfo, Integer pageNum, Integer pageSize,EnumProject projectType) { | |||||
userInfo.updateTenantInfo(getTenantInfo()); | |||||
userInfo.setSortColumns(BaseEntity.SortField.CreateTime_DESC,BaseEntity.SortField.Id_DESC); | |||||
userInfo.setProjectType(projectType.getCode()); | |||||
final PageInfo<MallUserInfo> page = userInfoService.listAsPage(userInfo, pageNum, pageSize); | |||||
for (MallUserInfo u : page.getList()) { | |||||
MallUserRole r = new MallUserRole(); | |||||
r.setUid(u.getId()); | |||||
PageInfo<MallUserRole> ur = userRoleService.listAsPage(r, 1, 1); | |||||
if (ur.getSize() > 0) { | |||||
MallRole role = mallRoleService.getById(ur.getList().get(0).getRoleId()); | |||||
if (role != null) { | |||||
u.setRoleName(role.getName()); | |||||
u.setRoleId(role.getId()); | |||||
} | |||||
} | |||||
// 保密 | |||||
u.setPassword(null); | |||||
u.setBopenId(null); | |||||
if(StringUtils.isNotBlank(u.getWebOpenId())) { | |||||
u.setWebOpenId("保密"); | |||||
} | |||||
} | |||||
return new ResultData(page); | |||||
} | |||||
//新增用户 | |||||
public ResultData doCreateUser(MallUserInfo userInfo,EnumProject projectType) { | |||||
MallUserInfo currentUser = getUser(); | |||||
if(currentUser.getIsAdmin().equals(EnumUserAdmin.Normal.getCode())) { | |||||
return new ResultData(ErrorCode.USER_NOT_ADMIN.getCode(), "只有系统管理员才能添加用户"); | |||||
} | |||||
if(!getTenantInfo().getTenantId().equals(currentUser.getTenantId())){ | |||||
return new ResultData(ErrorCode.USER_NO_PERMISSION); | |||||
} | |||||
if(checkUniqueName(userInfo.getUsername(),projectType) > 0){ | |||||
return new ResultData(ErrorCode.USER_NAME_IS_FOUND.getCode(),"用户名已存在"); | |||||
} | |||||
if(checkUniquePhone(userInfo.getPhone(),projectType) > 0){ | |||||
return new ResultData(ErrorCode.USER_PHONE_IS_FOUND.getCode(),"手机号已存在"); | |||||
} | |||||
Assert.notNull(userInfo.getPassword(), "密码不能为空"); | |||||
PasswordHelper passwordHelper = new PasswordHelper(); | |||||
passwordHelper.encryptPassword(userInfo); | |||||
userInfo.updateTenantInfo(currentUser); | |||||
// 无法创建超管 | |||||
userInfo.setIsAdmin(EnumUserAdmin.Normal.getCode()); | |||||
userInfo.setProjectType(projectType.getCode()); | |||||
userInfoService.saveOrUpdate(userInfo); | |||||
if (userInfo.getRoleId() != null) { | |||||
MallUserRole r = new MallUserRole(); | |||||
r.setRoleId(userInfo.getRoleId()); | |||||
r.setUid(userInfo.getId()); | |||||
userRoleService.saveOrUpdate(r); | |||||
} | |||||
return new ResultData(userInfo); | |||||
} | |||||
//修改用户 | |||||
public ResultData doUpdateUser(MallUserInfo userInfo,EnumProject projectType) { | |||||
boolean bChangedPhone = false; | |||||
MallUserInfo currentUser = getUser(); | |||||
// 只有超管和自己能更新信息 | |||||
if (!(currentUser.getId().equals(userInfo.getId()) || | |||||
currentUser.getIsAdmin().equals(EnumUserAdmin.ADMIN.getCode()))) { | |||||
return new ResultData(ErrorCode.USER_NO_PERMISSION.getCode(), "系统管理员和自己才能修改信息"); | |||||
} | |||||
// if(!getTenantInfo().getTenantId().equals(currentUser.getTenantId())){ | |||||
// return new ResultData(ErrorCode.USER_NO_PERMISSION); | |||||
// } | |||||
MallUserInfo oldUser = userInfoService.getById(userInfo.getId()); | |||||
if (!oldUser.getUsername().equals(userInfo.getUsername())) { | |||||
if(checkUniqueName(userInfo.getUsername(),projectType) > 0){ | |||||
return new ResultData(ErrorCode.USER_NAME_IS_FOUND.getCode(),"用户名已存在"); | |||||
} | |||||
} | |||||
if (!oldUser.getPhone().equals(userInfo.getPhone())) { | |||||
if(checkUniquePhone(userInfo.getPhone(),projectType) > 0){ | |||||
return new ResultData(ErrorCode.USER_PHONE_IS_FOUND.getCode(),"手机号已存在"); | |||||
} | |||||
bChangedPhone = true; | |||||
} | |||||
userInfo.updateTenantInfo(currentUser); | |||||
if (StringUtils.isNotBlank(userInfo.getPassword()) && userInfo.getPassword().length() > 0) { | |||||
PasswordHelper passwordHelper = new PasswordHelper(); | |||||
passwordHelper.encryptPassword(userInfo); | |||||
} | |||||
// 系统内人员不能设置系统管理员 | |||||
userInfo.setIsAdmin(EnumUserAdmin.Normal.getCode()); | |||||
/* | |||||
if (!currentUser.getIsAdmin().equals(EnumUserAdmin.ADMIN.getCode())) { | |||||
// 只有系统管理员才能设置系统管理员 | |||||
userInfo.setIsAdmin(null); | |||||
} | |||||
*/ | |||||
if (currentUser.getIsAdmin().equals(EnumUserAdmin.ADMIN.getCode()) && | |||||
currentUser.getId().equals(userInfo.getId())) { | |||||
// 超管 | |||||
MallUserInfo adminUser = new MallUserInfo(); | |||||
adminUser.setEmail(userInfo.getEmail()); | |||||
adminUser.setId(userInfo.getId()); | |||||
if (StringUtils.isNotBlank(userInfo.getPassword()) && userInfo.getPassword().length() > 0) { | |||||
adminUser.setPassword(userInfo.getPassword()); | |||||
} | |||||
if (StringUtils.isNotBlank(userInfo.getNickName())) { | |||||
adminUser.setNickName(userInfo.getNickName()); | |||||
} | |||||
if (StringUtils.isNotBlank(userInfo.getPhone())) { | |||||
adminUser.setPhone(userInfo.getPhone()); | |||||
} | |||||
adminUser.setInvestRule(userInfo.getInvestRule()); | |||||
userInfoService.saveOrUpdate(adminUser); | |||||
} else { | |||||
userInfoService.saveOrUpdate(userInfo); | |||||
if (userInfo.getRoleId() != null) { | |||||
userRoleService.deleteByUserId(userInfo.getId()); | |||||
MallUserRole r = new MallUserRole(); | |||||
r.setRoleId(userInfo.getRoleId()); | |||||
r.setUid(userInfo.getId()); | |||||
userRoleService.saveOrUpdate(r); | |||||
} | |||||
} | |||||
if(bChangedPhone) { | |||||
// 手机号修改,清除bopen_id, 清除web_open_id | |||||
userInfoService.cleanAllOpenId(userInfo); | |||||
} | |||||
return new ResultData(); | |||||
} | |||||
public int checkUniqueName(String userName,EnumProject projectType) { | |||||
return userInfoService.cntByUserName(userName,projectType.getCode()); | |||||
} | |||||
public int checkUniquePhone(String phone,EnumProject projectType) { | |||||
return userInfoService.cntByUserPhone(phone,projectType.getCode()); | |||||
} | |||||
//向用户发送验证码 | |||||
public ResultData doSendvalidationcode(String userName, Integer type,EnumProject projectType) { | |||||
MallUserInfo userQ = new MallUserInfo(); | |||||
userQ.setUsername(userName); | |||||
MallUserInfo user = userInfoService.getByUsername(userName,projectType.getCode()); | |||||
if (user==null) { | |||||
logger.error("用户不存在, userName: " + userName); | |||||
return new ResultData(ErrorCode.USER_IS_EMPTY); | |||||
} | |||||
if(user.getStatus() == EnumMallUserStatus.NOT_VALID.getCode()){ | |||||
logger.error("用户已停用, userName: " + userName); | |||||
return new ResultData(ErrorCode.USER_IS_LOCKED); | |||||
} | |||||
if (StringUtils.isBlank(user.getPhone())) { | |||||
logger.error("用户手机号为空, userName: " + userName); | |||||
return new ResultData(ErrorCode.USER_PHONE_IS_NOT_FOUND); | |||||
} | |||||
WxMsgValidationcode wxMsgValidationcode = new WxMsgValidationcode(); | |||||
wxMsgValidationcode.updateTenantInfo(user); | |||||
wxMsgValidationcode.setPhone(user.getPhone()); | |||||
wxMsgValidationcode.setType(type); | |||||
return wxMsgValidationcodeService.sendvalidationcode(wxMsgValidationcode,projectType.getCode()); | |||||
} | |||||
//更改用户密码 | |||||
public ResultData doUpdatepwd(Map<String, String> params,EnumProject projectType) { | |||||
// String phone,String code,String pwd | |||||
String userName = params.get("userName"); | |||||
String code = params.get("code"); | |||||
String pwd = params.get("pwd"); | |||||
if (StringUtils.isBlank(userName)) { | |||||
return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), "userName不能为空"); | |||||
} | |||||
if (StringUtils.isBlank(code)) { | |||||
return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), "验证码不能为空"); | |||||
} | |||||
if (StringUtils.isBlank(pwd)) { | |||||
return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), "密码不能为空"); | |||||
} | |||||
MallUserInfo userQ = new MallUserInfo(); | |||||
userQ.setUsername(userName); | |||||
MallUserInfo user = userInfoService.getByUsername(userName,projectType.getCode()); | |||||
if (user==null) { | |||||
logger.error("用户不存在, userName: " + userName); | |||||
return new ResultData(ErrorCode.USER_IS_EMPTY); | |||||
} | |||||
user.setPassword(pwd); | |||||
PasswordHelper passwordHelper = new PasswordHelper(); | |||||
passwordHelper.encryptPassword(user); | |||||
try { | |||||
return userInfoService.updatepwd(user, code); | |||||
} catch (Exception e) { | |||||
return new ResultData(Result.ERROR, e.getMessage()); | |||||
} | |||||
} | |||||
} |
@@ -3,6 +3,7 @@ package com.iformall.shiro; | |||||
import javax.annotation.Resource; | import javax.annotation.Resource; | ||||
import com.iformall.common.ErrorCode; | import com.iformall.common.ErrorCode; | ||||
import com.iformall.config.MyAuthenticationToken; | |||||
import com.iformall.enums.EnumMallUserStatus; | import com.iformall.enums.EnumMallUserStatus; | ||||
import com.iformall.service.MallUserInfoService; | import com.iformall.service.MallUserInfoService; | ||||
import org.apache.commons.lang3.StringUtils; | import org.apache.commons.lang3.StringUtils; | ||||
@@ -27,7 +28,13 @@ public class MyShiroRealm extends AuthorizingRealm { | |||||
@Resource | @Resource | ||||
private MallUserInfoService userService; | private MallUserInfoService userService; | ||||
//授权 | |||||
//识别自定义token | |||||
@Override | |||||
public boolean supports(AuthenticationToken token) { | |||||
return token != null && token instanceof MyAuthenticationToken; | |||||
} | |||||
//授权 | |||||
@Override | @Override | ||||
protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principalCollection) { | protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principalCollection) { | ||||
MallUserInfo user= (MallUserInfo) SecurityUtils.getSubject().getPrincipal(); | MallUserInfo user= (MallUserInfo) SecurityUtils.getSubject().getPrincipal(); | ||||
@@ -40,9 +47,10 @@ public class MyShiroRealm extends AuthorizingRealm { | |||||
//认证 | //认证 | ||||
@Override | @Override | ||||
protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken token) throws AuthenticationException { | protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken token) throws AuthenticationException { | ||||
MyAuthenticationToken mytoken = (MyAuthenticationToken) token; | |||||
//获取用户的输入的账号. | //获取用户的输入的账号. | ||||
String username = (String)token.getPrincipal(); | |||||
MallUserInfo user = userService.getByUsername(username); | |||||
//String username = (String)token.getPrincipal(); | |||||
MallUserInfo user = userService.getByUsername(mytoken.getUsername(),mytoken.getProjectType()); | |||||
if(user == null) { | if(user == null) { | ||||
throw new UnknownAccountException(ErrorCode.USER_IS_EMPTY.getMessage()); | throw new UnknownAccountException(ErrorCode.USER_IS_EMPTY.getMessage()); | ||||
} | } | ||||
@@ -54,7 +62,7 @@ public class MyShiroRealm extends AuthorizingRealm { | |||||
SimpleAuthenticationInfo authenticationInfo = new SimpleAuthenticationInfo( | SimpleAuthenticationInfo authenticationInfo = new SimpleAuthenticationInfo( | ||||
user, //用户 | user, //用户 | ||||
user.getPassword(), //密码 | user.getPassword(), //密码 | ||||
ByteSource.Util.bytes(username), | |||||
ByteSource.Util.bytes(mytoken.getUsername()), | |||||
getName() //realm name | getName() //realm name | ||||
); | ); | ||||
// 当验证都通过后,把用户信息放在session里 | // 当验证都通过后,把用户信息放在session里 | ||||
@@ -18,5 +18,16 @@ ALTER TABLE `user_mould_video` | |||||
ADD COLUMN cost_points_detail varchar(500) COMMENT '消耗金币明细' ; | ADD COLUMN cost_points_detail varchar(500) COMMENT '消耗金币明细' ; | ||||
ALTER TABLE `service_info` | |||||
ADD COLUMN mall_user_info int(11) COMMENT '登录用户编号' ; | |||||
ALTER TABLE `mall_user_info` | |||||
ADD COLUMN project_type int(1) NOT NULL COMMENT '所属项目EnumProject' ; | |||||
ALTER TABLE wx_msg_validationcode | |||||
ADD COLUMN project_type int(1) NOT NULL COMMENT '所属项目EnumProject' ; | |||||
@@ -280,7 +280,7 @@ public class MiniAppUserController extends BaseController { | |||||
// check 验证码正确 | // check 验证码正确 | ||||
boolean isValidCode = false; | boolean isValidCode = false; | ||||
try { | try { | ||||
isValidCode = wxMsgValidationcodeService.checkCodeValid(phone, code); | |||||
isValidCode = wxMsgValidationcodeService.checkCodeValid(phone, code,0); | |||||
} catch (Exception e) { | } catch (Exception e) { | ||||
return new ResultData(Result.ERROR, e.getMessage()); | return new ResultData(Result.ERROR, e.getMessage()); | ||||
} | } | ||||
@@ -298,7 +298,7 @@ public class WxUserGrantController extends BaseController { | |||||
// check 验证码正确 | // check 验证码正确 | ||||
boolean isValidCode = false; | boolean isValidCode = false; | ||||
try { | try { | ||||
isValidCode = wxMsgValidationcodeService.checkCodeValid(phone, code); | |||||
isValidCode = wxMsgValidationcodeService.checkCodeValid(phone, code,0); | |||||
} catch (Exception e) { | } catch (Exception e) { | ||||
return new ResultData(Result.ERROR, e.getMessage()); | return new ResultData(Result.ERROR, e.getMessage()); | ||||
} | } | ||||
@@ -345,7 +345,7 @@ public class WxUserGrantController extends BaseController { | |||||
WxMsgValidationcode wxMsgValidationcode = new WxMsgValidationcode(); | WxMsgValidationcode wxMsgValidationcode = new WxMsgValidationcode(); | ||||
wxMsgValidationcode.setPhone(phone); | wxMsgValidationcode.setPhone(phone); | ||||
wxMsgValidationcode.setType(EnumMsgModel.VALIDATION_CODE.getCode()); | wxMsgValidationcode.setType(EnumMsgModel.VALIDATION_CODE.getCode()); | ||||
return wxMsgValidationcodeService.sendvalidationcode(wxMsgValidationcode); | |||||
return wxMsgValidationcodeService.sendvalidationcode(wxMsgValidationcode,0); | |||||
} | } | ||||
@@ -395,7 +395,7 @@ public class WxUserGrantController extends BaseController { | |||||
WxMsgValidationcode wxMsgValidationcode = new WxMsgValidationcode(); | WxMsgValidationcode wxMsgValidationcode = new WxMsgValidationcode(); | ||||
wxMsgValidationcode.setPhone(phone); | wxMsgValidationcode.setPhone(phone); | ||||
wxMsgValidationcode.setType(EnumMsgModel.VALIDATION_CODE.getCode()); | wxMsgValidationcode.setType(EnumMsgModel.VALIDATION_CODE.getCode()); | ||||
return wxMsgValidationcodeService.sendvalidationcode(wxMsgValidationcode); | |||||
return wxMsgValidationcodeService.sendvalidationcode(wxMsgValidationcode,0); | |||||
} | } | ||||
@@ -592,7 +592,7 @@ public class WxUserGrantController extends BaseController { | |||||
// check 验证码正确 | // check 验证码正确 | ||||
boolean isValidCode = false; | boolean isValidCode = false; | ||||
try { | try { | ||||
isValidCode = wxMsgValidationcodeService.checkCodeValid(phone, code); | |||||
isValidCode = wxMsgValidationcodeService.checkCodeValid(phone, code,0); | |||||
} catch (Exception e) { | } catch (Exception e) { | ||||
return new ResultData(Result.ERROR, e.getMessage()); | return new ResultData(Result.ERROR, e.getMessage()); | ||||
} | } | ||||
@@ -26,7 +26,7 @@ public class MyRetryLimitCredentialsMatcher extends HashedCredentialsMatcher { | |||||
if(tk.getType().equals(EnumLoginType.NOPASSWD)){ | if(tk.getType().equals(EnumLoginType.NOPASSWD)){ | ||||
// 获取用户的输入的账号. | // 获取用户的输入的账号. | ||||
String username = (String)tk.getPrincipal(); | String username = (String)tk.getPrincipal(); | ||||
MallUserInfo user = userService.getByUsername(username); | |||||
MallUserInfo user = userService.getByUsername(username,tk.getProjectType()); | |||||
if(user == null) { | if(user == null) { | ||||
throw new UnknownAccountException(ErrorCode.USER_IS_EMPTY.getMessage()); | throw new UnknownAccountException(ErrorCode.USER_IS_EMPTY.getMessage()); | ||||
} | } | ||||
@@ -39,7 +39,7 @@ public class MyShiroRealm extends AuthorizingRealm { | |||||
protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken token) throws AuthenticationException { | protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken token) throws AuthenticationException { | ||||
//获取用户的输入的账号. | //获取用户的输入的账号. | ||||
String username = (String)token.getPrincipal(); | String username = (String)token.getPrincipal(); | ||||
MallUserInfo user = userService.getByUsername(username); | |||||
MallUserInfo user = userService.getByUsername(username,0); | |||||
if(user == null) { | if(user == null) { | ||||
throw new UnknownAccountException(ErrorCode.USER_IS_EMPTY.getMessage()); | throw new UnknownAccountException(ErrorCode.USER_IS_EMPTY.getMessage()); | ||||
} | } | ||||
@@ -7,14 +7,16 @@ public class UseriFormallToken extends UsernamePasswordToken { | |||||
private static final long serialVersionUID = -2564928913725078138L; | private static final long serialVersionUID = -2564928913725078138L; | ||||
private EnumLoginType type; | private EnumLoginType type; | ||||
private int projectType; | |||||
public UseriFormallToken() { | public UseriFormallToken() { | ||||
super(); | super(); | ||||
} | } | ||||
public UseriFormallToken(String username, String password, EnumLoginType type, boolean rememberMe, String host) { | |||||
public UseriFormallToken(String username, String password, EnumLoginType type, boolean rememberMe, String host,int projectType) { | |||||
super(username, password, rememberMe, host); | super(username, password, rememberMe, host); | ||||
this.type = type; | this.type = type; | ||||
this.projectType = projectType; | |||||
} | } | ||||
/** 免密登录 */ | /** 免密登录 */ | ||||
@@ -36,4 +38,13 @@ public class UseriFormallToken extends UsernamePasswordToken { | |||||
public void setType(EnumLoginType type) { | public void setType(EnumLoginType type) { | ||||
this.type = type; | this.type = type; | ||||
} | } | ||||
public int getProjectType() { | |||||
return projectType; | |||||
} | |||||
public void setProjectType(int projectType) { | |||||
this.projectType = projectType; | |||||
} | |||||
} | } |
@@ -78,6 +78,9 @@ public class MallUserInfo extends TenantEntity { | |||||
@io.swagger.annotations.ApiModelProperty(value = "邮箱", name = "email") | @io.swagger.annotations.ApiModelProperty(value = "邮箱", name = "email") | ||||
private String email; | private String email; | ||||
@io.swagger.annotations.ApiModelProperty(value = "所属项目EnumProject", name = "projectType") | |||||
private Integer projectType; | |||||
public Integer getWithWechatNotFormat() { | public Integer getWithWechatNotFormat() { | ||||
return this.withWechat; | return this.withWechat; | ||||
@@ -30,6 +30,8 @@ public class WxMsgValidationcode extends TenantEntity { | |||||
private String signature; | private String signature; | ||||
@io.swagger.annotations.ApiModelProperty(value="",name="code") | @io.swagger.annotations.ApiModelProperty(value="",name="code") | ||||
private String code; | private String code; | ||||
@io.swagger.annotations.ApiModelProperty(value="所属项目EnumProject",name="projectType") | |||||
private Integer projectType; | |||||
@TableField(exist = false) | @TableField(exist = false) | ||||
private String createtimeStr; | private String createtimeStr; | ||||
@@ -66,4 +66,10 @@ public class ServiceInfo extends BaseEntity{ | |||||
*/ | */ | ||||
@TableField("del_flag") | @TableField("del_flag") | ||||
private Integer delFlag; | private Integer delFlag; | ||||
/** | |||||
* 登录用户 | |||||
*/ | |||||
@TableField("mall_user_info") | |||||
private Long mallUserInfo; | |||||
} | } |
@@ -15,7 +15,7 @@ public interface MallUserInfoMapper extends CommonMapper<MallUserInfo, String> { | |||||
List<MallUserInfo> findList(MallUserInfo mallUserInfo); | List<MallUserInfo> findList(MallUserInfo mallUserInfo); | ||||
MallUserInfo selectByUserName(@Param("username") String username); | |||||
MallUserInfo selectByUserName(@Param("username") String username,@Param("projectType") Integer projectType); | |||||
MallUserInfo selectByUserNameWebOpen(@Param("username") String username, @Param("webOpenId") String webOpenId); | MallUserInfo selectByUserNameWebOpen(@Param("username") String username, @Param("webOpenId") String webOpenId); | ||||
@@ -34,7 +34,7 @@ public interface MallUserInfoMapper extends CommonMapper<MallUserInfo, String> { | |||||
int cntByUserName(Map<String,Object> params); | int cntByUserName(Map<String,Object> params); | ||||
List<MallUserInfoVo> selectUsersByPhone(@Param("phone") String phone); | |||||
List<MallUserInfoVo> selectUsersByPhone(@Param("phone") String phone,@Param("projectType") Integer projectType); | |||||
List<MallUserInfoVo> selectUsersByWebOpenId(@Param("webOpenId") String webOpenId); | List<MallUserInfoVo> selectUsersByWebOpenId(@Param("webOpenId") String webOpenId); | ||||
@@ -31,7 +31,7 @@ public interface MallUserInfoService { | |||||
* @param username | * @param username | ||||
* @return | * @return | ||||
*/ | */ | ||||
MallUserInfo getByUsername(String username); | |||||
MallUserInfo getByUsername(String username,int projectType); | |||||
/** | /** | ||||
@@ -121,14 +121,14 @@ public interface MallUserInfoService { | |||||
* | * | ||||
* @param username | * @param username | ||||
*/ | */ | ||||
int cntByUserName(String username); | |||||
int cntByUserName(String username,int projectType); | |||||
/** | /** | ||||
* 查询手机号,用于校验手机号是否重复 | * 查询手机号,用于校验手机号是否重复 | ||||
* | * | ||||
* @param phone | * @param phone | ||||
*/ | */ | ||||
int cntByUserPhone(String phone); | |||||
int cntByUserPhone(String phone,int projectType); | |||||
@@ -164,7 +164,7 @@ public interface MallUserInfoService { | |||||
* @param phone | * @param phone | ||||
* @return | * @return | ||||
*/ | */ | ||||
List<MallUserInfoVo> getUserByPhone(String phone); | |||||
List<MallUserInfoVo> getUserByPhone(String phone,int projectType); | |||||
void updateBOpenId(MallUserInfo user); | void updateBOpenId(MallUserInfo user); | ||||
@@ -37,9 +37,9 @@ public interface WxMsgValidationcodeService { | |||||
void deleteById(Long id); | void deleteById(Long id); | ||||
ResultData sendvalidationcode(WxMsgValidationcode record); | |||||
ResultData sendvalidationcode(WxMsgValidationcode record,int projectType); | |||||
boolean checkCodeValid(String phone, String code); | |||||
boolean checkCodeValid(String phone, String code,int projectType); | |||||
ResultData hasvalidationcode(WxMsgValidationcode record); | ResultData hasvalidationcode(WxMsgValidationcode record); | ||||
@@ -106,8 +106,8 @@ public class MallUserInfoServiceImpl implements MallUserInfoService { | |||||
} | } | ||||
@Override | @Override | ||||
public List<MallUserInfoVo> getUserByPhone(String phone) { | |||||
return mallUserInfoMapper.selectUsersByPhone(phone); | |||||
public List<MallUserInfoVo> getUserByPhone(String phone,int projectType) { | |||||
return mallUserInfoMapper.selectUsersByPhone(phone,projectType); | |||||
} | } | ||||
@Override | @Override | ||||
@@ -209,21 +209,23 @@ public class MallUserInfoServiceImpl implements MallUserInfoService { | |||||
} | } | ||||
@Override | @Override | ||||
public MallUserInfo getByUsername(String username) { | |||||
return mallUserInfoMapper.selectByUserName(username); | |||||
public MallUserInfo getByUsername(String username,int projectType) { | |||||
return mallUserInfoMapper.selectByUserName(username,projectType); | |||||
} | } | ||||
@Override | @Override | ||||
public int cntByUserName(String username) { | |||||
public int cntByUserName(String username,int projectType) { | |||||
Map<String, Object> params = new HashMap<>(); | Map<String, Object> params = new HashMap<>(); | ||||
params.put("username", username); | params.put("username", username); | ||||
params.put("projectType", projectType); | |||||
return mallUserInfoMapper.cntByUserName(params); | return mallUserInfoMapper.cntByUserName(params); | ||||
} | } | ||||
@Override | @Override | ||||
public int cntByUserPhone(String phone) { | |||||
public int cntByUserPhone(String phone,int projectType) { | |||||
Map<String, Object> params = new HashMap<>(); | Map<String, Object> params = new HashMap<>(); | ||||
params.put("phone", phone); | params.put("phone", phone); | ||||
params.put("projectType", projectType); | |||||
return mallUserInfoMapper.cntByUserName(params); | return mallUserInfoMapper.cntByUserName(params); | ||||
} | } | ||||
@@ -326,10 +326,10 @@ public class WxMallServiceImpl implements WxMallService { | |||||
userInfo.setPassword(wxMall.getAdminPassword()); | userInfo.setPassword(wxMall.getAdminPassword()); | ||||
if(userInfo.getId() == null){ | if(userInfo.getId() == null){ | ||||
if(userInfoService.cntByUserName(userInfo.getUsername()) > 0){ | |||||
if(userInfoService.cntByUserName(userInfo.getUsername(),0) > 0){ | |||||
return new ResultData(ErrorCode.USER_NAME_IS_FOUND.getCode(),"用户名已存在"); | return new ResultData(ErrorCode.USER_NAME_IS_FOUND.getCode(),"用户名已存在"); | ||||
} | } | ||||
if(userInfoService.cntByUserPhone(userInfo.getPhone()) > 0){ | |||||
if(userInfoService.cntByUserPhone(userInfo.getPhone(),0) > 0){ | |||||
return new ResultData(ErrorCode.USER_PHONE_IS_FOUND.getCode(),"手机号已存在"); | return new ResultData(ErrorCode.USER_PHONE_IS_FOUND.getCode(),"手机号已存在"); | ||||
} | } | ||||
if(StringUtils.isBlank(userInfo.getPassword())){ | if(StringUtils.isBlank(userInfo.getPassword())){ | ||||
@@ -356,7 +356,7 @@ public class WxMallServiceImpl implements WxMallService { | |||||
// } | // } | ||||
// } | // } | ||||
if (!oldUser.getPhone().equals(userInfo.getPhone())) { | if (!oldUser.getPhone().equals(userInfo.getPhone())) { | ||||
if(userInfoService.cntByUserPhone(userInfo.getPhone()) > 0){ | |||||
if(userInfoService.cntByUserPhone(userInfo.getPhone(),0) > 0){ | |||||
return new ResultData(ErrorCode.USER_PHONE_IS_FOUND.getCode(),"手机号已存在"); | return new ResultData(ErrorCode.USER_PHONE_IS_FOUND.getCode(),"手机号已存在"); | ||||
} | } | ||||
bChangedPhone = true; | bChangedPhone = true; | ||||
@@ -97,9 +97,9 @@ public class WxMsgValidationcodeServiceImpl implements WxMsgValidationcodeServic | |||||
@Override | @Override | ||||
public ResultData sendvalidationcode(WxMsgValidationcode wxMsgValidationcode) { | |||||
public ResultData sendvalidationcode(WxMsgValidationcode wxMsgValidationcode,int projectType) { | |||||
//1、查看是否存在未过期的短信,有返回成功 没有继续 | //1、查看是否存在未过期的短信,有返回成功 没有继续 | ||||
String key = Constant.codePrev + ":" + wxMsgValidationcode.getPhone(); | |||||
String key = Constant.codePrev + ":"+projectType+":" + wxMsgValidationcode.getPhone(); | |||||
Long expire = RedisCacheUtils.getExpire(redisTemplate, key); | Long expire = RedisCacheUtils.getExpire(redisTemplate, key); | ||||
if(expire != null && expire > 60*4l){ | if(expire != null && expire > 60*4l){ | ||||
return new ResultData(ErrorCode.MSG_REPEAT_SEND); | return new ResultData(ErrorCode.MSG_REPEAT_SEND); | ||||
@@ -108,6 +108,7 @@ public class WxMsgValidationcodeServiceImpl implements WxMsgValidationcodeServic | |||||
//2 判断是否已超过10条 | //2 判断是否已超过10条 | ||||
String systemTime = DateUtils.getSystemTime("yyyy-MM-dd"); | String systemTime = DateUtils.getSystemTime("yyyy-MM-dd"); | ||||
wxMsgValidationcode.setCreatetimeStr(systemTime); | wxMsgValidationcode.setCreatetimeStr(systemTime); | ||||
wxMsgValidationcode.setProjectType(projectType); | |||||
Integer count = wxMsgValidationcodeMapper.findListCount(wxMsgValidationcode); | Integer count = wxMsgValidationcodeMapper.findListCount(wxMsgValidationcode); | ||||
if (count != null && count.intValue() > 20) { | if (count != null && count.intValue() > 20) { | ||||
return new ResultData(ErrorCode.MSG_SEND_ERROR.getCode(), "验证码发送超限"); | return new ResultData(ErrorCode.MSG_SEND_ERROR.getCode(), "验证码发送超限"); | ||||
@@ -129,8 +130,8 @@ public class WxMsgValidationcodeServiceImpl implements WxMsgValidationcodeServic | |||||
} | } | ||||
@Override | @Override | ||||
public boolean checkCodeValid(String phone, String code) { | |||||
String key = Constant.codePrev + ":" + phone; | |||||
public boolean checkCodeValid(String phone, String code,int projectType) { | |||||
String key = Constant.codePrev + ":"+ projectType +":" + phone; | |||||
String cacheCode = RedisCacheUtils.getCacheString(redisTemplate, key); | String cacheCode = RedisCacheUtils.getCacheString(redisTemplate, key); | ||||
if(cacheCode == null || !cacheCode.equals(code)){ | if(cacheCode == null || !cacheCode.equals(code)){ | ||||
return false; | return false; | ||||
@@ -18,14 +18,15 @@ | |||||
<result column="bopen_id" jdbcType="VARCHAR" property="bopenId"/> | <result column="bopen_id" jdbcType="VARCHAR" property="bopenId"/> | ||||
<result column="web_open_id" jdbcType="VARCHAR" property="webOpenId"/> | <result column="web_open_id" jdbcType="VARCHAR" property="webOpenId"/> | ||||
<result column="email" jdbcType="VARCHAR" property="email"/> | <result column="email" jdbcType="VARCHAR" property="email"/> | ||||
<result column="project_type" jdbcType="VARCHAR" property="projectType"/> | |||||
</resultMap> | </resultMap> | ||||
<sql id="allSafeColumns"> | <sql id="allSafeColumns"> | ||||
`id`,`tenant_id`,`parent_tenant_id`,`username`,`name`,`password`,`create_time`,`last_login_time`,`status`,`is_admin`,`invest_rule`,`nick_name`,`phone`,`web_open_id`,email | |||||
`id`,`tenant_id`,`parent_tenant_id`,`username`,`name`,`password`,`create_time`,`last_login_time`,`status`,`is_admin`,`invest_rule`,`nick_name`,`phone`,`web_open_id`,email,`project_type` | |||||
</sql> | </sql> | ||||
<sql id="allColumns"> | <sql id="allColumns"> | ||||
`id`,`tenant_id`,`parent_tenant_id`,`username`,`name`,`password`,`create_time`,`last_login_time`,`status`,`is_admin`,`invest_rule`,`nick_name`,`phone`, | |||||
`id`,`tenant_id`,`parent_tenant_id`,`username`,`name`,`password`,`create_time`,`last_login_time`,`status`,`is_admin`,`invest_rule`,`nick_name`,`phone`,`project_type` | |||||
`bopen_id`,`web_open_id`,email | `bopen_id`,`web_open_id`,email | ||||
</sql> | </sql> | ||||
@@ -89,6 +90,9 @@ | |||||
<if test=" null != email "> | <if test=" null != email "> | ||||
and `email` = #{email} | and `email` = #{email} | ||||
</if> | </if> | ||||
<if test=" null != projectType "> | |||||
and `project_type` = #{projectType} | |||||
</if> | |||||
<if test="null != withWechatForQuery "> | <if test="null != withWechatForQuery "> | ||||
<if test="0 == withWechatForQuery "> | <if test="0 == withWechatForQuery "> | ||||
and `web_open_id` is not null | and `web_open_id` is not null | ||||
@@ -122,6 +126,9 @@ | |||||
<if test=" null != username "> | <if test=" null != username "> | ||||
and username=#{username} | and username=#{username} | ||||
</if> | </if> | ||||
<if test=" null != projectType "> | |||||
and project_type=#{projectType} | |||||
</if> | |||||
</select> | </select> | ||||
<select id="getById" resultMap="BaseResultMap"> | <select id="getById" resultMap="BaseResultMap"> | ||||
@@ -230,7 +237,7 @@ | |||||
</select> | </select> | ||||
<select id="cntByUserName" resultType="java.lang.Integer"> | <select id="cntByUserName" resultType="java.lang.Integer"> | ||||
select count(*) from mall_user_info where status = 1 | |||||
select count(1) from mall_user_info where status = 1 | |||||
<if test=" null != username "> | <if test=" null != username "> | ||||
and username=#{username} | and username=#{username} | ||||
</if> | </if> | ||||
@@ -240,6 +247,9 @@ | |||||
<if test=" null != id "> | <if test=" null != id "> | ||||
and `id` != #{id} | and `id` != #{id} | ||||
</if> | </if> | ||||
<if test=" null != projectType "> | |||||
and project_type=#{projectType} | |||||
</if> | |||||
</select> | </select> | ||||
<!-- 查询用户的所有权限 --> | <!-- 查询用户的所有权限 --> | ||||
@@ -284,6 +294,7 @@ | |||||
<result column="bopen_id" jdbcType="VARCHAR" property="bopenId"/> | <result column="bopen_id" jdbcType="VARCHAR" property="bopenId"/> | ||||
<result column="web_open_id" jdbcType="VARCHAR" property="webOpenId"/> | <result column="web_open_id" jdbcType="VARCHAR" property="webOpenId"/> | ||||
<result column="email" property="email"/> | <result column="email" property="email"/> | ||||
<result column="project_type" property="projectType"/> | |||||
<result column="mall_name" jdbcType="VARCHAR" property="mallName"/> | <result column="mall_name" jdbcType="VARCHAR" property="mallName"/> | ||||
<result column="mall_group" jdbcType="VARCHAR" property="mallGroup"/> | <result column="mall_group" jdbcType="VARCHAR" property="mallGroup"/> | ||||
@@ -293,13 +304,13 @@ | |||||
<sql id="allSafeVColumns"> | <sql id="allSafeVColumns"> | ||||
u.`id`,u.`tenant_id`,u.`parent_tenant_id`,u.`username`,u.`name`,u.`password`,u.`create_time`,u.`last_login_time`,u.`status`,u.`is_admin`,u.`invest_rule`,u.`nick_name`,u.`phone`, | u.`id`,u.`tenant_id`,u.`parent_tenant_id`,u.`username`,u.`name`,u.`password`,u.`create_time`,u.`last_login_time`,u.`status`,u.`is_admin`,u.`invest_rule`,u.`nick_name`,u.`phone`, | ||||
m.`name` as mall_name, m.`group` as mall_group, m.`img_url`, m.`img_url_h`,email | |||||
m.`name` as mall_name, m.`group` as mall_group, m.`img_url`, m.`img_url_h`,u.email,u.`project_type` | |||||
</sql> | </sql> | ||||
<sql id="allVColumns"> | <sql id="allVColumns"> | ||||
u.`id`,u.`tenant_id`,u.`parent_tenant_id`,u.`username`,u.`name`,u.`password`,u.`create_time`,u.`last_login_time`,u.`status`,u.`is_admin`,u.`invest_rule`,u.`nick_name`,u.`phone`, | u.`id`,u.`tenant_id`,u.`parent_tenant_id`,u.`username`,u.`name`,u.`password`,u.`create_time`,u.`last_login_time`,u.`status`,u.`is_admin`,u.`invest_rule`,u.`nick_name`,u.`phone`, | ||||
u.`bopen_id`,u.`web_open_id`, | u.`bopen_id`,u.`web_open_id`, | ||||
m.`name` as mall_name, m.`group` as mall_group, m.`img_url`, m.`img_url_h`,email | |||||
m.`name` as mall_name, m.`group` as mall_group, m.`img_url`, m.`img_url_h`,u.email,u.`project_type` | |||||
</sql> | </sql> | ||||
@@ -312,6 +323,9 @@ | |||||
<if test=" null != phone "> | <if test=" null != phone "> | ||||
and u.`phone` = #{phone} | and u.`phone` = #{phone} | ||||
</if> | </if> | ||||
<if test=" null != projectType "> | |||||
and u.project_type=#{projectType} | |||||
</if> | |||||
</select> | </select> | ||||
<select id="selectUsersByWebOpenId" resultMap="VBaseResultMap"> | <select id="selectUsersByWebOpenId" resultMap="VBaseResultMap"> | ||||
@@ -5,7 +5,7 @@ | |||||
<sql id="allColumns"> | <sql id="allColumns"> | ||||
`id`, `create_time`, `update_time`, `name`, `address`, `code`, `type`, `status`, `del_flag` | |||||
`id`, `create_time`, `update_time`, `name`, `address`, `code`, `type`, `status`, `del_flag`, `mall_user_info` | |||||
</sql> | </sql> | ||||
<sql id="dynamicWhereConditions"> | <sql id="dynamicWhereConditions"> | ||||
@@ -28,6 +28,9 @@ | |||||
<if test=" null != delFlag "> | <if test=" null != delFlag "> | ||||
and `del_flag` = #{delFlag} | and `del_flag` = #{delFlag} | ||||
</if> | </if> | ||||
<if test=" null != mallUserInfo "> | |||||
and `mall_user_info` = #{mallUserInfo} | |||||
</if> | |||||
</sql> | </sql> | ||||
<select id="listServiceInfo" resultType="com.iformall.domain.po.sm.ServiceInfo"> | <select id="listServiceInfo" resultType="com.iformall.domain.po.sm.ServiceInfo"> | ||||
@@ -12,10 +12,11 @@ | |||||
<result column="msg" jdbcType="VARCHAR" property="msg" /> | <result column="msg" jdbcType="VARCHAR" property="msg" /> | ||||
<result column="signature" jdbcType="VARCHAR" property="signature" /> | <result column="signature" jdbcType="VARCHAR" property="signature" /> | ||||
<result column="code" jdbcType="VARCHAR" property="code" /> | <result column="code" jdbcType="VARCHAR" property="code" /> | ||||
<result column="project_type" jdbcType="INTEGER" property="projectType" /> | |||||
</resultMap> | </resultMap> | ||||
<sql id="allColumns"> | <sql id="allColumns"> | ||||
`id`,`tenant_id`,`parent_tenant_id`,`phone`,`expiretime`,`createtime`,`type`,`msg`,`signature`,`code` | |||||
`id`,`tenant_id`,`parent_tenant_id`,`phone`,`expiretime`,`createtime`,`type`,`msg`,`signature`,`code`,`project_type` | |||||
</sql> | </sql> | ||||
<sql id="dynamicWhereConditions"> | <sql id="dynamicWhereConditions"> | ||||
@@ -35,6 +36,7 @@ | |||||
<if test=" null != signature ">and `signature` = #{signature}</if> | <if test=" null != signature ">and `signature` = #{signature}</if> | ||||
<if test=" null != code ">and `code` = #{code}</if> | <if test=" null != code ">and `code` = #{code}</if> | ||||
<if test=" null != createtimeStr ">and date_format(`createtime`,'%Y-%m-%d') = #{createtimeStr}</if> | <if test=" null != createtimeStr ">and date_format(`createtime`,'%Y-%m-%d') = #{createtimeStr}</if> | ||||
<if test=" null != projectType "> and `project_type` = #{projectType} </if> | |||||
<if test=" null != ids "> | <if test=" null != ids "> | ||||
and id in | and id in | ||||
<foreach collection="ids" index="index" item="idItem" open="(" separator="," close=")"> | <foreach collection="ids" index="index" item="idItem" open="(" separator="," close=")"> | ||||