use of com.dtstack.taier.develop.dto.user.DtUser in project Taier by DTStack.
the class UserController method login.
@PostMapping(value = "/login")
public R<String> login(@RequestParam(value = "username") String userName, @RequestParam(value = "password") String password, HttpServletRequest request, HttpServletResponse response) {
if (StringUtils.isBlank(userName)) {
throw new RdosDefineException("userName can not null");
}
if (StringUtils.isBlank(password)) {
throw new RdosDefineException("password can not null");
}
User user = userService.getByUserName(userName.trim());
if (null == user) {
throw new RdosDefineException(ErrorCode.USER_IS_NULL);
}
String md5Password = MD5Util.getMd5String(password);
if (!md5Password.equalsIgnoreCase(user.getPassword())) {
throw new RdosDefineException("password not correct");
}
DtUser dtUser = new DtUser();
dtUser.setUserId(user.getId());
dtUser.setUserName(user.getUserName());
dtUser.setEmail(user.getEmail());
dtUser.setPhone(user.getPhoneNumber());
loginService.onAuthenticationSuccess(request, response, dtUser);
return R.ok(dtUser.getUserName());
}
use of com.dtstack.taier.develop.dto.user.DtUser in project Taier by DTStack.
the class UserController method switchTenant.
@PostMapping(value = "/switchTenant")
public R<String> switchTenant(@RequestParam(value = "tenantId") Long tenantId, HttpServletRequest request, HttpServletResponse response) {
String token = cookieService.token(request);
if (StringUtils.isBlank(token)) {
throw new RdosDefineException(ErrorCode.TOKEN_IS_NULL);
}
DTToken decryption = tokenService.decryption(token);
Long userId = decryption.getUserId();
User user = userService.getById(userId);
if (null == user) {
throw new RdosDefineException(ErrorCode.USER_IS_NULL);
}
Tenant tenant = tenantService.getTenantById(tenantId);
if (null == tenant) {
throw new RdosDefineException(ErrorCode.TENANT_IS_NULL);
}
DtUser dtUser = new DtUser();
dtUser.setUserId(user.getId());
dtUser.setUserName(user.getUserName());
dtUser.setEmail(user.getEmail());
dtUser.setPhone(user.getPhoneNumber());
dtUser.setTenantId(tenantId);
dtUser.setTenantName(tenant.getTenantName());
loginService.onAuthenticationSuccess(request, response, dtUser);
return R.ok(user.getUserName());
}
Aggregations