Skip to content

Commit

Permalink
[ui/UMC-5th-Coumo#54] : 비밀번호 찾기도 로직거의 완성
Browse files Browse the repository at this point in the history
  • Loading branch information
psw9428 committed Feb 20, 2024
1 parent 2b73150 commit 3e75036
Show file tree
Hide file tree
Showing 8 changed files with 55 additions and 16 deletions.
6 changes: 6 additions & 0 deletions app/src/main/java/com/umc/coumo/data/remote/api/LoginApi.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import com.umc.coumo.data.remote.model.request.RequestJoinModel
import com.umc.coumo.data.remote.model.request.RequestJoinRequestVerificationModel
import com.umc.coumo.data.remote.model.request.RequestJoinVerifyCodeModel
import com.umc.coumo.data.remote.model.request.RequestLoginModel
import com.umc.coumo.data.remote.model.request.RequestResetPasswordModel
import com.umc.coumo.data.remote.model.request.RequestVerifyIdCodeModel
import com.umc.coumo.data.remote.model.response.ResponseCheckDupIdModel
import com.umc.coumo.data.remote.model.response.ResponseJoinModel
Expand Down Expand Up @@ -61,4 +62,9 @@ interface LoginApi {
@Body params: RequestLoginModel
): Response<ResponseModel<ResponseLoginAsOwnerModel>>

@POST("/customer/reset-password/set-pw")
suspend fun postResetPassword(
@Body params: RequestResetPasswordModel
): Response<ResponseModel<String>>

}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import com.umc.coumo.data.remote.model.request.RequestJoinModel
import com.umc.coumo.data.remote.model.request.RequestJoinRequestVerificationModel
import com.umc.coumo.data.remote.model.request.RequestJoinVerifyCodeModel
import com.umc.coumo.data.remote.model.request.RequestLoginModel
import com.umc.coumo.data.remote.model.request.RequestResetPasswordModel
import com.umc.coumo.data.remote.model.request.RequestVerifyIdCodeModel
import com.umc.coumo.data.remote.model.response.ResponseCheckDupIdModel
import com.umc.coumo.data.remote.model.response.ResponseJoinModel
Expand Down Expand Up @@ -86,6 +87,11 @@ class LoginRepositoryImpl @Inject constructor(
return mapToResponseLoginAsOwner(data.body()?.result)
}

override suspend fun postResetPassword(loginId: String, newPassword: String): Boolean {
val data = loginApi.postResetPassword(RequestResetPasswordModel(loginId, newPassword))
return data.body()?.isSuccess ?: false
}

