Skip to content

Commit

Permalink
User Authentication feature added...
Browse files Browse the repository at this point in the history
  • Loading branch information
theMr17 committed Dec 13, 2022
1 parent 50808f5 commit 107b92e
Show file tree
Hide file tree
Showing 11 changed files with 463 additions and 35 deletions.
6 changes: 3 additions & 3 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
plugins {
id 'com.android.application'
id 'org.jetbrains.kotlin.android'
id 'com.google.gms.google-services'
}

android {
Expand Down Expand Up @@ -38,14 +39,13 @@ dependencies {
implementation 'androidx.appcompat:appcompat:1.5.1'
implementation 'com.google.android.material:material:1.7.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
implementation 'com.google.firebase:firebase-auth-ktx:21.1.0'
implementation 'com.google.firebase:firebase-database-ktx:20.1.0'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.4'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.0'

//retrofit
implementation "com.squareup.retrofit2:retrofit:2.3.0"
implementation "com.squareup.retrofit2:adapter-rxjava2:2.3.0"
implementation "com.squareup.retrofit2:converter-gson:2.3.0"

implementation "io.reactivex.rxjava2:rxandroid:2.0.1"
}
39 changes: 39 additions & 0 deletions app/google-services.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
{
"project_info": {
"project_number": "1052295142832",
"project_id": "the-queezy",
"storage_bucket": "the-queezy.appspot.com"
},
"client": [
{
"client_info": {
"mobilesdk_app_id": "1:1052295142832:android:67543867b7d271c290ca75",
"android_client_info": {
"package_name": "com.mr_17.queezy"
}
},
"oauth_client": [
{
"client_id": "1052295142832-2tslr5nmi1fb05cgvlrel7sjcho997e4.apps.googleusercontent.com",
"client_type": 3
}
],
"api_key": [
{
"current_key": "AIzaSyBmMSRHFeAgMKNknVjizr92oCcVr9AyRaU"
}
],
"services": {
"appinvite_service": {
"other_platform_oauth_client": [
{
"client_id": "1052295142832-2tslr5nmi1fb05cgvlrel7sjcho997e4.apps.googleusercontent.com",
"client_type": 3
}
]
}
}
}
],
"configuration_version": "1"
}
24 changes: 16 additions & 8 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,49 +16,56 @@
tools:targetApi="31">
<activity
android:name=".activity.SolutionsActivity"
android:exported="false">
android:exported="false"
android:screenOrientation="portrait">
<meta-data
android:name="android.app.lib_name"
android:value="" />
</activity>
<activity
android:name=".activity.StatsActivity"
android:exported="false">
android:exported="false"
android:screenOrientation="portrait">
<meta-data
android:name="android.app.lib_name"
android:value="" />
</activity>
<activity
android:name=".activity.QuizActivity"
android:exported="false">
android:exported="false"
android:screenOrientation="portrait">
<meta-data
android:name="android.app.lib_name"
android:value="" />
</activity>
<activity
android:name=".activity.CreateAccountActivity"
android:exported="false">
android:exported="false"
android:screenOrientation="portrait">
<meta-data
android:name="android.app.lib_name"
android:value="" />
</activity>
<activity
android:name=".activity.LoginActivity"
android:exported="false">
android:exported="false"
android:screenOrientation="portrait">
<meta-data
android:name="android.app.lib_name"
android:value="" />
</activity>
<activity
android:name=".activity.WelcomeActivity"
android:exported="false">
android:exported="false"
android:screenOrientation="portrait">
<meta-data
android:name="android.app.lib_name"
android:value="" />
</activity>
<activity
android:name=".activity.SplashActivity"
android:exported="true">
android:exported="true"
android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

Expand All @@ -71,7 +78,8 @@
</activity>
<activity
android:name=".activity.MainActivity"
android:exported="false">
android:exported="false"
android:screenOrientation="portrait">
<meta-data
android:name="android.app.lib_name"
android:value="" />
Expand Down
117 changes: 116 additions & 1 deletion app/src/main/java/com/mr_17/queezy/activity/CreateAccountActivity.kt
Original file line number Diff line number Diff line change
@@ -1,12 +1,127 @@
package com.mr_17.queezy.activity

import androidx.appcompat.app.AppCompatActivity
import android.app.Activity
import android.app.ProgressDialog
import android.content.Intent
import android.os.Bundle
import android.text.TextUtils
import android.widget.Button
import android.widget.EditText
import android.widget.Toast
import androidx.appcompat.widget.Toolbar
import androidx.appcompat.app.AppCompatActivity
import com.google.android.gms.tasks.OnCompleteListener
import com.google.firebase.auth.FirebaseAuth
import com.google.firebase.database.DatabaseReference
import com.google.firebase.database.FirebaseDatabase
import com.mr_17.queezy.R
import com.mr_17.queezy.model.FirebaseModel

class CreateAccountActivity : AppCompatActivity() {

private var toolbar: Toolbar? = null
private var createAccountButton: Button? = null

private var firstName: EditText? = null
private var lastName:EditText? = null
private var userEmail:EditText? = null
private var userPassword:EditText? = null
private var confirmUserPassword:EditText? = null

private var myAuth: FirebaseAuth? = null
private var rootRef: DatabaseReference? = null

private var loadingBar: ProgressDialog? = null

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_create_account)

myAuth = FirebaseAuth.getInstance()
rootRef = FirebaseDatabase.getInstance().getReference()

InitializeFields()

createAccountButton!!.setOnClickListener{ CreateNewAccount() }

toolbar!!.setNavigationOnClickListener { onBackPressed() }
}

