// public functions @Override @Transactional public CommandProcessingResult createPublicUser(final JsonCommand command) { try { this.userDataValidator.validateCreate(command.getJsonCommand()); User user = User.fromJson(command, false, true); generateKeyUsedForPasswordSalting(user); final String encodePassword = this.applicationPasswordEncoder.encode(user); user.updatePassword(encodePassword); this.userRepository.save(user); final JsonElement element = this.fromJsonHelper.parse(command.getJsonCommand()); final String returnUrl = this.fromJsonHelper.extractStringNamed(ReturnUrlParamName, element); final String email = user.getUsername(); final SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); final String nowDate = sf.format(DateTime.now().toDate()); final String text = nowDate + email + nowDate + Math.random(); final String otp = new String(Base64.encode(text.getBytes())); final UserOtp userOtp = UserOtp.createOtp(user, email, otp.substring(3, otp.length() - 5), returnUrl); this.userOtpRepository.save(userOtp); final String finalOtp = userOtp.getOtp(); final String verificationLink = DefaultAppUrl + "userapi/activate" + "?e=" + email + "&uas=" + finalOtp; String toEmails[] = new String[] {email}; this.emailSenderService.sendEmail( toEmails, null, null, EmailTemplates.activateUserEmailSubject(), EmailTemplates.activateUserEmailTemplate(user.getName(), verificationLink)); return new CommandProcessingResultBuilder().withSuccessStatus().build(); } catch (DataIntegrityViolationException ex) { ex.printStackTrace(); final Throwable realCause = ex.getCause(); if (realCause.getMessage().toLowerCase().contains("email")) { throw new PlatformDataIntegrityException( "error.msg.email.already.exist", "The email provided already exitst in the system." + realCause.getMessage()); } throw new PlatformDataIntegrityException( "error.msg.unknown.data.integrity.issue", "Unknown data integrity issue with resource: " + realCause.getMessage()); } }
@Override @Transactional public CommandProcessingResult create(final JsonCommand command) { this.userDataValidator.validateCreate(command.getJsonCommand()); User user = User.fromJson(command, true, false); generateKeyUsedForPasswordSalting(user); final String encodePassword = this.applicationPasswordEncoder.encode(user); user.updatePassword(encodePassword); this.userRepository.saveAndFlush(user); return new CommandProcessingResultBuilder().withResourceIdAsString(user.getId()).build(); }