Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Falzaraj #128

Open
wants to merge 12 commits into
base: main
Choose a base branch
from
Open
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
17 changes: 0 additions & 17 deletions .idea/deploymentTargetDropDown.xml

This file was deleted.

4 changes: 2 additions & 2 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

54 changes: 3 additions & 51 deletions app/src/main/java/edu/sc/purplelimited/#Activity.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package edu.sc.purplelimited;

import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
Expand All @@ -16,12 +15,8 @@
import com.google.android.gms.tasks.OnCompleteListener;
import com.google.android.gms.tasks.Task;
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;

public class LoginActivity extends AppCompatActivity {

Expand All @@ -33,16 +28,11 @@ public class LoginActivity extends AppCompatActivity {
private CheckBox RememberMe;
private int cnt = 3; //base amount of login attempts

static String userName = "admin";
String userPassword = "admin"; //these are hard-coded for testing
static String userName;
String userPassword;

boolean isValid = false;

public UserAccount userAccount;

SharedPreferences sharedPreferences;
SharedPreferences.Editor sharedPreferencesEditor;

FirebaseDatabase database;
DatabaseReference usersReference;

Expand All @@ -57,33 +47,8 @@ protected void onCreate(Bundle savedInstanceState) {
AttemptsInfo = findViewById(R.id.noAttempts);
Login = findViewById(R.id.loginbutton);
Register = findViewById(R.id.registerbutton);
RememberMe = findViewById(R.id.RememberMe);

userAccount = new UserAccount();

sharedPreferences = getApplicationContext().getSharedPreferences("UserAccount", MODE_PRIVATE);
sharedPreferencesEditor = sharedPreferences.edit();

// Check to see if the shared preferences file exists
if(sharedPreferences != null) {

Map<String, ?> preferencesMap = sharedPreferences.getAll();

if(preferencesMap.size() != 0) {
userAccount.loadAccount(preferencesMap);
}

String savedUsername = sharedPreferences.getString("SavedUsername", "");
String savedPassword = sharedPreferences.getString("SavedPassword", "");

if(sharedPreferences.getBoolean("Checkbox", false)) {
Name.setText(savedUsername);
Password.setText(savedPassword);
RememberMe.setChecked(true);
}
}

// When login button is clicked
// When login button is clicked
Login.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Expand Down Expand Up @@ -154,20 +119,7 @@ public void onClick(View view) {
}
});

// If the 'Remember Me' checkbox is checked..
RememberMe.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
sharedPreferencesEditor.putBoolean("RememberMeCheckbox", RememberMe.isChecked());
sharedPreferencesEditor.apply();
}
});
}

private boolean validate(String userName, String userPassword) {
return userAccount.checkAccount(userName, userPassword); // moved validate from here to the UserAccount.java
}

public static String getCurrentUserName() {
return userName;
}
Expand Down
24 changes: 10 additions & 14 deletions app/src/main/java/edu/sc/purplelimited/RegistrationActivity.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
package edu.sc.purplelimited;

import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

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

Expand All @@ -24,13 +22,9 @@ public class RegistrationActivity extends AppCompatActivity {
private EditText RegistrationPassword;
private EditText RegistrationPassword2;
private Button Register2;
private Button Back;
private static FirebaseDatabase database;
private static DatabaseReference usersReference;
/*
public UserAccount userAccount;
SharedPreferences sharedPreferences;
SharedPreferences.Editor sharedPreferencesEditor;
*/

@Override
protected void onCreate(Bundle savedInstanceState) {
Expand All @@ -42,13 +36,7 @@ protected void onCreate(Bundle savedInstanceState) {
RegistrationPassword = findViewById(R.id.RegistrationPassword);
RegistrationPassword2 = findViewById(R.id.RegistrationPassword2);
Register2 = findViewById(R.id.logoutbutton);

/*
userAccount = new UserAccount();

sharedPreferences = getApplicationContext().getSharedPreferences("UserAccount", MODE_PRIVATE);
sharedPreferencesEditor = sharedPreferences.edit();
*/
Back = findViewById(R.id.backbutton);

// Instantiate Firebase database instance and users reference
database = FirebaseDatabase.getInstance();
Expand Down Expand Up @@ -90,6 +78,14 @@ public void onCancelled(@NonNull DatabaseError error) {/*empty*/}
}
}
});
// Clicking the Back Button
Back.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
// Go to Login Activity
startActivity(new Intent(RegistrationActivity.this, LoginActivity.class));
}
});
}