private fun InitializeFields() {
toolbar = findViewById(R.id.toolbar)
createAccountButton = findViewById(R.id.create_account_button)
firstName = findViewById(R.id.first_name_edittext)
lastName = findViewById(R.id.last_name_edittext)
userEmail = findViewById(R.id.email_address_edittext)
userPassword = findViewById(R.id.password_edittext)
confirmUserPassword = findViewById(R.id.confirm_password_edittext)

loadingBar = ProgressDialog(this)
}

private fun CreateNewAccount() {
val email = userEmail!!.text.toString()
val password = userPassword!!.text.toString()
val confirmPassword = confirmUserPassword!!.text.toString()
val first_Name = firstName!!.text.toString()
val last_Name = lastName!!.text.toString()

if (TextUtils.isEmpty(email)) {
Toast.makeText(this, "Email Required...", Toast.LENGTH_LONG).show()
} else if (TextUtils.isEmpty(password)) {
Toast.makeText(this, "Password Required...", Toast.LENGTH_LONG).show()
} else if (TextUtils.isEmpty(confirmPassword)) {
Toast.makeText(this, "Password Confirmation Required...", Toast.LENGTH_LONG).show()
} else if (TextUtils.isEmpty(first_Name)) {
Toast.makeText(this, "First Name Required...", Toast.LENGTH_LONG).show()
} else if (TextUtils.isEmpty(last_Name)) {
Toast.makeText(this, "Last Name Required...", Toast.LENGTH_LONG).show()
} else if (password != confirmPassword) {
Toast.makeText(this, "Passwords Mismatch...", Toast.LENGTH_LONG).show()
} else {
loadingBar!!.setTitle("Creating New Account")
loadingBar!!.setMessage("Please wait, while we are creating a new account for you...")
loadingBar!!.setCanceledOnTouchOutside(false)
loadingBar!!.show()
myAuth!!.createUserWithEmailAndPassword(email, password)
.addOnCompleteListener { task ->
if (task.isSuccessful) {
val currentUserID = myAuth!!.currentUser!!.uid
val profileMap = HashMap<String, String>()
profileMap[FirebaseModel.node_uid] = currentUserID
profileMap[FirebaseModel.node_firstName] = first_Name
profileMap[FirebaseModel.node_lastName] = last_Name

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
FirebaseModel.databaseRef_users.child(currentUserID)
.setValue("") // test this
//rootRef.child("Programs").child("subTopics").child("VIII").setValue("");
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
FirebaseModel.databaseRef_users.child(currentUserID).setValue(profileMap)
.addOnCompleteListener(
OnCompleteListener<Void?> {
SendToActivity(LoginActivity::class.java, false)
Toast.makeText(
this@CreateAccountActivity,
"Account Created Successfully. Login to continue.",
Toast.LENGTH_LONG
).show()
loadingBar!!.dismiss()
})
} else {
val message = task.exception!!.message
Toast.makeText(this@CreateAccountActivity, "Error: $message", Toast.LENGTH_LONG)
.show()
loadingBar!!.dismiss()
}
}
}
}

private fun SendToActivity(activityClass: Class<out Activity?>, backEnabled: Boolean) {
val intent = Intent(this, activityClass)
if (!backEnabled) intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TASK)
startActivity(intent)
if (!backEnabled) finish()
}
}
Loading

0 comments on commit 107b92e

Please sign in to comment.