Complete self registration via OTP service

revert-70ac1926
tcdlpds@gmail.com 4 years ago
parent 7f7fbf21b4
commit d53f56c96b

@ -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.dto.OneTimePinDTO;
import org.wso2.carbon.device.mgt.common.otp.mgt.wrapper.OTPWrapper; import org.wso2.carbon.device.mgt.common.otp.mgt.wrapper.OTPWrapper;
import java.util.Map;
public interface OTPManagementService { public interface OTPManagementService {
/** /**
@ -44,11 +46,14 @@ public interface OTPManagementService {
OneTimePinDTO isValidOTP(String oneTimeToken) throws OTPManagementException, BadRequestException; OneTimePinDTO isValidOTP(String oneTimeToken) throws OTPManagementException, BadRequestException;
/** /**
* Invalidate the OTP * Invalidate the OTP and send welcome mail
* @param oneTimeToken OTP * @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<String, String> properties)
throws OTPManagementException;
/** /**
* Create OTP token and send device enrollment invitation * Create OTP token and send device enrollment invitation

@ -58,6 +58,7 @@ import static org.wso2.carbon.device.mgt.common.DeviceManagementConstants.OTPPro
import java.sql.Timestamp; import java.sql.Timestamp;
import java.util.Calendar; import java.util.Calendar;
import java.util.List; import java.util.List;
import java.util.Map;
import java.util.Properties; import java.util.Properties;
import java.util.UUID; import java.util.UUID;
@ -150,7 +151,26 @@ public class OTPManagementServiceImpl implements OTPManagementService {
} }
@Override @Override
public void invalidateOTP(String oneTimeToken) throws OTPManagementException { public void completeSelfRegistration(String oneTimeToken, String email, Map<String, String> 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 { try {
ConnectionManagerUtil.beginDBTransaction(); ConnectionManagerUtil.beginDBTransaction();
if (!otpManagementDAO.expireOneTimeToken(oneTimeToken)) { if (!otpManagementDAO.expireOneTimeToken(oneTimeToken)) {

@ -16,7 +16,7 @@
under the License. under the License.
*# *#
<EmailConfig> <EmailConfig>
<Subject>You have been invited to enroll your device in Entgra IoT</Subject> <Subject>Verify email to register with Entgra IoTS</Subject>
<Body> <Body>
<![CDATA[ <![CDATA[
<html> <html>

@ -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.
*#
<EmailConfig>
<Subject>Welcome to Entgra Evaluation Cloud</Subject>
<Body>
<![CDATA[
<html>
<head>
<title>Entgra IoT Server</title>
</head>
<body style="color: #666666; background-color:#cdcdcd; padding: 0px; margin: 0px;">
<div style="background-color:#cdcdcd; font-length: 1em; font-family: Arial, Helvetica; line-height: 170%; color: #666666; padding: 20px 0px; margin: 0px;">
<div style="width: 86%; max-width: 650px; padding: 2%; background-color: #ffffff; margin: auto; border-radius: 14px;">
<div style="background-color: #ffebcc; line-height: 0px; border-top-left-radius: 10px; border-top-right-radius: 10px; padding: 10px;">
<div style="display: inline-block; line-height: 0px;">
<img alt="entgra" src="https://storage.googleapis.com/cdn-entgra/logo.png" height="50px" width="143px" />
</div>
</div>
<div style="background-color: #ffffff; line-height: 170%; color: #666666; padding: 20px 25px;">
<p style="font-length: 1em; font-family: Arial, Helvetica; line-height: 170%; color: #666666; margin: 5px 0px 20px;">
Hi $first-name,
</p>
<div>
<p style="font-length: 1em; font-family: Arial, Helvetica; line-height: 170%; color: #666666; margin: 20px 0px 5px;">
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.
</p>
</div>
<div>
<h2>Access different portals</h2>
<p style="font-size: 1em; font-family: Arial, Helvetica; line-height: 170%; color: #666666; margin: 5px 0px;">
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.
</p>
<h3>Endpoint management portal URL: <a href="$base-url-https/endpoint-mgt/">$base-url-https/endpoint-mgt/</a></h3>
<p style="font-length: 1em; font-family: Arial, Helvetica; line-height: 170%; color: #666666; margin: 20px 0px 5px;">
This is the portal used to send operations and policies to devices and overall management of
the server.
</p>
<h3>Application store portal URL: <a href="$base-url-https/store">$base-url-https/store</a></h3>
<p style="font-length: 1em; font-family: Arial, Helvetica; line-height: 170%; color: #666666; margin: 20px 0px 5px;">
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.
</p>
<h3>Application publishing portal URL: <a href="$base-url-https/publisher">$base-url-https/publisher</a></h3>
<p style="font-length: 1em; font-family: Arial, Helvetica; line-height: 170%; color: #666666; margin: 20px 0px 5px;">
The portal for publishing new applications for internal use. This is the developer view of the
enterprise application store that comes with the product.
</p>
</div>
<div>
<h2>Enroll a device</h2>
<p style="font-length: 1em; font-family: Arial, Helvetica; line-height: 170%; color: #666666; margin: 20px 0px 5px;">
Please find here a set of videos on how to enroll and onboard devices to our Cloud platform.
<a href="https://entgra-documentation.gitlab.io/v4.0.0/docs/product-guide/enrollment-guide/enroll-cloud/">[Cloud Enrollment Guide]</a>
When enrolling a device, Make sure to use the following log-in format:
</p>
<p>
<b>Organisation:</b> $tenant-domain
<b>Username:</b> $email-address
<b>Password:</b> password provided at registration.
</p>
</div>
<div>
<p style="font-length: 1em; font-family: Arial, Helvetica; line-height: 170%; color: #666666; margin: 20px 0px 5px;">
If you have any further questions, please reach out to us using your registered mail to
<a href="bizdev-group@entgra.io"> bizdev-group@entgra.io.</a> Looking forward to working with you.
</p>
<p style="font-length: 1em; font-family: Arial, Helvetica; line-height: 170%; color: #666666; margin: 20px 0px 5px;">
Best Regards,
</p>
<p style="font-size: 1em; font-family: Arial, Helvetica; line-height: 170%; color: #666666; margin: 5px 0px;">
Entgra Cloud Team
</p>
</div>
</div>
</div>
</div>
</body>
</html>
]]>
</Body>
</EmailConfig>
Loading…
Cancel
Save