Search in sources :

Example 1 with DtUser

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());
}
Also used : DtUser(com.dtstack.taier.develop.dto.user.DtUser) User(com.dtstack.taier.dao.domain.User) RdosDefineException(com.dtstack.taier.common.exception.RdosDefineException) DtUser(com.dtstack.taier.develop.dto.user.DtUser) PostMapping(org.springframework.web.bind.annotation.PostMapping)

Example 2 with DtUser

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());
}
Also used : DtUser(com.dtstack.taier.develop.dto.user.DtUser) User(com.dtstack.taier.dao.domain.User) Tenant(com.dtstack.taier.dao.domain.Tenant) RdosDefineException(com.dtstack.taier.common.exception.RdosDefineException) DTToken(com.dtstack.taier.develop.dto.user.DTToken) DtUser(com.dtstack.taier.develop.dto.user.DtUser) PostMapping(org.springframework.web.bind.annotation.PostMapping)

Aggregations

RdosDefineException (com.dtstack.taier.common.exception.RdosDefineException)2 User (com.dtstack.taier.dao.domain.User)2 DtUser (com.dtstack.taier.develop.dto.user.DtUser)2 PostMapping (org.springframework.web.bind.annotation.PostMapping)2 Tenant (com.dtstack.taier.dao.domain.Tenant)1 DTToken (com.dtstack.taier.develop.dto.user.DTToken)1