Commit 3d53b9e4 authored by zengtianlai3's avatar zengtianlai3

校验用户名,由字母、数字或下划线组成。修复post请求的token鉴权失败重定向bug。

parent 5e54a651
...@@ -12,13 +12,9 @@ import iot.sixiang.license.model.BaseResult; ...@@ -12,13 +12,9 @@ import iot.sixiang.license.model.BaseResult;
import iot.sixiang.license.model.ResResult; import iot.sixiang.license.model.ResResult;
import iot.sixiang.license.model.vo.LoginVo; import iot.sixiang.license.model.vo.LoginVo;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import springfox.documentation.annotations.ApiIgnore; import springfox.documentation.annotations.ApiIgnore;
import javax.servlet.http.HttpServletRequest;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
...@@ -70,9 +66,11 @@ public class LoginController { ...@@ -70,9 +66,11 @@ public class LoginController {
return BaseResult.success(); return BaseResult.success();
} }
@GetMapping("fail") @RequestMapping(value = "fail", method = {RequestMethod.GET, RequestMethod.POST})
@ApiIgnore @ApiIgnore
public BaseResult fail(HttpServletRequest request) { public BaseResult fail() {
return BaseResult.unauthorized(); return BaseResult.unauthorized();
} }
} }
...@@ -9,6 +9,7 @@ import iot.sixiang.license.mapper.UserMapper; ...@@ -9,6 +9,7 @@ import iot.sixiang.license.mapper.UserMapper;
import iot.sixiang.license.model.PageInfoModel; import iot.sixiang.license.model.PageInfoModel;
import iot.sixiang.license.model.vo.UserVo; import iot.sixiang.license.model.vo.UserVo;
import iot.sixiang.license.service.UserService; import iot.sixiang.license.service.UserService;
import iot.sixiang.license.util.CommonUtil;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
...@@ -60,8 +61,8 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements Us ...@@ -60,8 +61,8 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements Us
@Override @Override
public boolean addUser(String userName, String company, String password) { public boolean addUser(String userName, String company, String password) {
if(StringUtils.isEmpty(userName) || StringUtils.isEmpty(company)) { if (StringUtils.isEmpty(userName) || StringUtils.isEmpty(company) || !CommonUtil.regularMessage(userName)) {
throw new IotLicenseException(ResultCode.VALIDATE_FAILED.getCode(),ResultCode.VALIDATE_FAILED.getMsg()); throw new IotLicenseException(ResultCode.VALIDATE_FAILED.getCode(), ResultCode.VALIDATE_FAILED.getMsg());
} }
User res = userMapper.getUserByUserName(userName); User res = userMapper.getUserByUserName(userName);
if (res != null) { if (res != null) {
......
...@@ -233,4 +233,10 @@ public class CommonUtil { ...@@ -233,4 +233,10 @@ public class CommonUtil {
return result; return result;
} }
public static boolean regularMessage(String message) {
String regex = "^[a-z0-9A-Z]+$";
regex = "^[0-9a-zA-Z_]{1,}$";
return message.matches(regex);
}
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment