Skip to content

Commit

Permalink
APIs for updating PIN and password
Browse files Browse the repository at this point in the history
  • Loading branch information
slogan621 committed Apr 6, 2021
1 parent 0b5a40c commit 9b2e3ba
Showing 1 changed file with 60 additions and 4 deletions.
64 changes: 60 additions & 4 deletions app/src/main/java/org/thousandsmiles/tscharts_lib/LoginREST.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* (C) Copyright Syd Logan 2017
* (C) Copyright Thousand Smiles Foundation 2017
* (C) Copyright Syd Logan 2017-2021
* (C) Copyright Thousand Smiles Foundation 2017-2021
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -53,7 +53,7 @@ public void onResponse(JSONObject response) {
}
}

private class CreateUserResponseListener implements Response.Listener<JSONObject> {
private class AuthenticationAPIResponseListener implements Response.Listener<JSONObject> {

@Override
public void onResponse(JSONObject response) {
Expand Down Expand Up @@ -223,7 +223,63 @@ public Object createUser(String first, String last, String password, String eMai
// because of the bad JSON sent
}

AuthJSONObjectRequest request = new AuthJSONObjectRequest(Request.Method.POST, url, data, new CreateUserResponseListener(), new ErrorListener());
AuthJSONObjectRequest request = new AuthJSONObjectRequest(Request.Method.POST, url, data, new AuthenticationAPIResponseListener(), new ErrorListener());
request.setRetryPolicy(new DefaultRetryPolicy(getTimeoutInMillis(), getRetries(), DefaultRetryPolicy.DEFAULT_BACKOFF_MULT));

queue.add((JsonObjectRequest) request);

return m_lock;
}

public Object updatePassword(String username, String password) {

VolleySingleton volley = VolleySingleton.getInstance();

volley.initQueueIf(getContext());

RequestQueue queue = volley.getQueue();

String url = String.format("%s://%s:%s/tscharts/v1/updatepassword/", getProtocol(), getIP(), getPort());

JSONObject data = new JSONObject();

try {
data.put("username", username);
data.put("password", password);
} catch(Exception e) {
// not sure this would ever happen, ignore. Continue on with the request with the expectation it fails
// because of the bad JSON sent
}

AuthJSONObjectRequest request = new AuthJSONObjectRequest(Request.Method.PUT, url, data, new AuthenticationAPIResponseListener(), new ErrorListener());
request.setRetryPolicy(new DefaultRetryPolicy(getTimeoutInMillis(), getRetries(), DefaultRetryPolicy.DEFAULT_BACKOFF_MULT));

queue.add((JsonObjectRequest) request);

return m_lock;
}

public Object updatePIN(String username, String pin) {

VolleySingleton volley = VolleySingleton.getInstance();

volley.initQueueIf(getContext());

RequestQueue queue = volley.getQueue();

String url = String.format("%s://%s:%s/tscharts/v1/updatepin/", getProtocol(), getIP(), getPort());

JSONObject data = new JSONObject();

try {
data.put("first", username);
data.put("pin", pin);
} catch(Exception e) {
// not sure this would ever happen, ignore. Continue on with the request with the expectation it fails
// because of the bad JSON sent
}

AuthJSONObjectRequest request = new AuthJSONObjectRequest(Request.Method.PUT, url, data, new AuthenticationAPIResponseListener(), new ErrorListener());
request.setRetryPolicy(new DefaultRetryPolicy(getTimeoutInMillis(), getRetries(), DefaultRetryPolicy.DEFAULT_BACKOFF_MULT));

queue.add((JsonObjectRequest) request);
Expand Down

0 comments on commit 9b2e3ba

Please sign in to comment.