IanTDuncan / MealTime

Project for CSC 480
0 stars 0 forks source link

Database Updating On Login - Backend Development #125

Closed Cade5480 closed 6 months ago

Cade5480 commented 7 months ago

Database Updating On Login

Description:

After the database connection is established, I need to test it with adding functionality to the login to make sure it stores and saves the userID from login

Steps to Reproduce:

We are just going to simply create a login at the main page and test if it stores correctly

Expected vs. Actual Behavior:

Expected Behavior: That on login, the userID will be stored into our database

Code snippets:

` buttonLogin.setOnClickListener { // This is the beginning of our login logic, simple checking. val username = editTextUsername.text.toString() val password = editTextPassword.text.toString()

        // Example: Check if username and password are not empty
        if (username.isNotEmpty() && password.isNotEmpty()) {
            // Open the database for reading
            val db = SQLiteOpenHelper.readableDatabase

            // Query the database to check if the provided username and password match
            val selection = "username = ? AND password = ?"
            val selectionArgs = arrayOf(username, password)
            val cursor = db.query("User", null, selection, selectionArgs, null, null, null)

            if (cursor.moveToFirst()) {
                // Username and password match, login successful
                Toast.makeText(this, "Login successful", Toast.LENGTH_SHORT).show()
                val intent = Intent(this, MainMenuActivity::class.java)
                startActivity(intent)
            } else {
                // Username and password do not match, login unsuccessful
                Toast.makeText(this, "Invalid username or password", Toast.LENGTH_SHORT).show()
            }

            // Close the cursor and database connections when done
            cursor.close()
            db.close()
        } else {
            Toast.makeText(this, "Please enter username and password", Toast.LENGTH_SHORT).show()
        }
    }`

Environment Details:

IDE: Android Studio SDK: 34.1.2

Issue Resolution:

N/A

Current Status: Complete

Cade5480 commented 7 months ago

Forgot to update this after working on it over the weekend, will update it as soon as I get home after class

aaleksandraristic commented 7 months ago

Hey @Cade5480 , just to check if you could please update this issue and also let me know if we need to expend a due date, bc tomorrow is a due date for this issue.

Cade5480 commented 6 months ago

I have managed to update the logic to query the database for username and password, will not commit yet until registration side is done

aaleksandraristic commented 6 months ago

Is this function gonna track when the user logged in?