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

View File

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