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() {