|
|
|
@@ -189,20 +189,28 @@ public class HomeController extends BaseController { |
|
|
|
return data; |
|
|
|
} |
|
|
|
|
|
|
|
@GetMapping("sendLoginCode") |
|
|
|
@GetMapping("sendLoginPhoneCode") |
|
|
|
@ApiImplicitParams({ |
|
|
|
@ApiImplicitParam(name = "phone", value = "手机号", dataType = "String", paramType = "query", required = true), |
|
|
|
@ApiImplicitParam(name = "type", value = "场景(1:登录)", dataType = "Integer", paramType = "query", required = true)}) |
|
|
|
public ResultData sendlogincode(String phone, Integer type) { |
|
|
|
logger.debug("[" + getIpAddr() + "] HomeController::sendlogincode"); |
|
|
|
// 1. 检查手机号是否在用户列表里 |
|
|
|
// 2. 发送手机验证码 |
|
|
|
// 2.1 如果只找到一个手机号 直接发 |
|
|
|
// 2.2 如果找到多个,用富茂的发 |
|
|
|
// 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); |
|
|
|
WxMsgValidationcode wxMsgValidationcode = new WxMsgValidationcode(); |
|
|
|
wxMsgValidationcode.setPhone(phone); |
|
|
|
wxMsgValidationcode.setTenantId(user.getTenantId()); |
|
|
|
wxMsgValidationcode.setType(type); |
|
|
|
// TODO 登录时不知道哪个tenantId |
|
|
|
return wxMsgValidationcodeService.sendvalidationcode(wxMsgValidationcode); |
|
|
|
} |
|
|
|
|
|
|
|
@@ -221,103 +229,46 @@ public class HomeController extends BaseController { |
|
|
|
return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), "验证码不能为空"); |
|
|
|
} |
|
|
|
|
|
|
|
// check 验证码正确 |
|
|
|
// TODO |
|
|
|
// try { |
|
|
|
// return userInfoService.updatepwd(user, code); |
|
|
|
// } catch (Exception e) { |
|
|
|
// return new ResultData(Result.ERROR, e.getMessage()); |
|
|
|
// } |
|
|
|
|
|
|
|
// 获取用户信息列表 |
|
|
|
List<MallUserInfoVo> userList = mallUserInfoService.getUserByPhone(phone); |
|
|
|
if(userList.size() == 1) { |
|
|
|
// 唯一用户,直接登录即可 |
|
|
|
MallUserInfoVo user = userList.get(0); |
|
|
|
// check 验证码正确 |
|
|
|
try { |
|
|
|
Subject subject = SecurityUtils.getSubject(); |
|
|
|
UseriFormallToken token = new UseriFormallToken(user.getUsername()); |
|
|
|
subject.login(token); |
|
|
|
MallUserInfo info = (MallUserInfo) SecurityUtils.getSubject().getSession().getAttribute(UserSession.userInfo); |
|
|
|
info.setPassword("保密"); |
|
|
|
if(StringUtils.isNotBlank(info.getBopenId())) |
|
|
|
info.setBopenId("保密"); |
|
|
|
if(StringUtils.isNotBlank(info.getWebOpenId())) { |
|
|
|
info.setWebOpenId("保密"); |
|
|
|
info.setWithWechat(true); |
|
|
|
boolean isValidCode = mallUserInfoService.checkCodeValid(user, code); |
|
|
|
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.setPassword("保密"); |
|
|
|
if(StringUtils.isNotBlank(info.getBopenId())) |
|
|
|
info.setBopenId("保密"); |
|
|
|
if(StringUtils.isNotBlank(info.getWebOpenId())) { |
|
|
|
info.setWebOpenId("保密"); |
|
|
|
info.setWithWechat(true); |
|
|
|
} else { |
|
|
|
info.setWithWechat(false); |
|
|
|
} |
|
|
|
String menus = mallUserRoleService.getPermissionsByUser(info); |
|
|
|
if(menus != null) { |
|
|
|
info.setMenus(menus); |
|
|
|
} |
|
|
|
return new ResultData(info); |
|
|
|
} catch (Exception e) { |
|
|
|
return new ResultData(ResultData.ERROR, "用户名或者密码错误"); |
|
|
|
} |
|
|
|
} else { |
|
|
|
info.setWithWechat(false); |
|
|
|
} |
|
|
|
String menus = mallUserRoleService.getPermissionsByUser(info); |
|
|
|
if(menus != null) { |
|
|
|
info.setMenus(menus); |
|
|
|
return new ResultData(ErrorCode.MSG_VERIFY_CODE_NOT_FOUND); |
|
|
|
} |
|
|
|
return new ResultData(info); |
|
|
|
} catch (Exception e) { |
|
|
|
return new ResultData(ResultData.ERROR, "用户名或者密码错误"); |
|
|
|
return new ResultData(Result.ERROR, e.getMessage()); |
|
|
|
} |
|
|
|
} else { |
|
|
|
// TODO 多个租户,前端界面做选择 |
|
|
|
return new ResultData(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
@ApiOperation(value = "手机验证码租户登录", notes = "{\"tenantId\",\"string\", \"phone\",\"string\",\"code\",\"string\"}") |
|
|
|
@PostMapping("/doLoginByTenantPhone") |
|
|
|
public ResultData doLoginByTenantPhone(@RequestBody Map<String, String> params) { |
|
|
|
logger.debug("[" + getIpAddr() + "] HomeController::doLoginByTenantPhone"); |
|
|
|
String tenantId = params.get("tenantId"); |
|
|
|
String phone = params.get("phone"); |
|
|
|
String code = params.get("code"); |
|
|
|
|
|
|
|
if (StringUtils.isBlank(tenantId)) { |
|
|
|
return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), "tenantId不能为空"); |
|
|
|
} |
|
|
|
if (StringUtils.isBlank(phone)) { |
|
|
|
return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), "phone不能为空"); |
|
|
|
} |
|
|
|
if (StringUtils.isBlank(code)) { |
|
|
|
return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), "验证码不能为空"); |
|
|
|
} |
|
|
|
|
|
|
|
MallUserInfo user = mallUserInfoService.getByPhone(phone, tenantId); |
|
|
|
if(user == null) { |
|
|
|
return new ResultData(ErrorCode.USER_IS_EMPTY); |
|
|
|
} |
|
|
|
|
|
|
|
// check 验证码正确 |
|
|
|
ResultData r = null; |
|
|
|
try { |
|
|
|
r = mallUserInfoService.checkCodeValid(user, code); |
|
|
|
if(r.code != Result.SUCCESS) { |
|
|
|
return r; |
|
|
|
} |
|
|
|
} catch (Exception e) { |
|
|
|
return new ResultData(Result.ERROR, e.getMessage()); |
|
|
|
} |
|
|
|
|
|
|
|
try { |
|
|
|
Subject subject = SecurityUtils.getSubject(); |
|
|
|
UseriFormallToken token = new UseriFormallToken(user.getUsername()); |
|
|
|
subject.login(token); |
|
|
|
MallUserInfo info = (MallUserInfo) SecurityUtils.getSubject().getSession().getAttribute(UserSession.userInfo); |
|
|
|
info.setPassword("保密"); |
|
|
|
if(StringUtils.isNotBlank(info.getBopenId())) |
|
|
|
info.setBopenId("保密"); |
|
|
|
if(StringUtils.isNotBlank(info.getWebOpenId())) { |
|
|
|
info.setWebOpenId("保密"); |
|
|
|
info.setWithWechat(true); |
|
|
|
} else { |
|
|
|
info.setWithWechat(false); |
|
|
|
} |
|
|
|
String menus = mallUserRoleService.getPermissionsByUser(info); |
|
|
|
if(menus != null) { |
|
|
|
info.setMenus(menus); |
|
|
|
} |
|
|
|
return new ResultData(info); |
|
|
|
} catch (Exception e) { |
|
|
|
return new ResultData(ResultData.ERROR, "用户名或者密码错误"); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
@ApiOperation("登出") |
|
|
|
|