From d53f56c96b2323c396c9c85b3b93574a42ed4b9a Mon Sep 17 00:00:00 2001
From: "tcdlpds@gmail.com"
Date: Tue, 18 Aug 2020 08:09:39 +0530
Subject: [PATCH 1/2] Complete self registration via OTP service
---
.../mgt/common/spi/OTPManagementService.java | 11 +-
.../mgt/service/OTPManagementServiceImpl.java | 22 +++-
.../resources/email/templates/user-verify.vm | 2 +-
.../resources/email/templates/user-welcome.vm | 101 ++++++++++++++++++
4 files changed, 131 insertions(+), 5 deletions(-)
create mode 100644 features/email-sender/org.wso2.carbon.email.sender.feature/src/main/resources/email/templates/user-welcome.vm
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/spi/OTPManagementService.java b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/spi/OTPManagementService.java
index 8ecb4de4fd6..f63a95ca324 100644
--- a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/spi/OTPManagementService.java
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/spi/OTPManagementService.java
@@ -24,6 +24,8 @@ import org.wso2.carbon.device.mgt.common.invitation.mgt.DeviceEnrollmentInvitati
import org.wso2.carbon.device.mgt.common.otp.mgt.dto.OneTimePinDTO;
import org.wso2.carbon.device.mgt.common.otp.mgt.wrapper.OTPWrapper;
+import java.util.Map;
+
public interface OTPManagementService {
/**
@@ -44,11 +46,14 @@ public interface OTPManagementService {
OneTimePinDTO isValidOTP(String oneTimeToken) throws OTPManagementException, BadRequestException;
/**
- * Invalidate the OTP
+ * Invalidate the OTP and send welcome mail
* @param oneTimeToken OTP
- * @throws OTPManagementException If error occurred while invalidating the OTP
+ * @param email email address
+ * @param properties email properties to add to email body
+ * @throws OTPManagementException if error occurred while invalidate the OTP or send welcome email
*/
- void invalidateOTP(String oneTimeToken) throws OTPManagementException;
+ void completeSelfRegistration(String oneTimeToken, String email, Map properties)
+ throws OTPManagementException;
/**
* Create OTP token and send device enrollment invitation
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/otp/mgt/service/OTPManagementServiceImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/otp/mgt/service/OTPManagementServiceImpl.java
index ee7db06f152..111f9e35917 100644
--- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/otp/mgt/service/OTPManagementServiceImpl.java
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/otp/mgt/service/OTPManagementServiceImpl.java
@@ -58,6 +58,7 @@ import static org.wso2.carbon.device.mgt.common.DeviceManagementConstants.OTPPro
import java.sql.Timestamp;
import java.util.Calendar;
import java.util.List;
+import java.util.Map;
import java.util.Properties;
import java.util.UUID;
@@ -150,7 +151,26 @@ public class OTPManagementServiceImpl implements OTPManagementService {
}
@Override
- public void invalidateOTP(String oneTimeToken) throws OTPManagementException {
+ public void completeSelfRegistration(String oneTimeToken, String email, Map properties)
+ throws OTPManagementException {
+ try {
+ invalidateOTP(oneTimeToken);
+ Properties props = new Properties();
+ properties.forEach(props::setProperty);
+ sendMail(props, email);
+ } catch (OTPManagementException e) {
+ String msg = "Error occurred while completing the self registration via OTP";
+ log.error(msg, e);
+ throw new OTPManagementException(msg, e);
+ }
+ }
+
+ /**
+ * Invalidate the OTP
+ * @param oneTimeToken OTP
+ * @throws OTPManagementException If error occurred while invalidating the OTP
+ */
+ private void invalidateOTP(String oneTimeToken) throws OTPManagementException {
try {
ConnectionManagerUtil.beginDBTransaction();
if (!otpManagementDAO.expireOneTimeToken(oneTimeToken)) {
diff --git a/features/email-sender/org.wso2.carbon.email.sender.feature/src/main/resources/email/templates/user-verify.vm b/features/email-sender/org.wso2.carbon.email.sender.feature/src/main/resources/email/templates/user-verify.vm
index 18e3a66a015..858503fd8a4 100644
--- a/features/email-sender/org.wso2.carbon.email.sender.feature/src/main/resources/email/templates/user-verify.vm
+++ b/features/email-sender/org.wso2.carbon.email.sender.feature/src/main/resources/email/templates/user-verify.vm
@@ -16,7 +16,7 @@
under the License.
*#
- You have been invited to enroll your device in Entgra IoT
+ Verify email to register with Entgra IoTS
diff --git a/features/email-sender/org.wso2.carbon.email.sender.feature/src/main/resources/email/templates/user-welcome.vm b/features/email-sender/org.wso2.carbon.email.sender.feature/src/main/resources/email/templates/user-welcome.vm
new file mode 100644
index 00000000000..dfaab5c559a
--- /dev/null
+++ b/features/email-sender/org.wso2.carbon.email.sender.feature/src/main/resources/email/templates/user-welcome.vm
@@ -0,0 +1,101 @@
+#*
+ Copyright (c) 2020, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
+
+ Entgra (Pvt) Ltd. licenses this file to you under the Apache License,
+ Version 2.0 (the "License"); you may not use this file except
+ in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied. See the License for the
+ specific language governing permissions and limitations
+ under the License.
+*#
+
+ Welcome to Entgra Evaluation Cloud
+
+
+
+ Entgra IoT Server
+
+
+
+
+
+
+
+
+
+
+
+ Hi $first-name,
+
+
+
+ Welcome to Entgra Evaluation Cloud!! Entgra server support offers managing Android, iOS and Windows
+ devices along with a wide range of features that support cooperate (COPE) or personal device (BYOD)
+ enrollments.
+
+
+
+
Access different portals
+
+ Your log-in credentials to any of our portals(endpoint-mgt, store, publisher) are the same as the
+ email (username) and password you provided during the registration for an evaluation account.
+
+
+
+ This is the portal used to send operations and policies to devices and overall management of
+ the server.
+
+
+
+ This is an in-house corporate app store where you can host all your corporate applications.
+ Users may browse apps and install them to their devices if the administrator has made the apps
+ publicly visible to users. Administrator can install, uninstall and update apps in the user
+ device or device groups.
+
+
+
+ The portal for publishing new applications for internal use. This is the developer view of the
+ enterprise application store that comes with the product.
+
+
+
+
Enroll a device
+
+ Please find here a set of videos on how to enroll and onboard devices to our Cloud platform.
+ [Cloud Enrollment Guide]
+ When enrolling a device, Make sure to use the following log-in format:
+
+
+ Organisation: $tenant-domain
+ Username: $email-address
+ Password: password provided at registration.
+
+
+
+
+ If you have any further questions, please reach out to us using your registered mail to
+ bizdev-group@entgra.io. Looking forward to working with you.
+
+
+ Best Regards,
+
+
+ Entgra Cloud Team
+
+
+
+
+
+
+
+ ]]>
+
+
From b1845d9b42afd020679c7b3cc9845d7bb9bdbc50 Mon Sep 17 00:00:00 2001
From: "tcdlpds@gmail.com"
Date: Wed, 19 Aug 2020 08:24:55 +0530
Subject: [PATCH 2/2] Update user welcome mail body
---
.../mgt/core/DeviceManagementConstants.java | 1 +
.../mgt/service/OTPManagementServiceImpl.java | 2 +-
.../resources/email/templates/user-welcome.vm | 25 ++++++++-----------
3 files changed, 13 insertions(+), 15 deletions(-)
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/DeviceManagementConstants.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/DeviceManagementConstants.java
index afa9dfd767e..b09d6fad9de 100644
--- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/DeviceManagementConstants.java
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/DeviceManagementConstants.java
@@ -117,6 +117,7 @@ public final class DeviceManagementConstants {
public static final String USER_REGISTRATION_TEMPLATE = "user-registration";
public static final String USER_ENROLLMENT_TEMPLATE = "user-enrollment";
public static final String USER_VERIFY_TEMPLATE = "user-verify";
+ public static final String USER_WELCOME_TEMPLATE = "user-welcome";
public static final String DEFAULT_ENROLLMENT_TEMPLATE = "default-enrollment-invitation";
}
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/otp/mgt/service/OTPManagementServiceImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/otp/mgt/service/OTPManagementServiceImpl.java
index 111f9e35917..9b25987e84d 100644
--- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/otp/mgt/service/OTPManagementServiceImpl.java
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/otp/mgt/service/OTPManagementServiceImpl.java
@@ -157,7 +157,7 @@ public class OTPManagementServiceImpl implements OTPManagementService {
invalidateOTP(oneTimeToken);
Properties props = new Properties();
properties.forEach(props::setProperty);
- sendMail(props, email);
+ sendMail(props, email, DeviceManagementConstants.EmailAttributes.USER_WELCOME_TEMPLATE);
} catch (OTPManagementException e) {
String msg = "Error occurred while completing the self registration via OTP";
log.error(msg, e);
diff --git a/features/email-sender/org.wso2.carbon.email.sender.feature/src/main/resources/email/templates/user-welcome.vm b/features/email-sender/org.wso2.carbon.email.sender.feature/src/main/resources/email/templates/user-welcome.vm
index dfaab5c559a..5ce46119645 100644
--- a/features/email-sender/org.wso2.carbon.email.sender.feature/src/main/resources/email/templates/user-welcome.vm
+++ b/features/email-sender/org.wso2.carbon.email.sender.feature/src/main/resources/email/templates/user-welcome.vm
@@ -43,41 +43,38 @@
-
Access different portals
-
- Your log-in credentials to any of our portals(endpoint-mgt, store, publisher) are the same as the
- email (username) and password you provided during the registration for an evaluation account.
-
-
+
Access different portals
+
Your log-in credentials to any of our portals(endpoint-mgt, store, publisher) are,
+
Username: $portal-username
+
Password: password provided at registration for an evaluation account.
+
This is the portal used to send operations and policies to devices and overall management of
the server.
-
+
This is an in-house corporate app store where you can host all your corporate applications.
Users may browse apps and install them to their devices if the administrator has made the apps
publicly visible to users. Administrator can install, uninstall and update apps in the user
device or device groups.
-
+
The portal for publishing new applications for internal use. This is the developer view of the
enterprise application store that comes with the product.
-
Enroll a device
+
Enroll a device
Please find here a set of videos on how to enroll and onboard devices to our Cloud platform.
[Cloud Enrollment Guide]
When enrolling a device, Make sure to use the following log-in format:
-
- Organisation: $tenant-domain
- Username: $email-address
- Password: password provided at registration.
-
+
Organisation: $tenant-domain
+
Username: $agent-username
+
Password: password provided at registration.