added field validation

This commit is contained in:
IvanaE 2018-10-21 16:34:47 -04:00
parent b5558cd3a7
commit 846df76cdb
3 changed files with 48 additions and 28 deletions

View file

@ -20,6 +20,8 @@ public class LogIn extends AppCompatActivity {
String password = ((EditText) findViewById(R.id.PasswordInput)).getText().toString();
DBHelper dbHelper = new DBHelper(this);
Intent intent = new Intent(getApplicationContext(),Welcome.class);
if(username.matches("[a-zA-Z0-9]*")&&password.matches("[a-zA-Z0-9]*")
&& password.length()>0 && username.length()>0) {
if (dbHelper.findUserByUsername(username) != null) {
if (dbHelper.findUserByUsername(username).getUsername().equals(username) &&
dbHelper.findUserByUsername(username).getPassword().equals(password)) {
@ -30,11 +32,16 @@ public class LogIn extends AppCompatActivity {
} else {
Toast.makeText(this, "Wrong Password", Toast.LENGTH_LONG).show();
}
}
else{
} else {
Toast.makeText(this, "Account does not exist", Toast.LENGTH_LONG).show();
}
}
else if(username.length()==0 || password.length()==0){
Toast.makeText(this, "Fields cannot be empty", Toast.LENGTH_LONG).show();
}
else{
Toast.makeText(this, "Fields may only contain alphanumeric values", Toast.LENGTH_LONG).show();
}
}

View file

@ -32,6 +32,8 @@ public class SignUp extends AppCompatActivity {
String lastname = ((EditText) findViewById(R.id.LastNameInput)).getText().toString();
MaterialSpinner spinner = findViewById(R.id.RoleInput);
//TODO add message conditional to check if every EditText is filled up to standards
if(username.length()>=5 && password.length()>5 && firstname.length()>0 && lastname.length()>0 && username.matches("[a-zA-Z0-9]*") && password.matches("[a-zA-Z0-9]*")
&& firstname.matches("[a-zA-Z0-9]*") && lastname.matches("[a-zA-Z0-9]*")){
switch(spinner.getText().toString()){
case "User":
newUser = new User(username,password,firstname,lastname);
@ -52,6 +54,17 @@ public class SignUp extends AppCompatActivity {
}else{
Toast.makeText(this,"Username is taken",Toast.LENGTH_LONG).show();
}
}
else if(firstname.length()==0 || lastname.length()==0 || username.length()==0 || password.length()==0){
Toast.makeText(this, "Fields cannot be empty", Toast.LENGTH_LONG).show();
}
else if (username.length()<=5 || password.length()<=5 ){
Toast.makeText(this, "Password and username must be longer than 5 characters", Toast.LENGTH_LONG).show();
}
else{
Toast.makeText(this, "Fields may only contain alphanumeric values", Toast.LENGTH_LONG).show();
}
}

View file

@ -45,10 +45,10 @@
android:layout_height="50dp"
android:layout_marginBottom="20dp"
android:gravity="center"
android:text="You are logged in as"
android:text="You are logged in as a"
android:textAppearance="@style/TextAppearance.AppCompat.Large"
android:textColor="@android:color/white"
android:textSize="30sp"
android:textSize="18sp"
app:fontFamily="@font/julius_sans_one" />
<TextView