Skip to content

Commit

Permalink
[FEAT] #13 - 이메일 중복 확인 서버 연결
Browse files Browse the repository at this point in the history
  • Loading branch information
OliviaYJH committed Feb 4, 2022
1 parent 543c257 commit f14547d
Show file tree
Hide file tree
Showing 20 changed files with 215 additions and 30 deletions.
6 changes: 6 additions & 0 deletions EarthGardener/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,18 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="team.gdsc.earthgardener">

<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />

<application
android:name=".di.EarthGardenerApplication"
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:networkSecurityConfig="@xml/network_security_config"
android:theme="@style/Theme.EarthGardener.Splash">
<activity
android:name=".presentation.user.signup.SignUpActivity"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ package team.gdsc.earthgardener.data.api

import retrofit2.http.Body
import retrofit2.http.GET
import team.gdsc.earthgardener.data.model.request.ReqCheckEmailSuccessData
import retrofit2.http.Query
import team.gdsc.earthgardener.data.model.response.ResCheckEmailSuccessData

interface LoginService {
// Get Email Code
@GET("/user/signup/email")
@GET("user/signup/email")
suspend fun GetEmail(
@Body body: ReqCheckEmailSuccessData
@Query("email") email: String
):ResCheckEmailSuccessData

// Get NickName
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
package team.gdsc.earthgardener.data.datasource

import team.gdsc.earthgardener.data.model.request.ReqCheckEmailSuccessData
import team.gdsc.earthgardener.data.model.response.ResCheckEmailSuccessData

interface CheckEmailDataSource {
suspend fun getCheckEmail(body: ReqCheckEmailSuccessData): ResCheckEmailSuccessData
suspend fun getCheckEmail(email: String): ResCheckEmailSuccessData
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
package team.gdsc.earthgardener.data.datasource

import team.gdsc.earthgardener.data.api.LoginService
import team.gdsc.earthgardener.data.model.request.ReqCheckEmailSuccessData
import team.gdsc.earthgardener.data.model.response.ResCheckEmailSuccessData

class CheckEmailRemoteDataSource (private val loginService: LoginService) : CheckEmailDataSource {
override suspend fun getCheckEmail(body: ReqCheckEmailSuccessData): ResCheckEmailSuccessData {
return loginService.GetEmail(body)
override suspend fun getCheckEmail(email: String): ResCheckEmailSuccessData {
return loginService.GetEmail(email)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ import team.gdsc.earthgardener.domain.CheckEmailData
object CheckEmailMapper {
fun mapperToCheckEmailResultSuccessData(resCheckEmailSuccessData: ResCheckEmailSuccessData): CheckEmailData{
return CheckEmailData(
code = resCheckEmailSuccessData.code
code = resCheckEmailSuccessData.code,
message = resCheckEmailSuccessData.message,
status = resCheckEmailSuccessData.status
)
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@ package team.gdsc.earthgardener.data.repository

import team.gdsc.earthgardener.data.datasource.CheckEmailDataSource
import team.gdsc.earthgardener.data.mapper.CheckEmailMapper
import team.gdsc.earthgardener.data.model.request.ReqCheckEmailSuccessData
import team.gdsc.earthgardener.domain.CheckEmailData
import team.gdsc.earthgardener.domain.LoginRepository

class CheckEmailRepositoryImpl(private val checkEmailDataSource: CheckEmailDataSource): LoginRepository{
override suspend fun getCheckEmailResult(body: ReqCheckEmailSuccessData): CheckEmailData {
return CheckEmailMapper.mapperToCheckEmailResultSuccessData(checkEmailDataSource.getCheckEmail(body))
override suspend fun getCheckEmailResult(email: String): CheckEmailData {
return CheckEmailMapper.mapperToCheckEmailResultSuccessData(checkEmailDataSource.getCheckEmail(email))
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package team.gdsc.earthgardener.di

import org.koin.dsl.module
import team.gdsc.earthgardener.data.datasource.CheckEmailDataSource
import team.gdsc.earthgardener.data.datasource.CheckEmailRemoteDataSource

val dataSourceModule = module{
single<CheckEmailDataSource>{CheckEmailRemoteDataSource(get())}
}
Original file line number Diff line number Diff line change
@@ -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)
}

}
}
Original file line number Diff line number Diff line change
@@ -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>{
Retrofit.Builder()
.client(get())
.addConverterFactory(GsonConverterFactory.create(GsonBuilder().setLenient().create()))
.baseUrl("http://52.78.175.39:8080/")
.build()
}

single<LoginService>{
get<Retrofit>().create(LoginService::class.java)
}
}
Original file line number Diff line number Diff line change
@@ -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<LoginRepository>{CheckEmailRepositoryImpl(get())}
}
Original file line number Diff line number Diff line change
@@ -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())}
}
Original file line number Diff line number Diff line change
@@ -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())
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package team.gdsc.earthgardener.domain

data class CheckEmailData(
val code: String
val code: String,
val message: String,
val status: Int
)
Original file line number Diff line number Diff line change
@@ -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
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ class SignUpActivity : BaseActivity<ActivitySignUpBinding>(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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<FragmentEmailPwBinding>(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()
Expand Down Expand Up @@ -58,18 +69,25 @@ class EmailPwFragment : BaseFragment<FragmentEmailPwBinding>(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()
}
}
}

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

Expand All @@ -93,7 +111,7 @@ class EmailPwFragment : BaseFragment<FragmentEmailPwBinding>(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{
Expand All @@ -105,13 +123,15 @@ class EmailPwFragment : BaseFragment<FragmentEmailPwBinding>(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)
}
}



}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -24,11 +25,17 @@ class NickNameFragment : BaseFragment<FragmentNickNameBinding>(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(){
Expand Down
Loading

0 comments on commit f14547d

Please sign in to comment.