-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
User Authentication feature added...
- Loading branch information
Showing
11 changed files
with
463 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
117 changes: 116 additions & 1 deletion
117
app/src/main/java/com/mr_17/queezy/activity/CreateAccountActivity.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
} | ||
} |
Oops, something went wrong.