added field validation
This commit is contained in:
		
							parent
							
								
									b5558cd3a7
								
							
						
					
					
						commit
						846df76cdb
					
				
					 3 changed files with 48 additions and 28 deletions
				
			
		| 
						 | 
				
			
			@ -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();
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    }
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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();
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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…
	
	Add table
		Add a link
		
	
		Reference in a new issue