use of org.thingsboard.server.common.data.User in project thingsboard by thingsboard.
the class UserController method getActivationLink.
@PreAuthorize("hasAnyAuthority('SYS_ADMIN', 'TENANT_ADMIN')")
@RequestMapping(value = "/user/{userId}/activationLink", method = RequestMethod.GET, produces = "text/plain")
@ResponseBody
public String getActivationLink(@PathVariable(USER_ID) String strUserId, HttpServletRequest request) throws ThingsboardException {
checkParameter(USER_ID, strUserId);
try {
UserId userId = new UserId(toUUID(strUserId));
SecurityUser authUser = getCurrentUser();
if (authUser.getAuthority() == Authority.CUSTOMER_USER && !authUser.getId().equals(userId)) {
throw new ThingsboardException(YOU_DON_T_HAVE_PERMISSION_TO_PERFORM_THIS_OPERATION, ThingsboardErrorCode.PERMISSION_DENIED);
}
User user = checkUserId(userId);
UserCredentials userCredentials = userService.findUserCredentialsByUserId(user.getId());
if (!userCredentials.isEnabled()) {
String baseUrl = constructBaseUrl(request);
String activateUrl = String.format(ACTIVATE_URL_PATTERN, baseUrl, userCredentials.getActivateToken());
return activateUrl;
} else {
throw new ThingsboardException("User is already active!", ThingsboardErrorCode.BAD_REQUEST_PARAMS);
}
} catch (Exception e) {
throw handleException(e);
}
}
use of org.thingsboard.server.common.data.User in project thingsboard by thingsboard.
the class UserServiceImpl method saveUser.
@Override
public User saveUser(User user) {
log.trace("Executing saveUser [{}]", user);
userValidator.validate(user);
User savedUser = userDao.save(user);
if (user.getId() == null) {
UserCredentials userCredentials = new UserCredentials();
userCredentials.setEnabled(false);
userCredentials.setActivateToken(RandomStringUtils.randomAlphanumeric(DEFAULT_TOKEN_LENGTH));
userCredentials.setUserId(new UserId(savedUser.getUuidId()));
userCredentialsDao.save(userCredentials);
}
return savedUser;
}
use of org.thingsboard.server.common.data.User in project thingsboard by thingsboard.
the class UserEntity method toData.
@Override
public User toData() {
User user = new User(new UserId(id));
user.setCreatedTime(UUIDs.unixTimestamp(id));
user.setAuthority(authority);
if (tenantId != null) {
user.setTenantId(new TenantId(tenantId));
}
if (customerId != null) {
user.setCustomerId(new CustomerId(customerId));
}
user.setEmail(email);
user.setFirstName(firstName);
user.setLastName(lastName);
user.setAdditionalInfo(additionalInfo);
return user;
}
use of org.thingsboard.server.common.data.User in project thingsboard by thingsboard.
the class UserEntity method toData.
@Override
public User toData() {
User user = new User(new UserId(getId()));
user.setCreatedTime(UUIDs.unixTimestamp(getId()));
user.setAuthority(authority);
if (tenantId != null) {
user.setTenantId(new TenantId(fromString(tenantId)));
}
if (customerId != null) {
user.setCustomerId(new CustomerId(fromString(customerId)));
}
user.setEmail(email);
user.setFirstName(firstName);
user.setLastName(lastName);
user.setAdditionalInfo(additionalInfo);
return user;
}
use of org.thingsboard.server.common.data.User in project thingsboard by thingsboard.
the class BaseUserServiceTest method testFindUserCredentials.
@Test
public void testFindUserCredentials() {
User user = userService.findUserByEmail("sysadmin@thingsboard.org");
Assert.assertNotNull(user);
UserCredentials userCredentials = userService.findUserCredentialsByUserId(user.getId());
Assert.assertNotNull(userCredentials);
}
Aggregations