mirror of
https://github.com/ClaytonWWilson/Listify.git
synced 2026-03-10 18:55:03 +00:00
Send more detailed account deletion email
Use SES to send an account deletion confimration email to the user when they delete their account.
This commit is contained in:
@@ -1,21 +1,40 @@
|
||||
import com.amazonaws.services.cognitoidp.AWSCognitoIdentityProvider;
|
||||
import com.amazonaws.services.cognitoidp.AWSCognitoIdentityProviderClientBuilder;
|
||||
import com.amazonaws.services.cognitoidp.model.AdminDeleteUserRequest;
|
||||
import com.amazonaws.services.cognitoidp.model.AdminUserGlobalSignOutRequest;
|
||||
import com.amazonaws.services.cognitoidp.model.*;
|
||||
import com.amazonaws.regions.Regions;
|
||||
import com.amazonaws.services.simpleemail.AmazonSimpleEmailService;
|
||||
import com.amazonaws.services.simpleemail.AmazonSimpleEmailServiceClientBuilder;
|
||||
import com.amazonaws.services.simpleemail.model.Body;
|
||||
import com.amazonaws.services.simpleemail.model.Content;
|
||||
import com.amazonaws.services.simpleemail.model.Destination;
|
||||
import com.amazonaws.services.simpleemail.model.Message;
|
||||
import com.amazonaws.services.simpleemail.model.SendEmailRequest;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
import java.util.*;
|
||||
|
||||
public class UserDeleter implements CallHandler {
|
||||
|
||||
private Connection connection;
|
||||
private String cognitoID;
|
||||
|
||||
static final String DELETION_EMAIL_FROM = "merzn@purdue.edu";
|
||||
static final String CONFIGSET = "ConfigSet";
|
||||
static final String DELETION_EMAIL_SUBJECT = "Listify Account Deletion Confirmation";
|
||||
static final String HTMLBODY = "<h1>We're sad to see you go!</h1>"
|
||||
+ "<p> This email is to confirm your Listify account has been deleted. If you have any questions"
|
||||
+ " or did not request this action, please reply to this email. Thank you for being a Listify"
|
||||
+ " user and best of luck in your other endeavours!"
|
||||
+ "<p>"
|
||||
+ "<p> - The Listify Team";
|
||||
static final String TEXTBODY = "This email is to confirm your Listify account has been deleted. If you have any questions"
|
||||
+ " or did not request this action, please reply to this email. Thank you for being a Listify"
|
||||
+ " user and best of luck in your other endeavours! - The Listify Team";
|
||||
|
||||
private final String GET_LISTS = "SELECT * FROM List WHERE (owner = ?);";
|
||||
private final String DELETE_LIST_PRODUCT = "DELETE FROM ListProduct WHERE (listID = ?);";
|
||||
private final String DELETE_LISTS = "DELETE FROM List WHERE (owner = ?);";
|
||||
@@ -38,6 +57,30 @@ public class UserDeleter implements CallHandler {
|
||||
}
|
||||
String userPoolId = cognitoProperties.get("userPoolId").toString();
|
||||
System.out.println(userPoolId);
|
||||
|
||||
ListUsersRequest checkRequest = new ListUsersRequest().withUserPoolId(userPoolId);
|
||||
checkRequest.setFilter("sub=\"" + cognitoID +"\"");
|
||||
|
||||
ListUsersResult foundUsersResult = awsCognitoIdentityProvider.listUsers(checkRequest);
|
||||
List<UserType> foundUsers = foundUsersResult.getUsers();
|
||||
if (foundUsers.size() != 1) {
|
||||
System.out.println(foundUsers);
|
||||
if (foundUsers.size() == 0) {
|
||||
throw new InputMismatchException("No user with given sub");
|
||||
}
|
||||
throw new InputMismatchException("Found more than one user with supposedly unique sub");
|
||||
}
|
||||
UserType foundUser = foundUsers.get(0);
|
||||
System.out.println(foundUser.getAttributes());
|
||||
String email = "";
|
||||
for (AttributeType attribute : foundUser.getAttributes()) {
|
||||
if (attribute.getName().equals("email")) {
|
||||
email = attribute.getValue();
|
||||
break;
|
||||
}
|
||||
System.out.println(attribute.getName() + ": " + attribute.getValue());
|
||||
}
|
||||
|
||||
AdminUserGlobalSignOutRequest adminUserGlobalSignOutRequest = new AdminUserGlobalSignOutRequest().withUserPoolId(userPoolId);
|
||||
adminUserGlobalSignOutRequest.setUsername(cognitoID);
|
||||
System.out.println(adminUserGlobalSignOutRequest);
|
||||
@@ -49,6 +92,24 @@ public class UserDeleter implements CallHandler {
|
||||
|
||||
|
||||
|
||||
|
||||
AmazonSimpleEmailService client =
|
||||
AmazonSimpleEmailServiceClientBuilder.standard()
|
||||
.withRegion(Regions.US_EAST_2).build();
|
||||
SendEmailRequest request = new SendEmailRequest()
|
||||
.withDestination(
|
||||
new Destination().withToAddresses(email))
|
||||
.withMessage(new Message()
|
||||
.withBody(new Body()
|
||||
.withHtml(new Content()
|
||||
.withCharset("UTF-8").withData(HTMLBODY))
|
||||
.withText(new Content()
|
||||
.withCharset("UTF-8").withData(TEXTBODY)))
|
||||
.withSubject(new Content()
|
||||
.withCharset("UTF-8").withData(DELETION_EMAIL_SUBJECT)))
|
||||
.withSource(DELETION_EMAIL_FROM);
|
||||
client.sendEmail(request);
|
||||
|
||||
PreparedStatement statement = connection.prepareStatement(GET_LISTS);
|
||||
statement.setString(1, cognitoID);
|
||||
System.out.println(statement);
|
||||
|
||||
@@ -64,6 +64,11 @@
|
||||
<artifactId>aws-java-sdk-cognitoidp</artifactId>
|
||||
<version>1.11.875</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.amazonaws</groupId>
|
||||
<artifactId>aws-java-sdk-ses</artifactId>
|
||||
<version>1.11.875</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>software.amazon.ion</groupId>
|
||||
<artifactId>ion-java</artifactId>
|
||||
|
||||
Reference in New Issue
Block a user