Skip to content

Completed Login, SignUp, MainMenu #13

Merged
merged 2 commits into from
Mar 24, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .idea/.name

This file was deleted.

12 changes: 7 additions & 5 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,7 @@
<activity android:name=".Settings"></activity>

<activity android:name=".MainMenu" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".WaterWay.WaterWayNav"
Expand All @@ -28,7 +24,13 @@
<activity android:name=".Reset_password" />
<activity android:name=".SampleFordm" />
<activity android:name=".InspectionForm" />
<activity android:name=".Login" />
<activity android:name=".Login" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".SignUp" />
</application>

Expand Down
13 changes: 13 additions & 0 deletions app/src/main/java/com/sf/stormwaterutilityandroid/AgencyID.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.sf.stormwaterutilityandroid;

public class AgencyID {
private String agencyID;

public AgencyID(String agencyID) {
this.agencyID = agencyID;
}

public String getAgencyID() {
return agencyID;
}
}
19 changes: 17 additions & 2 deletions app/src/main/java/com/sf/stormwaterutilityandroid/Login.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
import com.google.android.gms.tasks.Task;
import com.google.firebase.auth.AuthResult;
import com.google.firebase.auth.FirebaseAuth;
import com.google.firebase.firestore.DocumentSnapshot;
import com.google.firebase.firestore.FirebaseFirestore;
import com.sf.stormwaterutilityandroid.WaterWay.WaterWayNav;

public class Login extends AppCompatActivity {
Expand Down Expand Up @@ -55,7 +57,7 @@ public void onAuthStateChanged(@NonNull FirebaseAuth firebaseAuth) {
setContentView(R.layout.activity_login);
inputEmail = findViewById(R.id.email);
inputPassword = findViewById(R.id.password);
progressBar = findViewById(R.id.progressBar);
progressBar = findViewById(R.id.progressBar3);
btnSignup = findViewById(R.id.btn_signup);
btnLogin = findViewById(R.id.btn_login);
btnReset = findViewById(R.id.btn_reset_password);
Expand All @@ -80,6 +82,7 @@ public void onClick(View v) {
btnLogin.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {

String email = inputEmail.getText().toString();
final String password = inputPassword.getText().toString();

Expand Down Expand Up @@ -113,11 +116,23 @@ public void onComplete(@NonNull Task<AuthResult> task) {
}
} else {
if (auth.getCurrentUser().isEmailVerified()) {
Intent intent = new Intent(Login.this, WaterWayNav.class);
FirebaseFirestore.getInstance().collection("Users").document(auth.getUid()).get().addOnCompleteListener(new OnCompleteListener<DocumentSnapshot>() {
@Override
public void onComplete(@NonNull Task<DocumentSnapshot> task) {
if (task.isSuccessful()) {
if (task.getResult().exists()) {
String agencyID = task.getResult().get("agencyID").toString();
AgencyID id = new AgencyID(agencyID);
}
}
}
});
Intent intent = new Intent(Login.this, MainMenu.class);
startActivity(intent);
progressBar.setVisibility(View.INVISIBLE);
finish();
} else {
progressBar.setVisibility(View.INVISIBLE);
AlertDialog.Builder builder;
builder = new AlertDialog.Builder(Login.this);
//builder.setIcon(R.drawable.open_browser);
Expand Down
37 changes: 32 additions & 5 deletions app/src/main/java/com/sf/stormwaterutilityandroid/MainMenu.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.sf.stormwaterutilityandroid;

import androidx.appcompat.app.AppCompatActivity;
import androidx.cardview.widget.CardView;

import android.content.Intent;
import android.os.Bundle;
Expand All @@ -12,15 +13,40 @@

public class MainMenu extends AppCompatActivity {
Button launchWWF,launchCF, launchSettings;
CardView cvWaterWay, cvConstruction, cvSettings;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main_menu);
launchWWF = findViewById(R.id.wwf);
launchCF = findViewById(R.id.cf);
launchSettings = findViewById(R.id.settings);
launchSettings.setOnClickListener(new View.OnClickListener() {
setContentView(R.layout.activity_menu2);
cvWaterWay = findViewById(R.id.cvWaterWay);
cvConstruction = findViewById(R.id.cvConstructionForm);
cvSettings = findViewById(R.id.cvSettings);
cvWaterWay.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(MainMenu.this, WaterWayNav.class);
startActivity(intent);
}
});
cvConstruction.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(MainMenu.this, ConstructionNav.class);
startActivity(intent);
}
});
cvSettings.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(MainMenu.this, Settings.class);
startActivity(intent);
}
});
// launchWWF = findViewById(R.id.wwf);
// launchCF = findViewById(R.id.cf);
// launchSettings = findViewById(R.id.settings);
// launchSettings.setOnClickListener(new View.OnClickListener() {
/* @Override
public void onClick(View v) {
Intent intent = new Intent(MainMenu.this, Settings.class);
startActivity(intent);
Expand All @@ -44,5 +70,6 @@ public void onClick(View v) {
}
});
*/
}
}
69 changes: 43 additions & 26 deletions app/src/main/java/com/sf/stormwaterutilityandroid/SignUp.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.sf.stormwaterutilityandroid;

import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
Expand All @@ -9,6 +11,7 @@
import android.widget.Toast;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;

