Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

week_10 #36

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions roy/Flo/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,16 @@ dependencies {
implementation("com.github.bumptech.glide:glide:4.12.0")
annotationProcessor("com.github.bumptech.glide:compiler:4.12.0")

//kakao
implementation "com.kakao.sdk:v2-user:2.20.6" // 카카오 로그인 API 모듈

//naver
implementation "com.navercorp.nid:oauth:5.7.0"






implementation libs.androidx.core.ktx
implementation libs.androidx.appcompat
Expand Down
48 changes: 44 additions & 4 deletions roy/Flo/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,22 @@
xmlns:tools="http://schemas.android.com/tools"
package="com.example.flo">

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


<application
android:name=".GlobalApplication"
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/Theme.FLO"
android:usesCleartextTraffic="true"
android:theme="@style/Theme.FLO">
android:networkSecurityConfig="@xml/network_security_config">

<meta-data
android:name="com.kakao.sdk.AppKey"
android:value="c656eaa588c6ec656ffce11b219d29f5"/>

<activity
android:name=".SplashActivity"
Expand All @@ -25,18 +34,49 @@

<activity
android:name=".LoginActivity"
android:exported="true" />
android:exported="true">

<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />

<data android:host="oauth"
android:scheme="kakaoc656eaa588c6ec656ffce11b219d29f5" />
</intent-filter>
</activity>




<activity
android:name=".SignUpActivity"
android:exported="true" />


<activity
android:name=".SongActivity"
android:exported="true" />

<activity
android:name=".ProfileActivity"
android:exported="true" />


<activity
android:name="com.kakao.sdk.auth.AuthCodeHandlerActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data
android:host="oauth"
android:scheme="kakaoc656eaa588c6ec656ffce11b219d29f5" />
</intent-filter>
</activity>


</application>

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

</manifest>
7 changes: 7 additions & 0 deletions roy/Flo/app/src/main/java/com/example/flo/ApiRepository.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.example.flo

class ApiRepository {
companion object {
const val BASE_URL = "https://edu-api-test.softsquared.com"
}
}
2 changes: 1 addition & 1 deletion roy/Flo/app/src/main/java/com/example/flo/AuthResponse.kt
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ data class AuthResponse(
data class Result(
@SerializedName("memberId") val memberId: Int,
@SerializedName("accessToken") val accessToken: String
)
)
3 changes: 1 addition & 2 deletions roy/Flo/app/src/main/java/com/example/flo/AuthService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -72,5 +72,4 @@ class AuthService {
}
})
}
}

}
12 changes: 12 additions & 0 deletions roy/Flo/app/src/main/java/com/example/flo/GlobalApplication.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.example.flo

import android.app.Application
import com.kakao.sdk.common.KakaoSdk

class GlobalApplication : Application() {
override fun onCreate() {
super.onCreate()

KakaoSdk.init(this, "c656eaa588c6ec656ffce11b219d29f5")
}
}
15 changes: 15 additions & 0 deletions roy/Flo/app/src/main/java/com/example/flo/LockerFragment.kt
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
package com.example.flo

import android.content.Intent
import android.content.Intent.FLAG_ACTIVITY_CLEAR_TOP
import android.os.Bundle
import android.util.Log
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.Toast
import androidx.appcompat.app.AppCompatActivity
import androidx.fragment.app.Fragment
import com.example.flo.databinding.FragmentLockerBinding
import com.google.android.material.tabs.TabLayoutMediator
import com.kakao.sdk.user.Constants.TAG
import com.kakao.sdk.user.UserApiClient

class LockerFragment : Fragment() {
lateinit var binding: FragmentLockerBinding
Expand Down Expand Up @@ -78,5 +83,15 @@ class LockerFragment : Fragment() {

editor.remove("jwt")
editor.apply()


UserApiClient.instance.logout { error ->
if (error != null) {
Log.e(TAG, "로그아웃 실패. SDK에서 토큰 삭제됨", error)
}
else {
Log.i(TAG, "로그아웃 성공. SDK에서 토큰 삭제됨")
}
}
}
}
63 changes: 56 additions & 7 deletions roy/Flo/app/src/main/java/com/example/flo/LoginActivity.kt
Original file line number Diff line number Diff line change
@@ -1,18 +1,24 @@
package com.example.flo

