From 3e75036718f0961c1afb2fd2f994f3bedf22adb2 Mon Sep 17 00:00:00 2001 From: psw9428 Date: Tue, 20 Feb 2024 21:55:36 +0900 Subject: [PATCH] =?UTF-8?q?[ui/#54]=20:=20=EB=B9=84=EB=B0=80=EB=B2=88?= =?UTF-8?q?=ED=98=B8=20=EC=B0=BE=EA=B8=B0=EB=8F=84=20=EB=A1=9C=EC=A7=81?= =?UTF-8?q?=EA=B1=B0=EC=9D=98=20=EC=99=84=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/umc/coumo/data/remote/api/LoginApi.kt | 6 ++++ .../remote/datasource/LoginRepositoryImpl.kt | 6 ++++ .../request/RequestResetPasswordModel.kt | 6 ++++ .../domain/repository/LoginRepository.kt | 1 + .../viewmodel/ResetPasswordViewModel.kt | 15 +++++++++- .../fragment/login/FoundIdFragment.kt | 2 +- .../login/PhoneVerificationFragment.kt | 5 ++-- .../fragment/login/ResetPasswordFragment.kt | 30 ++++++++++++------- 8 files changed, 55 insertions(+), 16 deletions(-) create mode 100644 app/src/main/java/com/umc/coumo/data/remote/model/request/RequestResetPasswordModel.kt diff --git a/app/src/main/java/com/umc/coumo/data/remote/api/LoginApi.kt b/app/src/main/java/com/umc/coumo/data/remote/api/LoginApi.kt index 780c2ab..984a7df 100644 --- a/app/src/main/java/com/umc/coumo/data/remote/api/LoginApi.kt +++ b/app/src/main/java/com/umc/coumo/data/remote/api/LoginApi.kt @@ -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 @@ -61,4 +62,9 @@ interface LoginApi { @Body params: RequestLoginModel ): Response> + @POST("/customer/reset-password/set-pw") + suspend fun postResetPassword( + @Body params: RequestResetPasswordModel + ): Response> + } \ No newline at end of file diff --git a/app/src/main/java/com/umc/coumo/data/remote/datasource/LoginRepositoryImpl.kt b/app/src/main/java/com/umc/coumo/data/remote/datasource/LoginRepositoryImpl.kt index 89a92f2..46b9b78 100644 --- a/app/src/main/java/com/umc/coumo/data/remote/datasource/LoginRepositoryImpl.kt +++ b/app/src/main/java/com/umc/coumo/data/remote/datasource/LoginRepositoryImpl.kt @@ -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 @@ -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( diff --git a/app/src/main/java/com/umc/coumo/data/remote/model/request/RequestResetPasswordModel.kt b/app/src/main/java/com/umc/coumo/data/remote/model/request/RequestResetPasswordModel.kt new file mode 100644 index 0000000..4ea9381 --- /dev/null +++ b/app/src/main/java/com/umc/coumo/data/remote/model/request/RequestResetPasswordModel.kt @@ -0,0 +1,6 @@ +package com.umc.coumo.data.remote.model.request + +data class RequestResetPasswordModel( + val loginId: String, + val newPassword: String +) diff --git a/app/src/main/java/com/umc/coumo/domain/repository/LoginRepository.kt b/app/src/main/java/com/umc/coumo/domain/repository/LoginRepository.kt index 058929b..deaa9c9 100644 --- a/app/src/main/java/com/umc/coumo/domain/repository/LoginRepository.kt +++ b/app/src/main/java/com/umc/coumo/domain/repository/LoginRepository.kt @@ -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 } \ No newline at end of file diff --git a/app/src/main/java/com/umc/coumo/domain/viewmodel/ResetPasswordViewModel.kt b/app/src/main/java/com/umc/coumo/domain/viewmodel/ResetPasswordViewModel.kt index 3cb5562..769c94d 100644 --- a/app/src/main/java/com/umc/coumo/domain/viewmodel/ResetPasswordViewModel.kt +++ b/app/src/main/java/com/umc/coumo/domain/viewmodel/ResetPasswordViewModel.kt @@ -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 get() = _isValidatePassword + private val _isSuccess = MutableLiveData(false) + val isSuccess: LiveData get() = _isSuccess + fun postResetPassword(loginId: String, newPassword: String) { + viewModelScope.launch { + _isSuccess.value = repository.postResetPassword(loginId, newPassword) + } + } fun setIsValidatePassword(bool: Boolean) { _isValidatePassword.value = bool } } \ No newline at end of file diff --git a/app/src/main/java/com/umc/coumo/presentation/fragment/login/FoundIdFragment.kt b/app/src/main/java/com/umc/coumo/presentation/fragment/login/FoundIdFragment.kt index 068c899..0c43451 100644 --- a/app/src/main/java/com/umc/coumo/presentation/fragment/login/FoundIdFragment.kt +++ b/app/src/main/java/com/umc/coumo/presentation/fragment/login/FoundIdFragment.kt @@ -10,7 +10,7 @@ import com.umc.coumo.utils.binding.BindingFragment class FoundIdFragment : BindingFragment(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() diff --git a/app/src/main/java/com/umc/coumo/presentation/fragment/login/PhoneVerificationFragment.kt b/app/src/main/java/com/umc/coumo/presentation/fragment/login/PhoneVerificationFragment.kt index 4a0127d..009cdc7 100644 --- a/app/src/main/java/com/umc/coumo/presentation/fragment/login/PhoneVerificationFragment.kt +++ b/app/src/main/java/com/umc/coumo/presentation/fragment/login/PhoneVerificationFragment.kt @@ -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 @@ -72,10 +73,8 @@ class PhoneVerificationFragment: BindingFragment (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 { @@ -36,16 +37,23 @@ class ResetPasswordFragment : BindingFragment (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 { @@ -63,9 +71,9 @@ class ResetPasswordFragment : BindingFragment (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() {