기본 UI와 Firebase를 이용한 이메일 로그인 기능을 구현하였습니다.
<EditText
android:id="@+id/emailEditText"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"
android:layout_width="0dp"
android:layout_height="wrap_content"/>
<EditText
android:id="@+id/passwordEditText"
app:layout_constraintStart_toStartOf="parent"
android:inputType="textPassword"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@+id/emailEditText"
android:layout_width="0dp"
android:layout_height="wrap_content"/>
<Button
android:id="@+id/loginButton"
android:text="로그인"
app:layout_constraintTop_toBottomOf="@+id/passwordEditText"
app:layout_constraintEnd_toEndOf="parent"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<Button
android:id="@+id/signUpButton"
android:text="회원가입"
android:layout_marginEnd="4dp"
app:layout_constraintTop_toBottomOf="@+id/passwordEditText"
app:layout_constraintEnd_toStartOf="@+id/loginButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
private fun initEmailAndPasswordEditText() {
val emailEditText =findViewById<EditText>(R.id.emailEditText)
val passwordEditText = findViewById<EditText>(R.id.passwordEditText)
val loginButton = findViewById<Button>(R.id.loginButton)
val signUpButton = findViewById<Button>(R.id.signUpButton)
emailEditText.addTextChangedListener {
val enable = emailEditText.text.isNotEmpty() && passwordEditText.text.isNotEmpty()
loginButton.isEnabled = enable
signUpButton.isEnabled = enable
}
}
private fun initLoginButton() {
val loginButton = findViewById<Button>(R.id.loginButton)
loginButton.setOnClickListener {
val email = getInputEmail()
val password = getInputPassword()
auth.signInWithEmailAndPassword(email, password)
.addOnCompleteListener(this) { task ->
if(task.isSuccessful){
finish()
}else{
Toast.makeText(this, "로그인에 실패했습니다. 이메일 또는 비밀번호를 확인해주세요.",Toast.LENGTH_SHORT).show()
}
}
}
}
private fun initSignUpButton() {
val signUpButton = findViewById<Button>(R.id.signUpButton)
signUpButton.setOnClickListener {
val email = getInputEmail()
val password = getInputPassword()
auth.createUserWithEmailAndPassword(email, password)
.addOnCompleteListener(this) { task->
if(task.isSuccessful){
Toast.makeText(this,"회원가입에 성공했습니다.", Toast.LENGTH_SHORT).show()
}else{
Toast.makeText(this,"이미 가입한 이메일이거나, 회원가입에 실패했습니다.", Toast.LENGTH_SHORT).show()
}
}
}
}
private fun getInputEmail(): String{
return findViewById<EditText>(R.id.emailEditText).text.toString()
}
private fun getInputPassword(): String{
return findViewById<EditText>(R.id.passwordEditText).text.toString()
}
패스트캠퍼스 바로가기 -> https://bit.ly/3FVdhDa
본 포스팅은 패스트캠퍼스 환급 챌린지 참여를 위해 작성되었습니다.
'패스트캠퍼스 챌린지' 카테고리의 다른 글
[패스트캠퍼스 챌린지 28일차] Android tinder DB 설정 (0) | 2021.11.28 |
---|---|
[패스트캠퍼스 캠퍼스 27일차] Android tinder Facebook Login (0) | 2021.11.27 |
[패스트캠퍼스 챌린지 25일차] Android tinder app 설정 (0) | 2021.11.25 |
[패스트캠퍼스 챌린지 24일차] Android book review 마무리 (0) | 2021.11.24 |
[패스트캠퍼스 챌린지 23일차] Android book review (0) | 2021.11.23 |