You are on page 1of 2

package com.example.

sms;

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;

public class Signup extends AppCompatActivity {

EditText fullname,username, email, password, repassword;


Button register;
DBHelper myDB;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_signup);
setTitle("Sign up");

fullname = (EditText) findViewById(R.id.fullname);


username = (EditText) findViewById(R.id.username);
email = (EditText) findViewById(R.id.email);
password = (EditText) findViewById(R.id.password);
repassword = (EditText) findViewById(R.id.repassword);

register = (Button) findViewById(R.id.register);

myDB = new DBHelper(this);


//click listener for register button
register.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String fname = fullname.getText().toString();
String user = username.getText().toString();
String mail = email.getText().toString();
String pass = password.getText().toString();
String repass = repassword.getText().toString();

//checking if any feild is empty or not


if(fname.equals("") || user.equals("") || mail.equals("") ||
pass.equals("") || repass.equals("")){
Toast.makeText(Signup.this, "All fields are required",
Toast.LENGTH_SHORT).show();
}else{
//check if the password and confirm password are matching
if(pass.equals(repass)){

//check if the user exists

Boolean usercheckResult = myDB.checkUsername(user);


if(usercheckResult == false){
//insert data

Boolean regResult = myDB.insertData(fname, user, mail,


pass);
if(regResult == true){
Toast.makeText(Signup.this, "user successfully
registered", Toast.LENGTH_SHORT).show();
Intent intent = new Intent(getApplicationContext(),
Signin.class);
startActivity(intent);
}else{
Toast.makeText(Signup.this, "Registration failed",
Toast.LENGTH_SHORT).show();
}

//insert data

}else{
Toast.makeText(Signup.this, "user already exists",
Toast.LENGTH_SHORT).show();
}
//check if the user exists

}else{
Toast.makeText(Signup.this, "Password doesn't match",
Toast.LENGTH_SHORT).show();
}
//check if the password and confirm password are matching

}
//checking if any feild is empty or not
}
});
//click listener for register button
}
}

You might also like