import com.google.android.gms.tasks.OnCompleteListener;
Expand All @@ -34,16 +37,14 @@ protected void onCreate(Bundle savedInstanceState) {
//Get Firebase auth instance
auth = FirebaseAuth.getInstance();

btnSignIn = findViewById(R.id.sign_in_button);
btnSignUp = findViewById(R.id.sign_up_button);
btnSignUp = findViewById(R.id.signUp);

inputEmail = findViewById(R.id.email);
inputPassword = findViewById(R.id.password);
progressBar = findViewById(R.id.progressBar);
btnResetPassword = findViewById(R.id.btn_reset_password);
inputGrade = findViewById(R.id.grade);
inputName = findViewById(R.id.name);
inputID = findViewById(R.id.studentID);
inputHR = findViewById(R.id.homeroom);
progressBar = findViewById(R.id.progressBar2);

/* btnResetPassword.setOnClickListener(new View.OnClickListener() {
@Override
Expand All @@ -52,12 +53,6 @@ public void onClick(View v) {
}
});
*/
btnSignIn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
finish();
}
});

btnSignUp.setOnClickListener(new View.OnClickListener() {
@Override
Expand All @@ -66,14 +61,13 @@ public void onClick(View v) {
final String email = inputEmail.getText().toString().trim();
final String password = inputPassword.getText().toString().trim();
final String name = inputName.getText().toString().trim();
final String grade = inputGrade.getText().toString().trim();
final String studentID = inputID.getText().toString().trim();
final String homeroom = inputHR.getText().toString().trim();

if (TextUtils.isEmpty(email)) {
Toast.makeText(getApplicationContext(), "Enter a email address!", Toast.LENGTH_SHORT).show();
return;
}

int index = email.indexOf("@");
String agencyID = email.substring(index + 1);
if (TextUtils.isEmpty(password)) {
Toast.makeText(getApplicationContext(), "Enter a password!", Toast.LENGTH_SHORT).show();
return;
Expand All @@ -83,12 +77,21 @@ public void onClick(View v) {
Toast.makeText(getApplicationContext(), "Password too short, enter minimum 6 characters!", Toast.LENGTH_SHORT).show();
return;
}
if (TextUtils.isEmpty(homeroom)) {
Toast.makeText(getApplicationContext(), "Enter a homeroom!", Toast.LENGTH_SHORT).show();
return;
}
if (TextUtils.isEmpty(studentID)) {
Toast.makeText(getApplicationContext(), "Enter a StudentID!", Toast.LENGTH_SHORT).show();

if (!email.contains("in.gov") && !email.contains("purdue.edu")) {
//invalid email
AlertDialog.Builder builder;
builder = new AlertDialog.Builder(SignUp.this);
builder.setTitle("Incorrect Email");
builder.setMessage("You are not allowed to create an email with your current domain");
builder.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
dialog.dismiss();
}
});

builder.setCancelable(true);
builder.show();
return;
}

Expand All @@ -109,8 +112,10 @@ public void onComplete(@NonNull Task<AuthResult> task) {
} else {
final String create_uid = FirebaseAuth.getInstance().getUid();
final FirebaseUser user2 = auth.getCurrentUser();
user2.sendEmailVerification();
User user = new User(name,email,create_uid);
// user2.sendEmailVerification();

System.out.println(agencyID);
User user = new User(name, email, create_uid, agencyID);

FirebaseFirestore.getInstance().collection("Users")
.document(create_uid)
Expand All @@ -122,10 +127,23 @@ public void onSuccess(Void aVoid) {
user2.sendEmailVerification();



// progressBar.setVisibility(View.GONE);
// Toast.makeText(SignupActivity.this, getString(R.string.registration_success), Toast.LENGTH_LONG).show();
// startActivity(new Intent(SignupActivity.this, LoginActivity.class));
AlertDialog.Builder builder;
builder = new AlertDialog.Builder(SignUp.this);
builder.setTitle("Account created");
builder.setMessage("Your account has successfully been created. An email has been sent, so you can verify your email. You must verify your email before logging in.");
builder.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
startActivity(new Intent(SignUp.this, Login.class));
dialog.dismiss();
}
});

builder.setCancelable(true);
builder.show();


// finish();

}
Expand All @@ -149,7 +167,6 @@ public void onFailure(@NonNull Exception e) {
}



@Override
protected void onResume() {
super.onResume();
Expand Down
13 changes: 11 additions & 2 deletions app/src/main/java/com/sf/stormwaterutilityandroid/User.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
package com.sf.stormwaterutilityandroid;

class User {
String name, email, uid;
String name, email, uid,agencyID;

public User(String name, String email, String uid) {
public User(String name, String email, String uid, String agencyID) {
this.name = name;
this.email = email;
this.uid = uid;
this.agencyID = agencyID;
}

public String getName() {
Expand All @@ -32,4 +33,12 @@ public String getUid() {
public void setUid(String uid) {
this.uid = uid;
}

public String getAgencyID() {
return agencyID;
}

public void setAgencyID(String agencyID) {
this.agencyID = agencyID;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,5 @@ public static double getWQI(double tempChange, double turbidity, double pH, doub

}

}


Binary file added app/src/main/res/drawable/construction.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/drawable/construction2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/drawable/settings.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/drawable/settings2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/drawable/settings3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/drawable/water.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading