Merge pull request #4179 from AndrewVolosytnykhThingsboard/activation-link-fix-new
Activation link fix
This commit is contained in:
commit
16c55b4dda
@ -215,6 +215,7 @@ public class AuthController extends BaseController {
|
||||
User user = userService.findUserById(TenantId.SYS_TENANT_ID, credentials.getUserId());
|
||||
UserPrincipal principal = new UserPrincipal(UserPrincipal.Type.USER_NAME, user.getEmail());
|
||||
SecurityUser securityUser = new SecurityUser(user, credentials.isEnabled(), principal);
|
||||
userService.setUserCredentialsEnabled(user.getTenantId(), user.getId(), true);
|
||||
String baseUrl = systemSecurityService.getBaseUrl(user.getTenantId(), user.getCustomerId(), request);
|
||||
String loginUrl = String.format("%s/login", baseUrl);
|
||||
String email = user.getEmail();
|
||||
|
||||
@ -94,12 +94,24 @@ public class UserController extends BaseController {
|
||||
processDashboardIdFromAdditionalInfo((ObjectNode) user.getAdditionalInfo(), DEFAULT_DASHBOARD);
|
||||
processDashboardIdFromAdditionalInfo((ObjectNode) user.getAdditionalInfo(), HOME_DASHBOARD);
|
||||
}
|
||||
UserCredentials userCredentials = userService.findUserCredentialsByUserId(user.getTenantId(), user.getId());
|
||||
if(userCredentials.isEnabled()) {
|
||||
addUserCredentialsEnabled((ObjectNode) user.getAdditionalInfo());
|
||||
}
|
||||
return user;
|
||||
} catch (Exception e) {
|
||||
throw handleException(e);
|
||||
}
|
||||
}
|
||||
|
||||
private void addUserCredentialsEnabled(ObjectNode additionalInfo) {
|
||||
if(!additionalInfo.isNull()) {
|
||||
if(!additionalInfo.has("userCredentialsEnabled")) {
|
||||
additionalInfo.put("userCredentialsEnabled", true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAnyAuthority('SYS_ADMIN', 'TENANT_ADMIN')")
|
||||
@RequestMapping(value = "/user/tokenAccessEnabled", method = RequestMethod.GET)
|
||||
@ResponseBody
|
||||
@ -193,13 +205,13 @@ public class UserController extends BaseController {
|
||||
user.getId(), user);
|
||||
|
||||
UserCredentials userCredentials = userService.findUserCredentialsByUserId(getCurrentUser().getTenantId(), user.getId());
|
||||
if (!userCredentials.isEnabled()) {
|
||||
if (!userCredentials.isEnabled() && userCredentials.getActivateToken() != null) {
|
||||
String baseUrl = systemSecurityService.getBaseUrl(getTenantId(), getCurrentUser().getCustomerId(), request);
|
||||
String activateUrl = String.format(ACTIVATE_URL_PATTERN, baseUrl,
|
||||
userCredentials.getActivateToken());
|
||||
mailService.sendActivationEmail(activateUrl, email);
|
||||
} else {
|
||||
throw new ThingsboardException("User is already active!", ThingsboardErrorCode.BAD_REQUEST_PARAMS);
|
||||
throw new ThingsboardException("User is already activated!", ThingsboardErrorCode.BAD_REQUEST_PARAMS);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
throw handleException(e);
|
||||
@ -218,13 +230,13 @@ public class UserController extends BaseController {
|
||||
User user = checkUserId(userId, Operation.READ);
|
||||
SecurityUser authUser = getCurrentUser();
|
||||
UserCredentials userCredentials = userService.findUserCredentialsByUserId(authUser.getTenantId(), user.getId());
|
||||
if (!userCredentials.isEnabled()) {
|
||||
if (!userCredentials.isEnabled() && userCredentials.getActivateToken() != null) {
|
||||
String baseUrl = systemSecurityService.getBaseUrl(getTenantId(), getCurrentUser().getCustomerId(), 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);
|
||||
throw new ThingsboardException("User is already activated!", ThingsboardErrorCode.BAD_REQUEST_PARAMS);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
throw handleException(e);
|
||||
|
||||
@ -19,13 +19,13 @@
|
||||
<button mat-raised-button color="primary"
|
||||
[disabled]="(isLoading$ | async)"
|
||||
(click)="onEntityAction($event, 'disableAccount')"
|
||||
[fxShow]="!isEdit && isUserCredentialsEnabled()">
|
||||
[fxShow]="!isEdit && isUserCredentialPresent() && isUserCredentialsEnabled()">
|
||||
{{'user.disable-account' | translate }}
|
||||
</button>
|
||||
<button mat-raised-button color="primary"
|
||||
[disabled]="(isLoading$ | async)"
|
||||
(click)="onEntityAction($event, 'enableAccount')"
|
||||
[fxShow]="!isEdit && !isUserCredentialsEnabled()">
|
||||
[fxShow]="!isEdit && isUserCredentialPresent() && !isUserCredentialsEnabled()">
|
||||
{{'user.enable-account' | translate }}
|
||||
</button>
|
||||
<button mat-raised-button color="primary"
|
||||
|
||||
@ -56,11 +56,11 @@ export class UserComponent extends EntityComponent<User> {
|
||||
}
|
||||
|
||||
isUserCredentialsEnabled(): boolean {
|
||||
if (!this.entity || !this.entity.additionalInfo || isUndefined(this.entity.additionalInfo.userCredentialsEnabled)) {
|
||||
return true;
|
||||
} else {
|
||||
return this.entity.additionalInfo.userCredentialsEnabled === true;
|
||||
}
|
||||
}
|
||||
|
||||
isUserCredentialPresent(): boolean {
|
||||
return this.entity && this.entity.additionalInfo && isDefinedAndNotNull(this.entity.additionalInfo.userCredentialsEnabled);
|
||||
}
|
||||
|
||||
buildForm(entity: User): FormGroup {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user