Merge pull request #105 from ClaytonWWilson/master

Merge from master
This commit is contained in:
Aaron Sun 2020-11-04 20:06:14 -08:00 committed by GitHub
commit a2e9c30d6c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 100 additions and 25 deletions

View File

@ -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);

View File

@ -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>

View File

@ -14,12 +14,14 @@ import android.widget.ListView;
import android.widget.ProgressBar;
import android.widget.SearchView;
import com.example.listify.adapter.SearchResultsListAdapter;
import com.example.listify.data.Chain;
import com.example.listify.data.ItemSearch;
import com.example.listify.model.Product;
import org.json.JSONException;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Properties;
@ -315,12 +317,28 @@ public class SearchResults extends AppCompatActivity implements FilterDialogFrag
public void acceptDelivery(Object delivered) {
ItemSearch results = (ItemSearch) delivered;
try {
HashMap<Integer,String> chainNameMap = new HashMap<>();
for (int i = 0; i < results.getResults().size(); i++) {
// TODO: Change to dynamically grab chain name by id
// Use hash map to save chain name to avoid lots of requests
if (!chainNameMap.containsKey((Integer)results.getResults().get(i).getChainID())) {
Properties configs = new Properties();
try {
configs = AuthManager.loadProperties(this, "android.resource://" + getPackageName() + "/raw/auths.json");
} catch (IOException | JSONException e) {
e.printStackTrace();
}
SynchronousReceiver<Chain> chainReciever = new SynchronousReceiver<>();
Requestor requestor = new Requestor(am, configs.getProperty("apiKey"));
requestor.getObject(Integer.toString(results.getResults().get(i).getChainID()), Chain.class, chainReciever);
chainNameMap.put((Integer)results.getResults().get(i).getChainID(), chainReciever.await().getName());
}
resultsProductList.add(new Product(
results.getResults().get(i).getDescription(),
results.getResults().get(i).getProductID(),
"Kroger",
chainNameMap.get(results.getResults().get(i).getChainID()),
results.getResults().get(i).getChainID(),
results.getResults().get(i).getUpc(),
results.getResults().get(i).getDescription(),

View File

@ -3,34 +3,25 @@ package com.example.listify.ui.home;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.view.ViewGroup;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;
import static com.example.listify.MainActivity.am;
import com.example.listify.AuthManager;
import com.example.listify.MainActivity;
import com.example.listify.R;
import com.example.listify.Requestor;
import com.example.listify.ui.ForgotPasswordPage;
import com.example.listify.ui.LoginPage;
import org.json.JSONException;
import java.io.IOException;
import java.util.Properties;
import static com.example.listify.MainActivity.am;
public class HomeFragment extends Fragment {
private Button toDeleteAccountPage;
@ -61,10 +52,10 @@ public class HomeFragment extends Fragment {
}
Requestor requestor = new Requestor(am, configs.getProperty("apiKey"));
try {
am.changePassword(am.getEmail());
}
catch (Exception e) {}
// try {
// am.changePassword(am.getEmail());
// }
// catch (Exception e) {}
/*try {
am.confirmPasswordReset("", "");
}