-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
[Feat/#72] 카카오 로그인 프로젝트 세팅 및 API 연결
- Loading branch information
Showing
22 changed files
with
422 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
app/src/main/java/com/sopt/umbba_android/data/datasource/LoginRemoteDataSource.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package com.sopt.umbba_android.data.datasource | ||
|
||
import com.sopt.umbba_android.data.model.ServicePool | ||
import com.sopt.umbba_android.data.model.request.LoginRequestDto | ||
import com.sopt.umbba_android.data.model.response.LoginResponseDto | ||
|
||
class LoginRemoteDataSource { | ||
private val loginService = ServicePool.loginService | ||
suspend fun postLogin(loginRequestDto: LoginRequestDto) : LoginResponseDto = | ||
loginService.postLogin(loginRequestDto) | ||
} |
19 changes: 16 additions & 3 deletions
19
app/src/main/java/com/sopt/umbba_android/data/interceptor/AuthInterceptor.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,33 @@ | ||
package com.sopt.umbba_android.data.interceptor | ||
|
||
import android.util.Log | ||
import com.sopt.umbba_android.data.local.SharedPreferences | ||
import com.sopt.umbba_android.presentation.login.LoginActivity.Companion.USER_KAKAO_TOKEN | ||
import com.sopt.umbba_android.presentation.login.LoginActivity.Companion.USER_TOKEN | ||
import okhttp3.Interceptor | ||
import okhttp3.Response | ||
|
||
class AuthInterceptor : Interceptor { | ||
private val token ="d" | ||
|
||
override fun intercept(chain: Interceptor.Chain): Response { | ||
|
||
val token = if (SharedPreferences.getString(USER_TOKEN).isNullOrBlank()) { | ||
SharedPreferences.getKakaoString(USER_KAKAO_TOKEN) | ||
// 저장된 서버 액세스 토큰이 없다면 카카오 토큰 전송 -> 회원가입 | ||
} else { | ||
"Bearer ${SharedPreferences.getString(USER_TOKEN)}" | ||
// 저장된 서버 액세스 토큰이 있다면 Bearer 붙여서 전송 -> 로그인 | ||
} | ||
|
||
val originalRequest = chain.request() | ||
|
||
val headerRequest = originalRequest.newBuilder() // 헤더를 추가한 req | ||
.header( | ||
"Authorization", | ||
"Bearer $token" | ||
"$token" | ||
) | ||
.build() | ||
|
||
Log.e("yeonjin", "헤더 $token") | ||
return chain.proceed(headerRequest) | ||
} | ||
} |
65 changes: 65 additions & 0 deletions
65
app/src/main/java/com/sopt/umbba_android/data/local/SharedPreferences.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
package com.sopt.umbba_android.data.local | ||
|
||
import android.content.Context | ||
import android.content.SharedPreferences | ||
import androidx.core.content.edit | ||
import androidx.security.crypto.EncryptedSharedPreferences | ||
import androidx.security.crypto.MasterKeys | ||
import com.sopt.umbba_android.BuildConfig | ||
import com.sopt.umbba_android.presentation.login.LoginActivity | ||
|
||
const val FILE_NAME = "UMBBA" | ||
|
||
object SharedPreferences { | ||
private lateinit var preferences: SharedPreferences | ||
|
||
fun init(context: Context) { | ||
val masterKeyAlias = MasterKeys.getOrCreate(MasterKeys.AES256_GCM_SPEC) | ||
preferences = | ||
if (BuildConfig.DEBUG) { | ||
context.getSharedPreferences(FILE_NAME, Context.MODE_PRIVATE) | ||
} else { | ||
EncryptedSharedPreferences.create( | ||
FILE_NAME, | ||
masterKeyAlias, | ||
context, | ||
EncryptedSharedPreferences.PrefKeyEncryptionScheme.AES256_SIV, | ||
EncryptedSharedPreferences.PrefValueEncryptionScheme.AES256_GCM | ||
) | ||
} | ||
} | ||
|
||
fun setKakaoString(key: String, value: String?) { | ||
preferences.edit { putString(key, value) } | ||
} | ||
|
||
fun getKakaoString(key: String): String? { | ||
return preferences.getString(key, null) | ||
} | ||
|
||
//토큰 저장 | ||
fun setString(key: String, value: String?) { | ||
preferences.edit { putString(key, value) } | ||
} | ||
//토큰 가져오기 - 자동 로그인 확인 | ||
fun getString(key: String): String? { | ||
return preferences.getString(key, null) | ||
} | ||
//온보딩 완료 상태 저장 | ||
fun setBoolean(key: String, value: Boolean) { | ||
preferences.edit { putBoolean(key, value) } | ||
} | ||
//온보딩 완료했는지 가져오기 - 온보딩 완료 확인 | ||
fun getBoolean(key: String): Boolean { | ||
return preferences.getBoolean(key, false) | ||
} | ||
|
||
private fun clear() { | ||
preferences.edit { clear() } | ||
} | ||
|
||
fun clearForLogout() { | ||
clear() | ||
setBoolean(LoginActivity.DID_USER_CLEAR_ONBOARD, true) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
app/src/main/java/com/sopt/umbba_android/data/model/request/LoginRequestDto.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package com.sopt.umbba_android.data.model.request | ||
|
||
import kotlinx.serialization.SerialName | ||
import kotlinx.serialization.Serializable | ||
|
||
@Serializable | ||
data class LoginRequestDto ( | ||
@SerialName("social_platform") | ||
val socialPlatform : String, | ||
@SerialName("fcm_token") | ||
val fcmToken : String | ||
) |
48 changes: 48 additions & 0 deletions
48
app/src/main/java/com/sopt/umbba_android/data/model/response/LoginResponseDto.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package com.sopt.umbba_android.data.model.response | ||
|
||
import kotlinx.serialization.SerialName | ||
import kotlinx.serialization.Serializable | ||
|
||
@Serializable | ||
data class LoginResponseDto( | ||
@SerialName("status") | ||
val status: Int, | ||
@SerialName("message") | ||
val message: String, | ||
@SerialName("data") | ||
val data: LoginData | ||
) { | ||
@Serializable | ||
data class LoginData( | ||
@SerialName("user_id") | ||
val userId: Long, | ||
@SerialName("is_new_user") | ||
val isNewUser: Boolean, | ||
@SerialName("username") | ||
val username: String?, | ||
@SerialName("gender") | ||
val gender: String?, | ||
@SerialName("born_year") | ||
val bornYear: Int?, | ||
@SerialName("token_dto") | ||
val tokenDto: TokenData, | ||
@SerialName("fcm_token") | ||
val fcmToken: String, | ||
@SerialName("social_platform") | ||
val socialPlatform: String, | ||
@SerialName("social_nickname") | ||
val socialNickname: String, | ||
@SerialName("social_profile_image") | ||
val socialProfileImage: String, | ||
@SerialName("social_access_token") | ||
val socialAccessToken: String | ||
) { | ||
@Serializable | ||
data class TokenData( | ||
@SerialName("access_token") | ||
val accessToken: String, | ||
@SerialName("refresh_token") | ||
val refreshToken: String | ||
) | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
app/src/main/java/com/sopt/umbba_android/data/repository/LoginRepositoryImpl.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package com.sopt.umbba_android.data.repository | ||
|
||
import android.util.Log | ||
import com.sopt.umbba_android.data.datasource.LoginRemoteDataSource | ||
import com.sopt.umbba_android.data.model.request.LoginRequestDto | ||
import com.sopt.umbba_android.data.model.response.LoginResponseDto | ||
import com.sopt.umbba_android.domain.repository.LoginRepository | ||
import timber.log.Timber | ||
|
||
class LoginRepositoryImpl( | ||
private val loginRemoteDataSource: LoginRemoteDataSource | ||
) : LoginRepository { | ||
override suspend fun postLogin(loginRequestDto: LoginRequestDto): Result<LoginResponseDto> = | ||
runCatching { | ||
loginRemoteDataSource.postLogin(loginRequestDto) | ||
}.onSuccess { | ||
Log.e("yeonjin", "Impl login 실패") | ||
}.onFailure { | ||
Log.e("yeonjin", "Impl login 실패") | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
app/src/main/java/com/sopt/umbba_android/data/service/LoginService.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package com.sopt.umbba_android.data.service | ||
|
||
import com.sopt.umbba_android.data.model.request.LoginRequestDto | ||
import com.sopt.umbba_android.data.model.response.LoginResponseDto | ||
import retrofit2.http.Body | ||
import retrofit2.http.Header | ||
import retrofit2.http.POST | ||
|
||
interface LoginService { | ||
|
||
@POST("/login") | ||
suspend fun postLogin( | ||
@Body body: LoginRequestDto | ||
): LoginResponseDto | ||
} |
8 changes: 8 additions & 0 deletions
8
app/src/main/java/com/sopt/umbba_android/domain/repository/LoginRepository.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package com.sopt.umbba_android.domain.repository | ||
|
||
import com.sopt.umbba_android.data.model.request.LoginRequestDto | ||
import com.sopt.umbba_android.data.model.response.LoginResponseDto | ||
|
||
interface LoginRepository { | ||
suspend fun postLogin(loginRequestDto: LoginRequestDto) : Result<LoginResponseDto> | ||
} |
Oops, something went wrong.