Skip to content

Commit

Permalink
Add fix for empty pass/email crash bug
Browse files Browse the repository at this point in the history
  • Loading branch information
1HazArd1 committed Feb 26, 2022
1 parent c046fc4 commit 218cfc6
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 24 deletions.
1 change: 1 addition & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

29 changes: 21 additions & 8 deletions app/src/main/java/com/hazard/samarpan/LoginFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -60,15 +60,28 @@ class LoginFragment: Fragment() {
password?.error = "Password cannot be empty"
}
else{
registerAuth.signInWithEmailAndPassword(mail,pass).addOnCompleteListener{ task ->
try {
registerAuth.signInWithEmailAndPassword(mail, pass)
.addOnCompleteListener { task ->

if(task.isSuccessful){
// logic for navigating to the dashboard
Toast.makeText(activity,"Logged in Successfully", Toast.LENGTH_SHORT).show()
}
else{
Toast.makeText(activity,task.exception!!.message.toString(), Toast.LENGTH_SHORT).show()
}
if (task.isSuccessful) {
// logic for navigating to the dashboard
Toast.makeText(
activity,
"Logged in Successfully",
Toast.LENGTH_SHORT
).show()
} else {
Toast.makeText(
activity,
task.exception!!.message.toString(),
Toast.LENGTH_SHORT
).show()
}
}
}
catch (e:IllegalArgumentException){
Toast.makeText(context,"Fields cannot be empty",Toast.LENGTH_SHORT)
}
}
}
Expand Down
1 change: 1 addition & 0 deletions app/src/main/java/com/hazard/samarpan/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ class MainActivity : AppCompatActivity() {
setTheme(R.style.Theme_Samarpan)
setContentView(R.layout.activity_main)
addFragment()

}

private fun addFragment() {
Expand Down
45 changes: 29 additions & 16 deletions app/src/main/java/com/hazard/samarpan/UserRegisterFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import android.widget.Button
import android.widget.LinearLayout
import android.widget.Toast
import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentManager
import com.google.android.gms.tasks.OnCompleteListener
import com.google.android.material.textfield.TextInputEditText
import com.google.firebase.auth.AuthResult
Expand Down Expand Up @@ -48,6 +49,7 @@ class UserRegisterFragment: Fragment(){
btnSignIn?.setOnClickListener {
val userLogin=LoginFragment()
activity?.supportFragmentManager?.beginTransaction()?.replace(R.id.fragment_container1,userLogin)?.commit()

}
btnRegister?.setOnClickListener{
val mail=email?.text.toString().trim()
Expand All @@ -64,28 +66,39 @@ class UserRegisterFragment: Fragment(){
if(!(isValidPassword(pass))){
password?.error="Password format is invalid"
}
else{
else {
//user registration
registerAuth.createUserWithEmailAndPassword(mail,pass).addOnCompleteListener(
OnCompleteListener <AuthResult>{ task ->
try {
registerAuth.createUserWithEmailAndPassword(mail, pass).addOnCompleteListener(
OnCompleteListener<AuthResult> { task ->

//if registration is done successfully
if(task.isSuccessful){
Toast.makeText(activity,"You were registered successfully.", Toast.LENGTH_SHORT).show()
/* add the intent to go to the main dashboard of the application and also add finish() so that
//if registration is done successfully
if (task.isSuccessful) {
Toast.makeText(
activity,
"You were registered successfully.",
Toast.LENGTH_SHORT
).show()
/* add the intent to go to the main dashboard of the application and also add finish() so that
if the user presses back after registration they don't go back to the registration page
it basically clears all the previous activities
*/
}
// if the registration failed somehow
else{
Toast.makeText(activity,
task.exception!!.message.toString(),
Toast.LENGTH_SHORT).show()
}
}
// if the registration failed somehow
else {
Toast.makeText(
activity,
task.exception!!.message.toString(),
Toast.LENGTH_SHORT
).show()
}

}
)
}
)
}
catch(e:IllegalArgumentException){
Toast.makeText(context,"Fields cannot be empty",Toast.LENGTH_SHORT)
}
}
}
return itemView
Expand Down

0 comments on commit 218cfc6

Please sign in to comment.