Added security token

master
Keith 2016-06-22 21:18:35 -04:00
parent 43d7680ba2
commit 78352d3c2d
2 changed files with 7 additions and 3 deletions

View File

@ -39,6 +39,7 @@ public class LocationService extends Service implements GoogleApiClient.Connecti
private Socket mSocket; private Socket mSocket;
private String mUserID; private String mUserID;
private String mUserSK;
private SharedPreferences sharedPref; private SharedPreferences sharedPref;
Location mLastLocation; Location mLastLocation;
private GoogleApiClient mGoogleApiClient; private GoogleApiClient mGoogleApiClient;
@ -118,6 +119,7 @@ public class LocationService extends Service implements GoogleApiClient.Connecti
Log.d(TAG, "LowPowerReceiver activated"); Log.d(TAG, "LowPowerReceiver activated");
mUserID = sharedPref.getString("loggedInUserId", null); mUserID = sharedPref.getString("loggedInUserId", null);
mUserSK = sharedPref.getString("loggedInUserId", null);
final String SERVER_ADDRESS = "https://tracman.org/"; final String SERVER_ADDRESS = "https://tracman.org/";
// Connect to socket // Connect to socket
@ -209,6 +211,7 @@ public class LocationService extends Service implements GoogleApiClient.Connecti
JSONObject mLocationView = new JSONObject(); JSONObject mLocationView = new JSONObject();
try { try {
mLocationView.put("usr", mUserID); mLocationView.put("usr", mUserID);
mLocationView.put("tok", mUserSK);
mLocationView.put("lat", String.valueOf(location.getLatitude())); mLocationView.put("lat", String.valueOf(location.getLatitude()));
mLocationView.put("lon", String.valueOf(location.getLongitude())); mLocationView.put("lon", String.valueOf(location.getLongitude()));
mLocationView.put("dir", String.valueOf(location.getBearing())); mLocationView.put("dir", String.valueOf(location.getBearing()));

View File

@ -143,20 +143,20 @@ public class LoginActivity extends AppCompatActivity implements
String userString = res.body().string(); String userString = res.body().string();
System.out.println("Full response: " + userString); System.out.println("Full response: " + userString);
String userID, userName; String userID, userName, userSK;
try { try {
JSONObject user = new JSONObject(userString); JSONObject user = new JSONObject(userString);
userID = user.getString("_id"); userID = user.getString("_id");
userName = user.getString("name"); userName = user.getString("name");
userSK = user.getString("sk32");
Log.v(TAG, "User retrieved with ID: " + userID); Log.v(TAG, "User retrieved with ID: " + userID);
} catch (JSONException e) { } catch (JSONException e) {
Log.e(TAG, "Unable to parse user JSON: ", e); Log.e(TAG, "Unable to parse user JSON: ", e);
Log.e(TAG, "JSON String used: " + userString); Log.e(TAG, "JSON String used: " + userString);
userID = null; userID = null;
userName = null; userName = null;
userSK = null;
} }
Log.v(TAG, "UserID: " + userID);
// Save user as loggedInUser // Save user as loggedInUser
SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(getApplicationContext()); SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
@ -164,6 +164,7 @@ public class LoginActivity extends AppCompatActivity implements
editor.putString("loggedInUser", userString); editor.putString("loggedInUser", userString);
editor.putString("loggedInUserId", userID); editor.putString("loggedInUserId", userID);
editor.putString("loggedInUserName", userName); editor.putString("loggedInUserName", userName);
editor.putString("loggedInUserSk", userSK);
editor.commit(); editor.commit();
startActivity(new Intent(getBaseContext(), MainActivity.class)); startActivity(new Intent(getBaseContext(), MainActivity.class));