diff --git a/OlympusServices/app/src/main/java/com/uottawa/olympus/olympusservices/LogIn.java b/OlympusServices/app/src/main/java/com/uottawa/olympus/olympusservices/LogIn.java index e864cb7..7eaf0d6 100644 --- a/OlympusServices/app/src/main/java/com/uottawa/olympus/olympusservices/LogIn.java +++ b/OlympusServices/app/src/main/java/com/uottawa/olympus/olympusservices/LogIn.java @@ -20,21 +20,28 @@ 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 (dbHelper.findUserByUsername(username).getUsername().equals(username) && - dbHelper.findUserByUsername(username).getPassword().equals(password)) { - intent.putExtra("username", username); - startActivity(intent); + 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); + startActivity(intent); + } else { + Toast.makeText(this, "Wrong Password", Toast.LENGTH_LONG).show(); + } } else { - Toast.makeText(this, "Wrong Password", Toast.LENGTH_LONG).show(); + Toast.makeText(this, "Account does not exist", Toast.LENGTH_LONG).show(); } } - 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(); } - } diff --git a/OlympusServices/app/src/main/java/com/uottawa/olympus/olympusservices/SignUp.java b/OlympusServices/app/src/main/java/com/uottawa/olympus/olympusservices/SignUp.java index 6f7048b..a009f14 100644 --- a/OlympusServices/app/src/main/java/com/uottawa/olympus/olympusservices/SignUp.java +++ b/OlympusServices/app/src/main/java/com/uottawa/olympus/olympusservices/SignUp.java @@ -32,26 +32,39 @@ 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 - switch(spinner.getText().toString()){ - case "User": - newUser = new User(username,password,firstname,lastname); - break; - case "Service Provider": - newUser = new ServiceProvider(username,password,firstname,lastname); - break; - default: - newUser = new User(username,password,firstname,lastname); //if nothing is enter then defaults to user role. - break; + 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); + break; + case "Service Provider": + newUser = new ServiceProvider(username,password,firstname,lastname); + break; + default: + newUser = new User(username,password,firstname,lastname); //if nothing is enter then defaults to user role. + break; + } + + DBHelper dbHelper = new DBHelper(this); + Intent intent = new Intent(getApplicationContext(),LogIn.class); //TODO check if signup should take to the login page or automatically login + if(dbHelper.addUser(newUser)){ + startActivityForResult(intent,0); + }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(); } - DBHelper dbHelper = new DBHelper(this); - Intent intent = new Intent(getApplicationContext(),LogIn.class); //TODO check if signup should take to the login page or automatically login - if(dbHelper.addUser(newUser)){ - startActivityForResult(intent,0); - }else{ - Toast.makeText(this,"Username is taken",Toast.LENGTH_LONG).show(); - } } diff --git a/OlympusServices/app/src/main/res/layout/activity_welcome.xml b/OlympusServices/app/src/main/res/layout/activity_welcome.xml index c65739b..a3af569 100644 --- a/OlympusServices/app/src/main/res/layout/activity_welcome.xml +++ b/OlympusServices/app/src/main/res/layout/activity_welcome.xml @@ -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" />