use of com.paascloud.provider.model.domain.UacUser in project paascloud-master by paascloud.
the class UacUserTokenServiceImpl method saveUserToken.
@Override
public void saveUserToken(String accessToken, String refreshToken, LoginAuthDto loginAuthDto, HttpServletRequest request) {
// 获取登录时间
Long userId = loginAuthDto.getUserId();
UacUser uacUser = uacUserService.selectByKey(userId);
final UserAgent userAgent = UserAgent.parseUserAgentString(request.getHeader("User-Agent"));
// 获取客户端操作系统
final String os = userAgent.getOperatingSystem().getName();
// 获取客户端浏览器
final String browser = userAgent.getBrowser().getName();
final String remoteAddr = RequestUtil.getRemoteAddr(request);
// 根据IP获取位置信息
final String remoteLocation = opcRpcService.getLocationById(remoteAddr);
// 存入mysql数据库
UacUserToken uacUserToken = new UacUserToken();
OAuth2ClientProperties[] clients = securityProperties.getOauth2().getClients();
int accessTokenValidateSeconds = clients[0].getAccessTokenValidateSeconds();
int refreshTokenValiditySeconds = clients[0].getRefreshTokenValiditySeconds();
uacUserToken.setOs(os);
uacUserToken.setBrowser(browser);
uacUserToken.setAccessToken(accessToken);
uacUserToken.setAccessTokenValidity(accessTokenValidateSeconds);
uacUserToken.setLoginIp(remoteAddr);
uacUserToken.setLoginLocation(remoteLocation);
uacUserToken.setLoginTime(uacUser.getLastLoginTime());
uacUserToken.setLoginName(loginAuthDto.getLoginName());
uacUserToken.setRefreshToken(refreshToken);
uacUserToken.setRefreshTokenValidity(refreshTokenValiditySeconds);
uacUserToken.setStatus(UacUserTokenStatusEnum.ON_LINE.getStatus());
uacUserToken.setUserId(userId);
uacUserToken.setUserName(loginAuthDto.getUserName());
uacUserToken.setUpdateInfo(loginAuthDto);
uacUserToken.setGroupId(loginAuthDto.getGroupId());
uacUserToken.setGroupName(loginAuthDto.getGroupName());
uacUserToken.setId(generateId());
uacUserTokenMapper.insertSelective(uacUserToken);
UserTokenDto userTokenDto = new ModelMapper().map(uacUserToken, UserTokenDto.class);
// 存入redis数据库
updateRedisUserToken(accessToken, accessTokenValidateSeconds, userTokenDto);
}
use of com.paascloud.provider.model.domain.UacUser in project paascloud-master by paascloud.
the class UacUserTokenServiceImpl method refreshToken.
@Override
public String refreshToken(String accessToken, String refreshToken, HttpServletRequest request) throws HttpProcessException {
String token;
Map<String, Object> map = new HashMap<>(2);
map.put("grant_type", "refresh_token");
map.put("refresh_token", refreshToken);
// 插件式配置请求参数(网址、请求参数、编码、client)
Header[] headers = HttpHeader.custom().contentType(HttpHeader.Headers.APP_FORM_URLENCODED).authorization(request.getHeader(HttpHeaders.AUTHORIZATION)).build();
HttpConfig config = HttpConfig.custom().headers(headers).url(refreshTokenUrl).map(map);
token = HttpClientUtil.post(config);
JSONObject jsonObj = JSON.parseObject(token);
String accessTokenNew = (String) jsonObj.get("access_token");
String refreshTokenNew = (String) jsonObj.get("refresh_token");
String loginName = (String) jsonObj.get("loginName");
// 更新本次token数据
UserTokenDto tokenDto = this.getByAccessToken(accessToken);
tokenDto.setStatus(UacUserTokenStatusEnum.ON_REFRESH.getStatus());
UacUser uacUser = uacUserService.findUserInfoByLoginName(loginName);
LoginAuthDto loginAuthDto = new LoginAuthDto(uacUser.getId(), uacUser.getLoginName(), uacUser.getUserName(), uacUser.getGroupId(), uacUser.getGroupName());
this.updateUacUserToken(tokenDto, loginAuthDto);
// 创建刷新token
this.saveUserToken(accessTokenNew, refreshTokenNew, loginAuthDto, request);
return token;
}
use of com.paascloud.provider.model.domain.UacUser in project paascloud-master by paascloud.
the class AuthRestController method checkEmailActive.
/**
* 校验邮箱.
*
* @param email the email
*
* @return the wrapper
*/
@PostMapping(value = "/checkEmailActive/{email:.+}")
@ApiOperation(httpMethod = "POST", value = "校验邮箱")
public Wrapper<Boolean> checkEmailActive(@PathVariable("email") String email) {
UacUser uacUser = new UacUser();
uacUser.setStatus(UacUserStatusEnum.ENABLE.getKey());
uacUser.setEmail(email);
int count = uacUserService.selectCount(uacUser);
return WrapMapper.ok(count > 0);
}
use of com.paascloud.provider.model.domain.UacUser in project paascloud-master by paascloud.
the class AuthRestController method checkPhoneActive.
/**
* 校验手机号码.
*
* @param mobileNo the mobile no
*
* @return the wrapper
*/
@PostMapping(value = "/checkPhoneActive/{mobileNo}")
@ApiOperation(httpMethod = "POST", value = "校验手机号码")
public Wrapper<Boolean> checkPhoneActive(@PathVariable String mobileNo) {
UacUser uacUser = new UacUser();
uacUser.setStatus(UacUserStatusEnum.ENABLE.getKey());
uacUser.setMobileNo(mobileNo);
int count = uacUserService.selectCount(uacUser);
return WrapMapper.ok(count > 0);
}
use of com.paascloud.provider.model.domain.UacUser in project paascloud-master by paascloud.
the class UacUserCommonController method queryUserInfo.
/**
* 根据userId查询用户详细信息(连表查询).
*
* @return the wrapper
*/
@PostMapping(value = "/queryUserInfo/{loginName}")
@ApiOperation(httpMethod = "POST", value = "根据userId查询用户详细信息")
public Wrapper<UserVo> queryUserInfo(@PathVariable String loginName) {
logger.info("根据userId查询用户详细信息");
UserVo userVo = new UserVo();
UacUser uacUser = uacUserService.findByLoginName(loginName);
uacUser = uacUserService.findUserInfoByUserId(uacUser.getId());
List<UacRole> roleList = uacRoleService.findAllRoleInfoByUserId(uacUser.getId());
List<MenuVo> authTree = uacRoleService.getOwnAuthTree(uacUser.getId());
BeanUtils.copyProperties(uacUser, userVo);
if (PublicUtil.isNotEmpty(roleList)) {
userVo.setRoles(new HashSet<>(roleList));
}
userVo.setAuthTree(authTree);
return WrapMapper.ok(userVo);
}
Aggregations