added field validation
This commit is contained in:
parent
a1d92aa423
commit
4a725dd6d6
3 changed files with 48 additions and 28 deletions
|
@ -20,7 +20,9 @@ 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(dbHelper.findUserByUsername(username)!=null) {
|
||||
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)) {
|
||||
intent.putExtra("username", username);
|
||||
|
@ -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();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue