mirror of
https://github.com/ClaytonWWilson/Listify.git
synced 2025-12-15 18:28:47 +00:00
User retrieval updates
Make sure AuthManager always has the user email. Make UserGET always return a User object.
This commit is contained in:
parent
e528830474
commit
53570b3356
@ -33,16 +33,18 @@ public class UserGetter implements CallHandler {
|
||||
checkRequest.setFilter("email=\"" + emailObject.toString() +"\"");
|
||||
} else {
|
||||
try {
|
||||
String id = queryMap.get("id");
|
||||
if ((id != null) && (!id.equals(""))) {
|
||||
attributeToGet = "email";
|
||||
checkRequest.setFilter("sub=\"" + cognitoID + "\"");
|
||||
} else {
|
||||
return cognitoID;
|
||||
}
|
||||
// String id = queryMap.get("id");
|
||||
attributeToGet = "email";
|
||||
checkRequest.setFilter("sub=\"" + cognitoID + "\"");
|
||||
// if ((id != null) && (!id.equals(""))) {
|
||||
// attributeToGet = "email";
|
||||
// checkRequest.setFilter("sub=\"" + cognitoID + "\"");
|
||||
// } else {
|
||||
// return cognitoID;
|
||||
// }
|
||||
} catch (Exception e) {
|
||||
System.out.println(e);
|
||||
return cognitoID;
|
||||
return new User(cognitoID, null);
|
||||
}
|
||||
}
|
||||
System.out.println(checkRequest);
|
||||
@ -52,9 +54,9 @@ public class UserGetter implements CallHandler {
|
||||
if (foundUsers.size() != 1) {
|
||||
System.out.println(foundUsers);
|
||||
if (foundUsers.size() == 0) {
|
||||
throw new InputMismatchException("Not user with given email");
|
||||
throw new InputMismatchException("Not user with given attribute (" + attributeToGet + ")");
|
||||
}
|
||||
throw new InputMismatchException("Found more than one user with supposedly unique email");
|
||||
throw new InputMismatchException("Found more than one user with supposedly unique attribute (" + attributeToGet + ")");
|
||||
}
|
||||
UserType foundUser = foundUsers.get(0);
|
||||
System.out.println(foundUser.getAttributes());
|
||||
@ -66,6 +68,11 @@ public class UserGetter implements CallHandler {
|
||||
}
|
||||
System.out.println(attribute.getName() + ": " + attribute.getValue());
|
||||
}
|
||||
return new User(cognitoID, attributeToReturn);
|
||||
if (attributeToGet.equals("email")) {
|
||||
return new User(cognitoID, attributeToReturn);
|
||||
} else if (attributeToGet.equals("sub")) {
|
||||
return new User(attributeToReturn, emailObject.toString());
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@ -9,6 +9,7 @@ import com.amplifyframework.auth.result.AuthResetPasswordResult;
|
||||
import com.amplifyframework.auth.result.AuthSignInResult;
|
||||
import com.amplifyframework.auth.result.AuthSignUpResult;
|
||||
import com.amplifyframework.core.Amplify;
|
||||
import com.example.listify.data.ListShare;
|
||||
import com.example.listify.data.User;
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
@ -60,7 +61,21 @@ public class AuthManager {
|
||||
return authSession.getUserPoolTokens().getValue().getIdToken();
|
||||
}
|
||||
|
||||
public String getEmail() {
|
||||
public String getEmail(Requestor requestor) {
|
||||
if (email == null) {
|
||||
try {
|
||||
requestor.putObject(new ListShare(285, "nmerz@icloud.com", 210, -1, null));
|
||||
} catch (JSONException jsonException) {
|
||||
jsonException.printStackTrace();
|
||||
}
|
||||
SynchronousReceiver<User> userSynchronousReceiver = new SynchronousReceiver<>();
|
||||
requestor.getObject("self", User.class, userSynchronousReceiver);
|
||||
try {
|
||||
email = userSynchronousReceiver.await().getEmail();
|
||||
} catch (Exception e) {
|
||||
return email;
|
||||
}
|
||||
}
|
||||
return email;
|
||||
}
|
||||
|
||||
|
||||
@ -171,8 +171,6 @@ public class MainActivity extends AppCompatActivity implements CreateListDialogF
|
||||
DrawerLayout drawer = findViewById(R.id.drawer_layout);
|
||||
NavigationView navigationView = findViewById(R.id.nav_view);
|
||||
|
||||
TextView emailView = navigationView.getHeaderView(0).findViewById(R.id.textViewEmailSidebar);
|
||||
emailView.setText(am.getEmail());
|
||||
Properties configs = new Properties();
|
||||
try {
|
||||
configs = AuthManager.loadProperties(this, "android.resource://" + getPackageName() + "/raw/auths.json");
|
||||
@ -180,6 +178,8 @@ public class MainActivity extends AppCompatActivity implements CreateListDialogF
|
||||
e.printStackTrace();
|
||||
}
|
||||
Requestor requestor = new Requestor(am, configs.getProperty("apiKey"));
|
||||
TextView emailView = navigationView.getHeaderView(0).findViewById(R.id.textViewEmailSidebar);
|
||||
emailView.setText(am.getEmail(requestor));
|
||||
SynchronousReceiver<Picture> profilePictureReceiver = new SynchronousReceiver<>();
|
||||
ImageView profilePictureView = navigationView.getHeaderView(0).findViewById(R.id.imageViewProfilePicture);
|
||||
try {
|
||||
|
||||
@ -33,7 +33,14 @@ public class ProfileFragment extends Fragment {
|
||||
View root = inflater.inflate(R.layout.fragment_profile, container, false);
|
||||
|
||||
TextView emailText = (TextView) root.findViewById(R.id.textViewEmail);
|
||||
emailText.setText(am.getEmail());
|
||||
Properties configs = new Properties();
|
||||
try {
|
||||
configs = AuthManager.loadProperties(getContext(), "android.resource://" + getActivity().getPackageName() + "/raw/auths.json");
|
||||
} catch (IOException | JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
Requestor requestor = new Requestor(am, configs.getProperty("apiKey"));
|
||||
emailText.setText(am.getEmail(requestor));
|
||||
|
||||
toDeleteAccountPage = (Button) root.findViewById(R.id.button);
|
||||
toDeleteAccountPage.setOnClickListener(new View.OnClickListener() {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user