package monnethic.mobile.homepage; import android.content.Intent; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.view.View; import android.widget.Button; import android.widget.EditText; import android.widget.Toast; import com.example.monnthic.monnethicmobile.R; import monnethic.mobile.database.User; import monnethic.mobile.user.UserAccountActivity; public class RegisterActivity extends AppCompatActivity { private EditText name; private EditText firstname; private EditText email; private EditText confirmEmail; private EditText password; private EditText confirmPassword; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_signup); name = findViewById(R.id.inputName); firstname = findViewById(R.id.inputPrenom); email = findViewById(R.id.inputEmail); confirmEmail = findViewById(R.id.inputConfEmail); password = findViewById(R.id.inputPassword); confirmPassword = findViewById(R.id.inputConfPassword); Button buttonCancel = findViewById(R.id.buttonCancel); Button buttonOk = findViewById(R.id.buttonOk); buttonCancel.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { finish(); } }); buttonOk.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { validateInput(); } }); } //TODO VERIFY EACH EDIT TEXT public void validateInput(){ if(checkInputEmpty()){ if(!InputController.passwordValidator(password.getText().toString())){ Toast.makeText(this, "Password must contains 6 to 20 characters, one lowercase, one uppercase and one digit", Toast.LENGTH_LONG).show(); }else if(InputController.validEmail(email.getText().toString())){ User inputUser = new User(name.getText().toString(),firstname.getText().toString(),email.getText().toString(),password.getText().toString()); insertUserLdap(inputUser); } } } //TODO INSERT VALIDE USER INTO LDAP private void insertUserLdap(User u){ //CHECK IF USER ALREADY EXIST //IF USER DOESN'T EXIST, INSERT USER INTO LDAP //CHECK RESPONSE OR RESULT OF INSERT //IF SUCCESSFULLY INSERTED INTO LDAP CALL LAUNCHWALLET //TEMPORARY if(InputController.checkUser(u.getEmail())){ Toast.makeText(this, "User already have an account, please log in", Toast.LENGTH_SHORT).show(); }else { Toast.makeText(this, "INSERT", Toast.LENGTH_SHORT).show(); launchUserActivity(1); } } //TODO LAUNCH WALLET ACTIVITY private void launchUserActivity(int ldapId){ //LAUNCH APP WALLET WITH ID USER Intent walletIntent = new Intent(RegisterActivity.this, UserAccountActivity.class); walletIntent.putExtra("idUser", ldapId); RegisterActivity.this.startActivity(walletIntent); finish(); } private boolean checkInputEmpty(){ if(InputController.isEmptyEdit(name)){ Toast.makeText(this, "You did not enter your name", Toast.LENGTH_SHORT).show(); return false; } else if (!InputController.nameValidator(name.getText().toString())){ Toast.makeText(this, "Name must be 4 to 30 character long", Toast.LENGTH_SHORT).show(); return false; } else if(InputController.isEmptyEdit(firstname)){ Toast.makeText(this, "You did not enter your firstname", Toast.LENGTH_SHORT).show(); return false; } else if(InputController.isEmptyEdit(email)){ Toast.makeText(this, "You did not enter your email", Toast.LENGTH_SHORT).show(); return false; } else if(!InputController.validEmail(email.getText().toString())){ Toast.makeText(this, "Your email is invalid", Toast.LENGTH_SHORT).show(); return false; } else if(InputController.isEmptyEdit(confirmEmail)){ Toast.makeText(this, "You did not confirm your email", Toast.LENGTH_SHORT).show(); return false; } else if(InputController.isEmptyEdit(password)){ Toast.makeText(this, "You did not enter your password", Toast.LENGTH_SHORT).show(); return false; } else if(InputController.isEmptyEdit(confirmPassword)){ Toast.makeText(this, "You did not confirm your password", Toast.LENGTH_SHORT).show(); return false; }else { if (!(password.getText().toString().equals(confirmPassword.getText().toString()))) { Toast.makeText(this, "Password don't match confirmation password", Toast.LENGTH_SHORT).show(); return false; } else if (!(email.getText().toString().equals(confirmEmail.getText().toString()))) { Toast.makeText(this, "Email don't match confirmation email", Toast.LENGTH_SHORT).show(); return false; }else{ return true; } } } }