ARCHIVES

태그

신고하기

상단 메뉴 페이지

기본 콘텐츠로 건너뛰기

2강. Firebase 서버를 통한 Android앱 개발. 메일 로그인


Firebase 서버를 통한 Android앱 개발

메일 회원가입 구현, 인프런 2강



1. 강좌에는 바로 현재 화면에 했지만, 2page 구성을 한다. 회원가입 UI 화면을 구현한다.
   오랜만에 안드로이드를 해봐서 연습삼아 화면을 구현 했다. 


    회원가입, 비밀번호는 6글자 이상이 되어야 한다.
// 이메일/비밀번호로 Firebase에 회원가입
private fun signUpWithEmail() {

val email: String = editTextId.text.toString().trim()
val password: String = editTextPassword.text.toString().trim()

Log.d(TAG, "email = " + email + ", password : " + password )
auth.createUserWithEmailAndPassword(email, password)
.addOnCompleteListener(this) { task ->
if (task.isSuccessful) {
// Sign in success, update UI with the signed-in user's information
Log.d(TAG, "유저가 생성 되었습니다.")
val user = auth.currentUser
//updateUI(user)
// 인증 메일 발송
user?.sendEmailVerification()
// 새로운 계정 생성이 성공하였으므로 기존 계정이 있을 경우 로그아웃 시킴
auth.signOut()
} else {
// If sign in fails, display a message to the user.
Log.w(TAG, "createUserWithEmail:failure", task.exception)
Toast.makeText(baseContext, "Authentication failed.",
Toast.LENGTH_SHORT).show()
//updateUI(null)
}

// ...
}
}

3. 회원가입이 완료되면 파이어 베이스에서 확인 가능 하다.

4. 로그인 페이지에서 로그인 해본다.
private fun signInWithEmailAndPassword() {
val email: String = editTextId.text.toString().trim()
val password: String = editTextPassword.text.toString().trim()

auth.signInWithEmailAndPassword(email, password)
.addOnCompleteListener(this) { task ->
if (task.isSuccessful) {
// Sign in success, update UI with the signed-in user's information
Log.d(TAG, "signInWithEmail:success")
val user = auth.currentUser
// updateUI(user)
} else {
// If sign in fails, display a message to the user.
Log.w(TAG, "signInWithEmail:failure", task.exception)
Toast.makeText(baseContext, "Authentication failed.",
Toast.LENGTH_SHORT).show()
// updateUI(null)
// ...
}

// ...
}
}

완료.

로그인 디자인은 입맛대로 바꾸면 된다.

댓글