Commit e689cc5e authored by austin.blanke's avatar austin.blanke

Completed Login

parent f2c0c5d0
...@@ -2,6 +2,8 @@ package com.example.bookingapp_austinblanke; ...@@ -2,6 +2,8 @@ package com.example.bookingapp_austinblanke;
import androidx.appcompat.app.AppCompatActivity; import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent; import android.content.Intent;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle; import android.os.Bundle;
import android.view.View; import android.view.View;
import android.widget.EditText; import android.widget.EditText;
...@@ -24,10 +26,21 @@ public class CreateAccountActivity extends AppCompatActivity { ...@@ -24,10 +26,21 @@ public class CreateAccountActivity extends AppCompatActivity {
EditText username = findViewById(R.id.Username); EditText username = findViewById(R.id.Username);
EditText password = findViewById(R.id.Password); EditText password = findViewById(R.id.Password);
connector.addNewUser(username.getText().toString(), password.getText().toString()); if (username.length() == 0 || password.length() == 0){
Toast.makeText(this, "username or password not provided", Toast.LENGTH_SHORT).show();
Intent intent = new Intent(this, LoginActivity.class); }
startActivity(intent); else{
if (connector.usernameRepeat(username.getText().toString())){
Toast.makeText(this, "username already taken", Toast.LENGTH_SHORT).show();
}
else{
connector.addNewUser(username.getText().toString(), password.getText().toString());
Intent intent = new Intent(this, LoginActivity.class);
startActivity(intent);
}
}
} }
} }
...@@ -54,6 +54,24 @@ public class DatabaseConnector extends SQLiteOpenHelper { ...@@ -54,6 +54,24 @@ public class DatabaseConnector extends SQLiteOpenHelper {
} }
public boolean usernameRepeat(String username){
boolean result = false;
String query = "SELECT * FROM " + TABLE_USERS + " WHERE " + COLUMN_USERNAME + " = \"" + username +"\"";
SQLiteDatabase db = this.getWritableDatabase();
Cursor cursor = db.rawQuery(query, null);
if(cursor.getCount() == 0){
result = false;
}
else result = true;
cursor.close();
db.close();
return result;
}
public boolean login(String username, String password) { public boolean login(String username, String password) {
String query = "SELECT * FROM " + TABLE_USERS + " WHERE " + COLUMN_USERNAME + " = \"" + username +"\""; String query = "SELECT * FROM " + TABLE_USERS + " WHERE " + COLUMN_USERNAME + " = \"" + username +"\"";
SQLiteDatabase db = this.getWritableDatabase(); SQLiteDatabase db = this.getWritableDatabase();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment