Permalink
Browse files

Added authentication checking

  • Loading branch information...
darver committed May 19, 2017
1 parent 14ca2a0 commit 39f13b61e1a564202133163f07de409d45cda2eb
@@ -5,6 +5,17 @@
*/
public class Coordinator extends PointOfContact {
// private String firstName;
// private String lastName;
// private String email;
// private String sms;
// private String phoneNumber;
// private boolean isAvailable;
// private int preferredMethodOfContact;
public Coordinator() {
}
public Coordinator(String firstName,
String lastName,
@@ -22,4 +33,38 @@ public Coordinator(String firstName,
this.preferredMethodOfContact = preferredMethodOfContact;
}
// @Override
// public String getFirstName() {
// return firstName;
// }
//
// @Override
// public String getLastName() {
// return lastName;
// }
//
// @Override
// public String getEmail() {
// return email;
// }
//
// @Override
// public String getSms() {
// return sms;
// }
//
// @Override
// public String getPhoneNumber() {
// return phoneNumber;
// }
//
// @Override
// public boolean isAvailable() {
// return isAvailable;
// }
//
// @Override
// public int getPreferredMethodOfContact() {
// return preferredMethodOfContact;
// }
}
@@ -1,5 +1,15 @@
package foodrev.org.foodrev.presentation.presenters.impl;
import com.google.firebase.auth.FirebaseAuth;
import com.google.firebase.database.DataSnapshot;
import com.google.firebase.database.DatabaseError;
import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.FirebaseDatabase;
import com.google.firebase.database.ValueEventListener;
import java.util.Map;
import foodrev.org.foodrev.domain.models.Coordinator;
import foodrev.org.foodrev.presentation.presenters.UserTypePresenter;
/**
@@ -16,9 +26,44 @@ public void attachView(View view) {
@Override
public void coordinatorSelected() {
// Do some checking to see if the authenticated user is able to be coordinator
// TODO: do checking with an associated user hash instead
final String uid = FirebaseAuth.getInstance().getCurrentUser().getUid();
DatabaseReference ref = FirebaseDatabase.getInstance().getReference("COORDINATORS");
ref.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
for (DataSnapshot coordinator : dataSnapshot.getChildren()) {
TempCoordinator tc = coordinator.getValue(TempCoordinator.class);
if (uid.equals(tc.getCoordinatorOauth())) {
mView.goToCoordinatorMode();
}
}
mView.showError("Not a coordinator");
}
@Override
public void onCancelled(DatabaseError databaseError) {
mView.showError(databaseError.getMessage());
}
});
}
public static class TempCoordinator {
private String coordinatorName;
private String coordinatorOauth;
public TempCoordinator() {
}
public String getCoordinatorName() {
return this.coordinatorName;
}
public String getCoordinatorOauth() {
return this.coordinatorOauth;
}
mView.goToCoordinatorMode();
}
@Override
@@ -3,8 +3,10 @@
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Toast;
import com.google.firebase.auth.FirebaseAuth;
import foodrev.org.foodrev.R;
import foodrev.org.foodrev.presentation.presenters.UserTypePresenter;
import foodrev.org.foodrev.presentation.presenters.impl.UserTypePresenterImpl;
@@ -15,6 +17,7 @@
@Override
protected void onCreate(Bundle savedInstanceState) {
Log.d("Darin", FirebaseAuth.getInstance().getCurrentUser().getUid());
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_user_type);
attachPresenter();
@@ -71,6 +74,6 @@ public void hideProgressDialog() {
@Override
public void showError(String message) {
Toast.makeText(this, message, Toast.LENGTH_SHORT).show();
}
}
@@ -9,7 +9,7 @@
<TextView
android:id="@+id/textView2"
android:layout_width="292dp"
android:layout_height="32dp"
android:layout_height="0dp"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:text="@string/user_type"
@@ -18,9 +18,9 @@
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
tools:text="@string/user_type"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintHorizontal_bias="0.495"
app:layout_constraintTop_toTopOf="parent"
android:layout_marginTop="-123dp" />
android:layout_marginTop="24dp" />
<Button
android:id="@+id/select_type_coordinator_button"
@@ -31,9 +31,12 @@
app:layout_constraintRight_toRightOf="@+id/select_type_driver_button"
android:layout_marginLeft="0dp"
app:layout_constraintLeft_toLeftOf="@+id/select_type_driver_button"
android:layout_marginTop="14dp"
android:layout_marginTop="13dp"
app:layout_constraintTop_toBottomOf="@+id/select_type_driver_button"
app:layout_constraintHorizontal_bias="0.0" />
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintBottom_toBottomOf="parent"
android:layout_marginBottom="8dp"
app:layout_constraintVertical_bias="0.0" />
<Button
android:id="@+id/select_type_driver_button"
@@ -45,7 +48,7 @@
android:layout_marginRight="8dp"
app:layout_constraintRight_toRightOf="@+id/textView2"
app:layout_constraintHorizontal_bias="0.504"
android:layout_marginTop="42dp"
android:layout_marginTop="41dp"
app:layout_constraintTop_toBottomOf="@+id/textView2" />
</android.support.constraint.ConstraintLayout>

0 comments on commit 39f13b6

Please sign in to comment.