private fun mapToResponseLoginModel(response: ResponseLoginModel?): ResponseLoginModel? {
return if (response != null) {
ResponseLoginModel(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.umc.coumo.data.remote.model.request

data class RequestResetPasswordModel(
val loginId: String,
val newPassword: String
)
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,5 @@ interface LoginRepository {
suspend fun postJoinRequestVerification(name: String, phone: String): Boolean
suspend fun postJoinVerifyCode(phone: String, verificationCode: String): Boolean
suspend fun postLoginAsOwner(loginId: String, password: String): ResponseLoginAsOwnerModel?
suspend fun postResetPassword(loginId: String, newPassword: String): Boolean
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,26 @@ package com.umc.coumo.domain.viewmodel
import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.umc.coumo.data.remote.api.LoginApi
import com.umc.coumo.domain.repository.LoginRepository
import kotlinx.coroutines.launch
import javax.inject.Inject

class ResetPasswordViewModel @Inject constructor(): ViewModel() {
class ResetPasswordViewModel @Inject constructor(
private val repository: LoginRepository
): ViewModel() {
private val _isValidatePassword = MutableLiveData(false)
val isValidatePassword: LiveData<Boolean> get() = _isValidatePassword

private val _isSuccess = MutableLiveData(false)
val isSuccess: LiveData<Boolean> get() = _isSuccess

fun postResetPassword(loginId: String, newPassword: String) {
viewModelScope.launch {
_isSuccess.value = repository.postResetPassword(loginId, newPassword)
}
}

fun setIsValidatePassword(bool: Boolean) { _isValidatePassword.value = bool }
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import com.umc.coumo.utils.binding.BindingFragment
class FoundIdFragment : BindingFragment<FragmentFoundIdBinding>(R.layout.fragment_found_id) {
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
val text = requireArguments().getString("userName")?.toString()
val text = requireArguments().getString("userName")
val isSuccess = !text.isNullOrEmpty()
val bundle = Bundle()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package com.umc.coumo.presentation.fragment.login
import android.os.Bundle
import android.text.Editable
import android.text.TextWatcher
import android.util.Log
import android.view.View
import androidx.fragment.app.activityViewModels
import androidx.lifecycle.Observer
Expand Down Expand Up @@ -72,10 +73,8 @@ class PhoneVerificationFragment: BindingFragment<FragmentPhoneVerificationBindin
bundle.putString("userName", viewModel.foundId)
if (isFindForId) {
findNavController().navigate(R.id.action_phoneVerificationFragment_to_foundIdFragment, bundle)
} else if (viewModel.isValidateUser.value == true) {
findNavController().navigate(R.id.action_phoneVerificationFragment_to_resetPasswordFragment, bundle)
} else {
ConfirmDialog("오류가 발생했습니다. 다시 시도해주세요. 그래도 오류가 발생한다면 관리자에게 문의하세요.")
findNavController().navigate(R.id.action_phoneVerificationFragment_to_resetPasswordFragment, bundle)
}
}
else if (success == false) binding.tvPhoneVerificationWrongCode.visibility = View.VISIBLE
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,27 @@ import android.text.Editable
import android.text.TextWatcher
import android.view.View
import androidx.fragment.app.viewModels
import androidx.lifecycle.Observer
import androidx.navigation.fragment.findNavController
import com.umc.coumo.R
import com.umc.coumo.databinding.FragmentResetPasswordBinding
import com.umc.coumo.domain.type.AccountAction
import com.umc.coumo.domain.viewmodel.PhoneVerificationViewModel
import com.umc.coumo.domain.viewmodel.ResetPasswordViewModel
import com.umc.coumo.presentation.dialog.AccountBottomSheetDialog
import com.umc.coumo.presentation.dialog.ConfirmDialog
import com.umc.coumo.utils.binding.BindingFragment

class ResetPasswordFragment : BindingFragment<FragmentResetPasswordBinding> (R.layout.fragment_reset_password) {

private val viewmodel: ResetPasswordViewModel by viewModels()
private val viewModel: ResetPasswordViewModel by viewModels()
private val isPasswordEqual get() =
binding.textboxResetPasswordNewPw.text.toString() == binding.textboxResetPasswordPwRetype.text.toString()
private val isItOk get() = viewmodel.isValidatePassword.value!! && isPasswordEqual
private val isItOk get() = viewModel.isValidatePassword.value!! && isPasswordEqual

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)

binding.viewModel = viewmodel
val loginId = requireArguments().getString("userName")
binding.viewModel = viewModel
binding.lifecycleOwner = this

binding.btnResetPasswordLeftArrow.setOnClickListener {
Expand All @@ -36,16 +37,23 @@ class ResetPasswordFragment : BindingFragment<FragmentResetPasswordBinding> (R.l
binding.tvResetPasswordWrongPw.visibility = View.VISIBLE
}
override fun onTextChanged(s: CharSequence?, start: Int, before: Int, count: Int) {
viewmodel.setIsValidatePassword(checkPassword(s.toString()))
viewModel.setIsValidatePassword(checkPassword(s.toString()))
}
override fun afterTextChanged(s: Editable?) {}
})

binding.btnResetPasswordConfirm.setOnClickListener {
ConfirmDialog(IsItWrongMessage()).show(parentFragmentManager, null)
if (isItOk)
findNavController().navigate(R.id.action_reset_to_home)
if (isItOk) viewModel.postResetPassword(loginId!!, binding.textboxResetPasswordNewPw.text.toString())
else ConfirmDialog(IsItWrongMessage()).show(parentFragmentManager, null)
}

viewModel.isSuccess.observe(viewLifecycleOwner, Observer {
if (it) {
ConfirmDialog("비밀번호가 성공적으로 재설정되었습니다.").show(parentFragmentManager, null)
findNavController().navigate(R.id.action_reset_to_home)
}
else ConfirmDialog("비밀번호 재설정 과정에서 오류가 발생했습니다. 관리자에게 문의 바랍니다.").show(parentFragmentManager, null)
})
}

private fun checkPassword(str: String): Boolean {
Expand All @@ -63,9 +71,9 @@ class ResetPasswordFragment : BindingFragment<FragmentResetPasswordBinding> (R.l
}

private fun IsItWrongMessage() : String {
if (!viewmodel.isValidatePassword.value!!) return "형식에 맞는 비밀번호를 입력해주세요."
if (!viewModel.isValidatePassword.value!!) return "형식에 맞는 비밀번호를 입력해주세요."
else if (!isPasswordEqual) return "비밀번호가 일치하지 않습니다."
else return "비밀번호 설정이 완료되었습니다."
else return "알 수 없는 오류가 발생했습니다."
}

override fun onBackPressed() {
Expand Down

0 comments on commit 3e75036

Please sign in to comment.