| | |
| | | @PostMapping("/login") |
| | | @ApiOperation(value = "账号密码(用于前端登录)", notes = "通过账号/手机号/用户名密码登录,还要携带用户的类型,也就是用户所在的系统") |
| | | public Result login(@Valid UserLoginModel model, HttpServletResponse httpResponse) { |
| | | validateMainlandIpAccess(); |
| | | String mobileOrUserName = model.getUserName(); |
| | | User user = null; |
| | | if (model.getType() == 1) { |
| | |
| | | @PostMapping("/registerNoVerifcode") |
| | | @ApiOperation(value = "手机/邮箱/用户名注册(无验证码)") |
| | | public Result register(@Valid RegisterModel model) { |
| | | validateMainlandIpAccess(); |
| | | validateMainlandEmailRegister(model.getUserName(), model.getType()); |
| | | |
| | | String username = model.getUserName(); |
| | | String password = model.getPassword(); |
| | |
| | | @PostMapping("/registerVerifcode") |
| | | @ApiOperation(value = "手机(有验证码)") |
| | | public Result registerVerifcode(@Valid RegisterMobile model) { |
| | | validateMainlandIpAccess(); |
| | | validateMainlandEmailRegister(model.getUserName(), model.getType()); |
| | | |
| | | String username = model.getUserName(); |
| | | String password = model.getPassword(); |
| | |
| | | return resultObject; |
| | | } |
| | | |
| | | private void validateMainlandIpAccess() { |
| | | String clientIp = IPHelper.getIpAddr(); |
| | | List<RiskClient> riskList = RiskClientUtil.getRiskInfoByIp(clientIp, "badnetwork"); |
| | | if (CollectionUtil.isNotEmpty(riskList)) { |
| | | throw new YamiShopBindException("大陆IP禁止访问"); |
| | | } |
| | | } |
| | | |
| | | private void validateMainlandEmailRegister(String userName, Integer type) { |
| | | if (type == null || type != 2 || StringUtils.isEmptyString(userName)) { |
| | | return; |
| | | } |
| | | int atPos = userName.lastIndexOf("@"); |
| | | if (atPos <= 0 || atPos >= userName.length() - 1) { |
| | | return; |
| | | } |
| | | String domain = userName.substring(atPos + 1).trim().toLowerCase(); |
| | | if (domain.endsWith(".cn")) { |
| | | throw new YamiShopBindException("大陆邮箱不支持注册"); |
| | | } |
| | | Set<String> blockedDomains = new HashSet<>(Arrays.asList( |
| | | "qq.com", "foxmail.com", "163.com", "126.com", "yeah.net", |
| | | "sina.com", "sina.cn", "sohu.com", "aliyun.com", "21cn.com", |
| | | "189.cn", "tom.com" |
| | | )); |
| | | if (blockedDomains.contains(domain)) { |
| | | throw new YamiShopBindException("大陆邮箱不支持注册"); |
| | | } |
| | | } |
| | | |
| | | } |