fun findUserId(name: String, email: String) {
Log.d(TAG,"AppRepository - findUserId() called")
val firebaseDatabase = RealTimeDatabase.getDatabase().child("Users")
firebaseDatabase.orderByChild("name").equalTo(name).get().addOnCompleteListener { task ->
if (task.isSuccessful) {
val snapshot = task.result
var userName: String? = null
var userEmail: String? = null
var userId: String? = null
snapshot?.children?.forEach { it ->
it.children.forEach { children ->
if (children.key.equals("name")) userName = children.getValue(String::class.java)
else if (children.key.equals("email")) userEmail = children.getValue(String::class.java)
else if (children.key.equals("id")) userId = children.getValue(String::class.java)
}
}
Log.d(TAG, "findUserId: name : $name email : ${email}\n$userName : $userName userEmail : $userEmail")
if (userName.equals(name) && userEmail.equals(email)) {
Log.d(TAG,"AppRepository - $name $email")
Toast.makeText(application.applicationContext, "찾으시는 아이디는 ${userId}입니다.", Toast.LENGTH_SHORT).show()
} else {
Toast.makeText(application.applicationContext, "일치하는 회원이 존재하지 않습니다.", Toast.LENGTH_SHORT).show()
}
}
}
}
728x90
반응형
'팀프로젝트 > Cando' 카테고리의 다른 글
캔두프로젝트 - 헤로쿠로 메시징 서버 배포하기 (0) | 2022.09.12 |
---|---|
캔두프로젝트 - 글 조회 (0) | 2021.10.25 |
캔두 프로젝트 - 추가할 기능들 (0) | 2021.10.13 |
캔두 프로젝트 개요 (0) | 2021.08.24 |