import android.content.Context.MODE_PRIVATE
import android.content.Intent
import android.os.Bundle
import android.util.Log
import android.widget.Toast
import androidx.appcompat.app.AppCompatActivity
import com.example.flo.MainActivity
import com.example.flo.SongDatabase
import androidx.core.content.ContextCompat.startActivity
import androidx.databinding.DataBindingUtil.setContentView
import com.example.flo.databinding.ActivityLoginBinding
import com.kakao.sdk.auth.model.OAuthToken
import com.kakao.sdk.common.model.ClientError
import com.kakao.sdk.common.model.ClientErrorCause
import com.kakao.sdk.user.Constants.TAG
import com.kakao.sdk.user.UserApiClient


class LoginActivity : AppCompatActivity(), LoginView {

lateinit var binding : ActivityLoginBinding
lateinit var binding: ActivityLoginBinding
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
binding = ActivityLoginBinding.inflate(layoutInflater)
Expand All @@ -27,10 +33,52 @@ class LoginActivity : AppCompatActivity(), LoginView {
binding.loginSignInBtn.setOnClickListener {
login()
}


//카카오 로그인
val callback: (OAuthToken?, Throwable?) -> Unit = { token, error ->
if (error != null) {
Log.e(TAG, "카카오계정으로 로그인 실패", error)
} else if (token != null) {
Log.i(TAG, "카카오계정으로 로그인 성공 ${token.accessToken}")
val intent = Intent(this, ProfileActivity::class.java)
startActivity(intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP))
finish()
}
}

binding.loginKakakoLoginIv.setOnClickListener {
if (UserApiClient.instance.isKakaoTalkLoginAvailable(this)) {
UserApiClient.instance.loginWithKakaoTalk(this) { token, error ->
if (error != null) {
Log.e(TAG, "카카오톡으로 로그인 실패", error)

// 사용자가 카카오톡 설치 후 디바이스 권한 요청 화면에서 로그인을 취소한 경우,
// 의도적인 로그인 취소로 보고 카카오계정으로 로그인 시도 없이 로그인 취소로 처리 (예: 뒤로 가기)
if (error is ClientError && error.reason == ClientErrorCause.Cancelled) {
return@loginWithKakaoTalk
}

// 카카오톡에 연결된 카카오계정이 없는 경우, 카카오계정으로 로그인 시도
UserApiClient.instance.loginWithKakaoAccount(this, callback = callback)
} else if (token != null) {
Log.i(TAG, "카카오톡으로 로그인 성공 ${token.accessToken}")
val intent = Intent(this, ProfileActivity::class.java)
startActivity(intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP))
finish()
}
}
} else {
UserApiClient.instance.loginWithKakaoAccount(this, callback = callback)
}
}
}


private fun login() {
if (binding.loginIdEt.text.toString().isEmpty() || binding.loginDirectInputEt.text.toString().isEmpty()) {
if (binding.loginIdEt.text.toString()
.isEmpty() || binding.loginDirectInputEt.text.toString().isEmpty()
) {
Toast.makeText(this, "이메일을 입력해주세요.", Toast.LENGTH_SHORT).show()
return
}
Expand All @@ -40,7 +88,8 @@ class LoginActivity : AppCompatActivity(), LoginView {
return
}

val email : String = binding.loginIdEt.text.toString() + "@" + binding.loginDirectInputEt.text.toString()
val email: String =
binding.loginIdEt.text.toString() + "@" + binding.loginDirectInputEt.text.toString()
val pwd: String = binding.loginPasswordEt.text.toString()

val authService = AuthService()
Expand All @@ -57,7 +106,7 @@ class LoginActivity : AppCompatActivity(), LoginView {


private fun saveJwt2(jwt: String) {
val spf = getSharedPreferences("auth2" , MODE_PRIVATE)
val spf = getSharedPreferences("auth2", MODE_PRIVATE)
val editor = spf.edit()

editor.putString("jwt", jwt)
Expand All @@ -75,5 +124,5 @@ class LoginActivity : AppCompatActivity(), LoginView {
override fun onLoginFailure() {
Toast.makeText(this, "회원 정보가 존재하지 않습니다.", Toast.LENGTH_SHORT).show()
}
}

}
3 changes: 2 additions & 1 deletion roy/Flo/app/src/main/java/com/example/flo/LoginRequest.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@

package com.example.flo

data class LoginRequest(
val email: String,
val password: String
)
)
3 changes: 2 additions & 1 deletion roy/Flo/app/src/main/java/com/example/flo/LoginView.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@

package com.example.flo

interface LoginView {
fun onLogInSuccess(isSuccess: Boolean)
fun onLoginFailure()
}
}
Loading