diff --git a/EarthGardener/app/src/main/AndroidManifest.xml b/EarthGardener/app/src/main/AndroidManifest.xml index 5a7c97d..c472061 100644 --- a/EarthGardener/app/src/main/AndroidManifest.xml +++ b/EarthGardener/app/src/main/AndroidManifest.xml @@ -2,12 +2,18 @@ + + + + {CheckEmailRemoteDataSource(get())} +} \ No newline at end of file diff --git a/EarthGardener/app/src/main/java/team/gdsc/earthgardener/di/EarthGardenerApplication.kt b/EarthGardener/app/src/main/java/team/gdsc/earthgardener/di/EarthGardenerApplication.kt new file mode 100644 index 0000000..d7edcd5 --- /dev/null +++ b/EarthGardener/app/src/main/java/team/gdsc/earthgardener/di/EarthGardenerApplication.kt @@ -0,0 +1,29 @@ +package team.gdsc.earthgardener.di + +import android.app.Application +import android.content.SharedPreferences +import org.koin.android.ext.koin.androidContext +import org.koin.core.context.startKoin + +class EarthGardenerApplication: Application() { + + companion object{ + lateinit var sSharedPreferences: SharedPreferences + lateinit var editor: SharedPreferences.Editor + + val X_ACCESS_TOKEN = "X-ACCESS-TOKEN" + } + + override fun onCreate() { + super.onCreate() + + sSharedPreferences = applicationContext.getSharedPreferences("EARTH_GARDENER", MODE_PRIVATE) + editor = sSharedPreferences.edit() + + startKoin{ + androidContext(this@EarthGardenerApplication) + modules(netWorkModule, dataSourceModule, repositoryModule, viewModelModule) + } + + } +} \ No newline at end of file diff --git a/EarthGardener/app/src/main/java/team/gdsc/earthgardener/di/NetworkModule.kt b/EarthGardener/app/src/main/java/team/gdsc/earthgardener/di/NetworkModule.kt new file mode 100644 index 0000000..d5c7365 --- /dev/null +++ b/EarthGardener/app/src/main/java/team/gdsc/earthgardener/di/NetworkModule.kt @@ -0,0 +1,39 @@ +package team.gdsc.earthgardener.di + +import com.google.gson.GsonBuilder +import okhttp3.Interceptor +import okhttp3.OkHttpClient +import okhttp3.logging.HttpLoggingInterceptor +import org.koin.dsl.module +import retrofit2.Retrofit +import retrofit2.converter.gson.GsonConverterFactory +import team.gdsc.earthgardener.data.api.LoginService +import team.gdsc.earthgardener.di.EarthGardenerApplication.Companion.X_ACCESS_TOKEN +import team.gdsc.earthgardener.di.EarthGardenerApplication.Companion.sSharedPreferences + +val netWorkModule = module { + single{ + OkHttpClient.Builder() + .addInterceptor(HttpLoggingInterceptor().setLevel(HttpLoggingInterceptor.Level.BODY)) + .addNetworkInterceptor(XAccessTokenInterceptor()) + .addInterceptor(Interceptor { chain -> + chain.proceed( + chain.request().newBuilder() + .build() + ) + }) + .build() + } + + single{ + Retrofit.Builder() + .client(get()) + .addConverterFactory(GsonConverterFactory.create(GsonBuilder().setLenient().create())) + .baseUrl("http://52.78.175.39:8080/") + .build() + } + + single{ + get().create(LoginService::class.java) + } +} \ No newline at end of file diff --git a/EarthGardener/app/src/main/java/team/gdsc/earthgardener/di/RepositoryModule.kt b/EarthGardener/app/src/main/java/team/gdsc/earthgardener/di/RepositoryModule.kt new file mode 100644 index 0000000..9b91216 --- /dev/null +++ b/EarthGardener/app/src/main/java/team/gdsc/earthgardener/di/RepositoryModule.kt @@ -0,0 +1,9 @@ +package team.gdsc.earthgardener.di + +import org.koin.dsl.module +import team.gdsc.earthgardener.data.repository.CheckEmailRepositoryImpl +import team.gdsc.earthgardener.domain.LoginRepository + +val repositoryModule = module{ + single{CheckEmailRepositoryImpl(get())} +} \ No newline at end of file diff --git a/EarthGardener/app/src/main/java/team/gdsc/earthgardener/di/ViewModelModule.kt b/EarthGardener/app/src/main/java/team/gdsc/earthgardener/di/ViewModelModule.kt new file mode 100644 index 0000000..1c6253e --- /dev/null +++ b/EarthGardener/app/src/main/java/team/gdsc/earthgardener/di/ViewModelModule.kt @@ -0,0 +1,9 @@ +package team.gdsc.earthgardener.di + +import org.koin.androidx.viewmodel.dsl.viewModel +import org.koin.dsl.module +import team.gdsc.earthgardener.presentation.user.signup.viewModel.CheckEmailViewModel + +val viewModelModule = module{ + viewModel{CheckEmailViewModel(get())} +} \ No newline at end of file diff --git a/EarthGardener/app/src/main/java/team/gdsc/earthgardener/di/XAccessTokenInterceptor.kt b/EarthGardener/app/src/main/java/team/gdsc/earthgardener/di/XAccessTokenInterceptor.kt new file mode 100644 index 0000000..848e6a7 --- /dev/null +++ b/EarthGardener/app/src/main/java/team/gdsc/earthgardener/di/XAccessTokenInterceptor.kt @@ -0,0 +1,19 @@ +package team.gdsc.earthgardener.di + +import okhttp3.Interceptor +import okhttp3.Request +import okhttp3.Response +import team.gdsc.earthgardener.di.EarthGardenerApplication.Companion.X_ACCESS_TOKEN +import team.gdsc.earthgardener.di.EarthGardenerApplication.Companion.sSharedPreferences + +class XAccessTokenInterceptor: Interceptor { + + override fun intercept(chain: Interceptor.Chain): Response { + val builder: Request.Builder = chain.request().newBuilder() + val jwtToken: String? = sSharedPreferences.getString(X_ACCESS_TOKEN, null) + if(jwtToken != null){ + builder.addHeader("X-ACCESS-TOKEN", jwtToken) + } + return chain.proceed(builder.build()) + } +} \ No newline at end of file diff --git a/EarthGardener/app/src/main/java/team/gdsc/earthgardener/domain/CheckEmailData.kt b/EarthGardener/app/src/main/java/team/gdsc/earthgardener/domain/CheckEmailData.kt index 70c7daa..fbf5a3a 100644 --- a/EarthGardener/app/src/main/java/team/gdsc/earthgardener/domain/CheckEmailData.kt +++ b/EarthGardener/app/src/main/java/team/gdsc/earthgardener/domain/CheckEmailData.kt @@ -1,5 +1,7 @@ package team.gdsc.earthgardener.domain data class CheckEmailData( - val code: String + val code: String, + val message: String, + val status: Int ) diff --git a/EarthGardener/app/src/main/java/team/gdsc/earthgardener/domain/LoginRepository.kt b/EarthGardener/app/src/main/java/team/gdsc/earthgardener/domain/LoginRepository.kt index cb56b78..ce569b6 100644 --- a/EarthGardener/app/src/main/java/team/gdsc/earthgardener/domain/LoginRepository.kt +++ b/EarthGardener/app/src/main/java/team/gdsc/earthgardener/domain/LoginRepository.kt @@ -1,8 +1,5 @@ package team.gdsc.earthgardener.domain -import team.gdsc.earthgardener.data.model.request.ReqCheckEmailSuccessData -import team.gdsc.earthgardener.data.model.response.ResCheckEmailSuccessData - interface LoginRepository { - suspend fun getCheckEmailResult(body: ReqCheckEmailSuccessData): CheckEmailData + suspend fun getCheckEmailResult(email: String): CheckEmailData } \ No newline at end of file diff --git a/EarthGardener/app/src/main/java/team/gdsc/earthgardener/presentation/user/signup/SignUpActivity.kt b/EarthGardener/app/src/main/java/team/gdsc/earthgardener/presentation/user/signup/SignUpActivity.kt index 5fee1a2..8c0e310 100644 --- a/EarthGardener/app/src/main/java/team/gdsc/earthgardener/presentation/user/signup/SignUpActivity.kt +++ b/EarthGardener/app/src/main/java/team/gdsc/earthgardener/presentation/user/signup/SignUpActivity.kt @@ -20,7 +20,8 @@ class SignUpActivity : BaseActivity(R.layout.activity_sig .commit() } - fun nextSignUpFragment(fa: Fragment){ + fun nextSignUpFragment(fa: Fragment, bundle: Bundle){ + fa.arguments = bundle supportFragmentManager.beginTransaction() .replace(R.id.frame_sign_up, fa) .commit() diff --git a/EarthGardener/app/src/main/java/team/gdsc/earthgardener/presentation/user/signup/emailpw/EmailPwFragment.kt b/EarthGardener/app/src/main/java/team/gdsc/earthgardener/presentation/user/signup/emailpw/EmailPwFragment.kt index 86ce102..0d01175 100644 --- a/EarthGardener/app/src/main/java/team/gdsc/earthgardener/presentation/user/signup/emailpw/EmailPwFragment.kt +++ b/EarthGardener/app/src/main/java/team/gdsc/earthgardener/presentation/user/signup/emailpw/EmailPwFragment.kt @@ -3,18 +3,29 @@ package team.gdsc.earthgardener.presentation.user.signup.emailpw import android.os.Bundle import android.text.Editable import android.text.TextWatcher +import android.util.Log import android.view.View +import android.widget.Toast import androidx.core.content.ContextCompat import androidx.core.view.isVisible +import org.koin.androidx.viewmodel.ext.android.viewModel +import retrofit2.Call +import retrofit2.Callback +import retrofit2.Response import team.gdsc.earthgardener.R import team.gdsc.earthgardener.databinding.FragmentEmailPwBinding import team.gdsc.earthgardener.presentation.base.BaseFragment import team.gdsc.earthgardener.presentation.user.signup.nickname.NickNameFragment import team.gdsc.earthgardener.presentation.user.signup.SignUpActivity +import team.gdsc.earthgardener.presentation.user.signup.viewModel.CheckEmailViewModel import java.util.regex.Pattern class EmailPwFragment : BaseFragment(R.layout.fragment_email_pw) { + private val checkEmailViewModel: CheckEmailViewModel by viewModel() + private var emailCode: String?= null + private var checkEmailCode = false + override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) checkEmailPattern() @@ -58,11 +69,12 @@ class EmailPwFragment : BaseFragment(R.layout.fragment_e private fun getCodeEvent(){ binding.tvGetCode.setOnClickListener { if(checkEmailPattern()){ - // Get Code from email - - binding.tvCode.isVisible = true binding.linearEmailCode.isVisible = true + + // 통신 Get Code from email + checkEmailViewModel.email = binding.etSignUpEmail.text.toString() + checkEmailViewModel.getEmail() } } } @@ -70,6 +82,12 @@ class EmailPwFragment : BaseFragment(R.layout.fragment_e private fun checkCode(){ binding.tvCheckCode.setOnClickListener { // check if code is right + if(emailCode.equals(binding.etEmailCode.text.toString())){ + checkEmailCode = true + }else{ + Toast.makeText(context, "인증코드를 잘못 입력하셨습니다", Toast.LENGTH_SHORT).show() + binding.etEmailCode.text.clear() + } } } @@ -93,7 +111,7 @@ class EmailPwFragment : BaseFragment(R.layout.fragment_e private fun btnNextActive(){ val signUpActivity = activity as SignUpActivity - if(binding.etSignupPw.text.isNotEmpty() ){ // 이메일 인증 코드 맞는지 여부 조건도 넣기 + if(binding.etSignupPw.text.isNotEmpty() ){ // 이메일 인증 코드 맞는지 여부 조건도 넣기 && checkEmailCode signUpActivity.binding.btnNext.setBackgroundResource(R.drawable.rectangle_primary_green_radius_30) signUpActivity.binding.btnNext.isEnabled = true }else{ @@ -105,13 +123,15 @@ class EmailPwFragment : BaseFragment(R.layout.fragment_e private fun btnNextEvent(){ val signUpActivity = activity as SignUpActivity signUpActivity.binding.btnNext.setOnClickListener { + val bundle = Bundle() + bundle.putString("email", binding.etSignUpEmail.text.toString()) + bundle.putString("pw", binding.etSignupPw.text.toString()) + signUpActivity.binding.btnNext.text = getString(R.string.finish) signUpActivity.binding.btnNext.setBackgroundResource(R.drawable.rectangle_light_gray_radius_30) signUpActivity.binding.btnNext.isEnabled = false - signUpActivity.nextSignUpFragment(NickNameFragment()) + signUpActivity.nextSignUpFragment(NickNameFragment(), bundle) } } - - } \ No newline at end of file diff --git a/EarthGardener/app/src/main/java/team/gdsc/earthgardener/presentation/user/signup/nickname/NickNameFragment.kt b/EarthGardener/app/src/main/java/team/gdsc/earthgardener/presentation/user/signup/nickname/NickNameFragment.kt index af51463..1004410 100644 --- a/EarthGardener/app/src/main/java/team/gdsc/earthgardener/presentation/user/signup/nickname/NickNameFragment.kt +++ b/EarthGardener/app/src/main/java/team/gdsc/earthgardener/presentation/user/signup/nickname/NickNameFragment.kt @@ -8,6 +8,7 @@ import android.os.Bundle import android.provider.MediaStore import android.text.Editable import android.text.TextWatcher +import android.util.Log import android.view.View import okhttp3.MediaType import okhttp3.MediaType.Companion.toMediaType @@ -24,11 +25,17 @@ class NickNameFragment : BaseFragment(R.layout.fragment private val OPEN_GALLERY = 1 + private var email: String? =null + private var pw: String? = null + override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) openGallery() btnFinishActive() btnFinishEvent() + + email = arguments!!.getString("email", "error") + pw = arguments!!.getString("pw", "error") } private fun openGallery(){ diff --git a/EarthGardener/app/src/main/java/team/gdsc/earthgardener/presentation/user/signup/viewModel/CheckEmailViewModel.kt b/EarthGardener/app/src/main/java/team/gdsc/earthgardener/presentation/user/signup/viewModel/CheckEmailViewModel.kt new file mode 100644 index 0000000..ce788e7 --- /dev/null +++ b/EarthGardener/app/src/main/java/team/gdsc/earthgardener/presentation/user/signup/viewModel/CheckEmailViewModel.kt @@ -0,0 +1,39 @@ +package team.gdsc.earthgardener.presentation.user.signup.viewModel + +import android.util.Log +import android.widget.Toast +import androidx.lifecycle.LiveData +import androidx.lifecycle.MutableLiveData +import androidx.lifecycle.ViewModel +import androidx.lifecycle.viewModelScope +import kotlinx.coroutines.launch +import team.gdsc.earthgardener.data.model.response.ResCheckEmailSuccessData +import team.gdsc.earthgardener.domain.CheckEmailData +import team.gdsc.earthgardener.domain.LoginRepository + +class CheckEmailViewModel(private val loginRepository: LoginRepository): ViewModel() { + + //private var _checkEmail = MutableLiveData() + //var checkEmail : LiveData = _checkEmail + + private var _email : String = "" + var email: String = _email + set(value){ + _email = value + field = value + } + + + fun getEmail() = viewModelScope.launch(){ + runCatching{loginRepository.getCheckEmailResult(_email)} + .onSuccess { + //_checkEmail.postValue(it) + Log.d("getEmail", it.code) + + } + .onFailure { + Log.d("getEmail", "fail") + it.printStackTrace() + } + } +} \ No newline at end of file diff --git a/EarthGardener/app/src/main/res/xml/network_security_config.xml b/EarthGardener/app/src/main/res/xml/network_security_config.xml new file mode 100644 index 0000000..bbec0dd --- /dev/null +++ b/EarthGardener/app/src/main/res/xml/network_security_config.xml @@ -0,0 +1,5 @@ + + + + +