codice:
public class SignupActivity extends AppCompatActivity {
private static final String TAG = "SignupActivity";
public User u;
public String nome, mail, password,conferma;
EditText email;
EditText pass;
EditText name;
Button button1;
TextView text1;
EditText confirm;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_signup);
//ButterKnife.bind(this);
final MySQLiteHelper db = new MySQLiteHelper(this);
button1 = (Button) findViewById(R.id.btn_signup);
text1 = (TextView) findViewById(R.id.link_login);
email = (EditText) findViewById(R.id.input_email);
pass = (EditText) findViewById(R.id.input_password);
name = (EditText) findViewById(R.id.input_name);
confirm = (EditText)findViewById(R.id.conf_password);
button1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
nome = name.getText().toString();
mail = email.getText().toString();
password = pass.getText().toString();
conferma = confirm.getText().toString();
if (nome.equals("") || password.equals("") || conferma.equals("") || mail.equals("")) {
//Toast.makeText(getApplicationContext(), "Campo mancante, reinserire", Toast.LENGTH_LONG).show();
final ProgressDialog progressDialog = new ProgressDialog(SignupActivity.this, R.style.AppTheme_Dark_Dialog);
progressDialog.setIndeterminate(true);
progressDialog.setMessage("Campo mancante, Reinserire..");
progressDialog.show();
return;
}
if (!password.equals(conferma)) {
//Toast.makeText(getApplicationContext(), "Le password non coincidono", Toast.LENGTH_LONG).show();
final ProgressDialog progressDialog = new ProgressDialog(SignupActivity.this, R.style.AppTheme_Dark_Dialog);
progressDialog.setIndeterminate(true);
progressDialog.setMessage("Le password non coincidono, reinserire..");
progressDialog.show();
return;
}
else {
/*
db.ExistingUser(mail);
final ProgressDialog progressDialog = new ProgressDialog(SignupActivity.this, R.style.AppTheme_Dark_Dialog);
progressDialog.setIndeterminate(true);
progressDialog.setMessage("Email già in uso..");
progressDialog.show();
*/
// Save the Data in Database
db.addUser(new User(nome, mail, password));
//Toast.makeText(getApplicationContext(), "Account Creato Correttamente ", Toast.LENGTH_LONG).show();
final ProgressDialog progressDialog2 = new ProgressDialog(SignupActivity.this, R.style.AppTheme_Dark_Dialog);
progressDialog2.setIndeterminate(true);
progressDialog2.setMessage("Registrazione Effettuata..");
progressDialog2.show();
}
Intent intentLogin = new Intent(getApplicationContext(), LoginActivity.class);
startActivity(intentLogin);
// Register(context);
}
});
text1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// Finish the registration screen and return to the Login activity
// finish();
}
});
}
@Override
protected void onDestroy() {
// TODO Auto-generated method stub
super.onDestroy();
}
}
Database Helper
codice:
/**
* Created by christian on 27/01/2016.
*/
public class MySQLiteHelper extends SQLiteOpenHelper {
//database version
private static final int DATABASE_VERSION = 1;
//database name
private static final String DATABASE_NAME = "ToDoNotes";
public MySQLiteHelper(Context context){
super(context, DATABASE_NAME, null, DATABASE_VERSION);
}
@Override
/**
* Metodo per creare la tabella ToDoNotes_Users
*/
public void onCreate(SQLiteDatabase db){
String CREATE_TODONOTES_USERS = "CREATE TABLE ToDoNotes_Users (" +
"name TEXT, "+
"email TEXT PRIMARY KEY, "+
"password TEXT)" ;
db.execSQL(CREATE_TODONOTES_USERS);
}
@Override
/**
* Il metodo OnUpgrade elimina la tabella se già presente per crearne una nuova
*/
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion){
db.execSQL("DROP TABLE IF EXISTS ToDoNotes_Users");
this.onCreate(db);
}
//Tabella Utenti
public static final String TABLE_USERS = "ToDoNotes_Users";
// Colonne tabella utenti
private static final String name = "name";
private static final String email = "email";
private static final String password = "password";
//private static final String code ="captcha";
/**
* Il metodo inserisce gli utenti nella tabella del database
*/
public void addUser(User u){
Log.d("Utenti", u.toString());
SQLiteDatabase db = this.getWritableDatabase();
ContentValues values = new ContentValues();
values.put(name, u.getName());
values.put(email, u.getEmail());
values.put(password, u.getPassword());
db.insert(TABLE_USERS, null, values);
db.close();
}
public User ExistingUser(String mail){
// metodo per vedere se un utente è già registrato
Log.d("Verifica", email);
SQLiteDatabase db = this.getReadableDatabase();
//String sql = "SELECT email from ToDoNotes_Users Where email=?";
Cursor cursor = db.query(TABLE_USERS, new String[]{name,email,password}, "email = ?", new String[]{mail}, null, null, null, null);
if(cursor != null)
cursor.moveToFirst();
User user = new User();
user.setName(cursor.getString(0));
user.setEmail(cursor.getString(1));
user.setPassword(cursor.getColumnName(2));
Log.d("verifica", user.toString());
return user;
}
}
queste sono le due classi che sto usando per registrare gli utenti e verificare che essi già ci siano...
poi un'altra domanda....la libreria SendEmail di java si può usare con android studio?? e soprattutto come posso creare un'altra tabella SQLite che usa la mia primary key come foreign key su un'altra tabella??
perché voglio creare la tabella "ATTIVAZIONI" dove presa la mail viene associato il codice registrazione ricevuto via email...
Grazie a chiunque mi risponda