diff --git a/.idea/misc.xml b/.idea/misc.xml
index 4dad7a2..8e9d626 100644
--- a/.idea/misc.xml
+++ b/.idea/misc.xml
@@ -7,6 +7,8 @@
+
+
diff --git a/app/src/main/java/com/example/infrastudy/APIData.kt b/app/src/main/java/com/example/infrastudy/APIData.kt
index 5fc556a..c30672f 100644
--- a/app/src/main/java/com/example/infrastudy/APIData.kt
+++ b/app/src/main/java/com/example/infrastudy/APIData.kt
@@ -42,6 +42,9 @@ data class GetPostResponse(
@SerializedName("image_src") val imageSrc:String,
@SerializedName("user_id") val userid:String?
):Serializable
+data class GetUserResponse(
+ @SerializedName("user_id") val userid:String
+)
data class imgaeResponse(
@SerializedName("message") val message:String,
diff --git a/app/src/main/java/com/example/infrastudy/APIInterface.kt b/app/src/main/java/com/example/infrastudy/APIInterface.kt
index 38e7414..a5075f4 100644
--- a/app/src/main/java/com/example/infrastudy/APIInterface.kt
+++ b/app/src/main/java/com/example/infrastudy/APIInterface.kt
@@ -47,6 +47,12 @@ interface GetPostInterface{
):Response?>
}
+interface GetUserInterface{
+ @GET("/users/getid")
+ suspend fun GetUserRequest(
+ ):Response?>
+}
+
interface DeleteInterface{
@DELETE("/board/{board_id}")
suspend fun DeleteRequest(
diff --git a/app/src/main/java/com/example/infrastudy/APIServiceImp.kt b/app/src/main/java/com/example/infrastudy/APIServiceImp.kt
index ee384b6..441d8ca 100644
--- a/app/src/main/java/com/example/infrastudy/APIServiceImp.kt
+++ b/app/src/main/java/com/example/infrastudy/APIServiceImp.kt
@@ -3,10 +3,11 @@ package com.example.infrastudy
import okhttp3.OkHttpClient
import retrofit2.Retrofit
import retrofit2.converter.gson.GsonConverterFactory
+import retrofit2.create
import java.util.concurrent.TimeUnit
object APIServiceImp {
- private const val BASE_URL = "http://133.186.159.229:80/"
+ private const val BASE_URL = "http://dev-api-team2.openinfra-kr.org/"
//"http://10.0.2.2"
//"http://133.186.223.119:80"
@@ -23,5 +24,6 @@ object APIServiceImp {
val getPostInterface =retrofit.create(GetPostInterface::class.java)
val imageInterface= retrofit.create(ImageInterface::class.java)
val deleteInterface= retrofit.create(DeleteInterface::class.java)
+ val getUserInterface=retrofit.create(GetUserInterface::class.java)
}
diff --git a/app/src/main/java/com/example/infrastudy/LoginActivity.kt b/app/src/main/java/com/example/infrastudy/LoginActivity.kt
index b1ef1ef..d4474cd 100644
--- a/app/src/main/java/com/example/infrastudy/LoginActivity.kt
+++ b/app/src/main/java/com/example/infrastudy/LoginActivity.kt
@@ -1,4 +1,5 @@
-package com.example.infrastudy
+package com.example.infrastud
+
import android.content.Intent
import androidx.appcompat.app.AppCompatActivity
@@ -6,6 +7,7 @@ import android.os.Bundle
import android.util.Log
import android.webkit.CookieManager
import android.widget.Toast
+import com.example.infrastudy.*
import com.example.infrastudy.databinding.ActivityLoginBinding
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
@@ -18,6 +20,7 @@ import retrofit2.Response
class LoginActivity : AppCompatActivity() {
lateinit var binding: ActivityLoginBinding
+ var data=ArrayList()
companion object {
const val TAG = "LoginActivty"
@@ -28,33 +31,56 @@ class LoginActivity : AppCompatActivity() {
binding = ActivityLoginBinding.inflate(layoutInflater)
setContentView(binding.root)
postInformation()
+ initData()
binding.userid.setText("fantasy7772")
binding.userpw.setText("123123k")
binding.username.setText("jinuk")
}
+ private fun initData(){
+ var response_GetUserRequest:Response?>
+ CoroutineScope(Dispatchers.Main).launch {
+ withContext(Dispatchers.IO){
+ response_GetUserRequest= APIServiceImp.getUserInterface.GetUserRequest()
+ Log.i("userdata",response_GetUserRequest.body().toString())
+ }
+ response_GetUserRequest.body()?.let{data.addAll(it)}
+
+ }
+
+
+ }
private fun postInformation() {
binding.apply {
button3.setOnClickListener {
- var response_Join: Response
- CoroutineScope(Dispatchers.Main).launch {
- withContext(Dispatchers.IO) {
- response_Join = APIServiceImp.joinInterface.postJoinRequest(
- userid = userid.text.toString(),
- userpw = userpw.text.toString(),
- username = username.text.toString()
- )
- if (response_Join != null) {
- Log.i("message", "join success")
+ var check=true
+ for(i in 0 until data.count()){
+ if(data[i].userid==binding.userid.text.toString()){
+ Toast.makeText(this@LoginActivity, "중복된 ID 입니다", Toast.LENGTH_SHORT).show()
+ check=false
+ }
+ }
+ if(check==true) {
+ var response_Join: Response
+ CoroutineScope(Dispatchers.Main).launch {
+ withContext(Dispatchers.IO) {
+ response_Join = APIServiceImp.joinInterface.postJoinRequest(
+ userid = userid.text.toString(),
+ userpw = userpw.text.toString(),
+ username = username.text.toString()
+ )
+ if (response_Join != null) {
+ Log.i("message", "join success")
- } else {
- Log.i("message", "join failed")
+ } else {
+ Log.i("message", "join failed")
+ }
+ }
+ if (response_Join != null) {
+ val i = Intent(this@LoginActivity, MainActivity::class.java)
+ i.putExtra("cur_user", userid.text.toString())
+ startActivity(i)
}
- }
- if(response_Join!=null){
- val i= Intent(this@LoginActivity, MainActivity::class.java)
- i.putExtra("cur_user", userid.text.toString())
- startActivity(i)
}
}
}
@@ -72,11 +98,14 @@ class LoginActivity : AppCompatActivity() {
Log.i("message", "login failed")
}
}
- if(response_Login!=null){
+ if(response_Login.body()!!.msg =="success"){
val i= Intent(this@LoginActivity, MainActivity::class.java)
i.putExtra("cur_user", userid.text.toString())
startActivity(i)
}
+ else{
+ Toast.makeText(this@LoginActivity, "로그인 실패", Toast.LENGTH_SHORT).show()
+ }
}
}
}