boolean validate(String name, String password, String password2)
Expand Down
35 changes: 0 additions & 35 deletions app/src/main/java/edu/sc/purplelimited/UserAccount.java

This file was deleted.

18 changes: 7 additions & 11 deletions app/src/main/res/layout/activity_login.xml
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,9 @@
android:shadowDy="2"
android:shadowRadius="5"
android:textColor="@color/white"
android:textColorHint="@color/white" />
android:textColorHint="@color/white"
android:digits="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890!@#$%^*()-+=_"
/>

<EditText
android:id="@+id/userPassword"
Expand All @@ -81,7 +83,8 @@
android:shadowDy="2"
android:shadowRadius="5"
android:textColor="@color/white"
android:textColorHint="@color/white" />
android:textColorHint="@color/white"
android:digits="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890!@#$%^*()-+=_"/>

<com.google.android.material.button.MaterialButton
android:id="@+id/#button"
Expand Down Expand Up @@ -115,16 +118,9 @@
android:shadowDy="2"
android:shadowRadius="5"
android:text="Number of attempts remaining: 3"
android:textStyle="bold"
android:textColor="@color/white" />

<CheckBox
android:id="@+id/RememberMe"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/userPassword"
android:layout_marginTop="24dp"
android:layout_marginEnd="10dp"
android:text="Remember Me" />


</RelativeLayout>
</RelativeLayout>
44 changes: 34 additions & 10 deletions app/src/main/res/layout/activity_registration.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,19 @@

<TextView
android:id="@+id/PassText"
android:layout_width="313dp"
android:layout_height="20dp"
android:layout_width="407dp"
android:layout_height="56dp"
android:layout_below="@id/RegistrationPassword2"
android:layout_marginStart="49dp"
android:layout_marginTop="200dp"
android:layout_marginEnd="49dp"
android:text="Passwords should be a minimum of 8 characters long"
app:layout_constraintBottom_toTopOf="@+id/RegistrationPassword2"
android:padding="20dp"
android:shadowColor="@color/black"
android:text="Passwords should be a minimum of 8 characters"
android:textStyle="bold"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.351"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/RegistrationPassword" />
app:layout_constraintTop_toBottomOf="@+id/RegistrationPassword2" />

<EditText
android:id="@+id/RegistrationName"
Expand All @@ -61,7 +63,8 @@
app:layout_constraintBottom_toTopOf="@+id/RegistrationPassword"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/TopText" />
app:layout_constraintTop_toBottomOf="@+id/TopText"
android:digits="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890!@#$%^*()-+=_"/>

<EditText
android:id="@+id/RegistrationPassword"
Expand All @@ -83,7 +86,8 @@
app:layout_constraintBottom_toTopOf="@+id/RegistrationPassword2"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/RegistrationName" />
app:layout_constraintTop_toBottomOf="@+id/RegistrationName"
android:digits="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890!@#$%^*()-+=_"/>

<EditText
android:id="@+id/RegistrationPassword2"
Expand All @@ -105,7 +109,8 @@
app:layout_constraintBottom_toTopOf="@+id/logoutbutton"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/RegistrationPassword" />
app:layout_constraintTop_toBottomOf="@+id/RegistrationPassword"
android:digits="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890!@#$%^*()-+=_"/>

<Button
android:id="@+id/logoutbutton"
Expand All @@ -128,4 +133,23 @@
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/RegistrationPassword2" />

</androidx.constraintlayout.widget.ConstraintLayout>
<Button
android:id="@+id/backbutton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/logoutbutton"
android:layout_centerHorizontal="true"
android:backgroundTint="@color/design_default_color_secondary"
android:shadowColor="@color/black"
android:shadowDx="2"
android:shadowDy="2"
android:shadowRadius="5"
android:text="Back"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.498"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/RegistrationPassword2"
app:layout_constraintVertical_bias="0.415" />

</androidx.constraintlayout.widget.ConstraintLayout>