Skip to content

Commit

Permalink
Merge pull request #55 from PawWithU/feature/login
Browse files Browse the repository at this point in the history
feat/login: 중개자 로그인 api 연결 및 로그인 실패시 에러 메세지 출력
  • Loading branch information
kang9366 authored Nov 23, 2023
2 parents f5c3e8c + 9b7e84c commit df3df84
Show file tree
Hide file tree
Showing 111 changed files with 113 additions and 33 deletions.
29 changes: 29 additions & 0 deletions app/google-services.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"project_info": {
"project_number": "260494595521",
"project_id": "connectdog-8ace1",
"storage_bucket": "connectdog-8ace1.appspot.com"
},
"client": [
{
"client_info": {
"mobilesdk_app_id": "1:260494595521:android:4082b77d97edb83f428b40",
"android_client_info": {
"package_name": "com.kusitms.connectdog"
}
},
"oauth_client": [],
"api_key": [
{
"current_key": "AIzaSyDqQ5mEJVaoopO1yxSahoDXJ4D6EvUf15U"
}
],
"services": {
"appinvite_service": {
"other_platform_oauth_client": []
}
}
}
],
"configuration_version": "1"
}
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,12 @@ internal interface ApiService {
@Body loginBody: NormalLoginBody
): LoginResponseItem

@Headers("Content-Type: application/json")
@POST("/intermediaries/login")
suspend fun postIntermediatorLoginData(
@Body loginBody: NormalLoginBody
): LoginResponseItem

@POST("/volunteers/login/social")
suspend fun postSocialLoginData(
@Body socialLoginBody: SocialLoginBody
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,8 @@ interface LoginRepository {
suspend fun postSocialLoginData(
socialLoginBody: SocialLoginBody
): LoginResponseItem

suspend fun postIntermediatorLoginData(
loginBody: NormalLoginBody
): LoginResponseItem
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,8 @@ internal class LoginRepositoryImpl @Inject constructor(
socialLoginBody
)
}

override suspend fun postIntermediatorLoginData(loginBody: NormalLoginBody): LoginResponseItem {
return api.postIntermediatorLoginData(loginBody)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
Expand Down Expand Up @@ -122,7 +123,7 @@ fun ConnectDogCardButton(
}

@Composable
fun ErrorCard() {
fun ConnectDogErrorCard() {
Card(
colors =
CardDefaults.cardColors(
Expand All @@ -132,7 +133,6 @@ fun ErrorCard() {
Modifier
.fillMaxWidth()
.height(40.dp)
.padding(horizontal = 20.dp)
) {
Row(
modifier =
Expand All @@ -147,7 +147,7 @@ fun ErrorCard() {
)
Spacer(modifier = Modifier.width(6.dp))
Text(
text = "이메일 혹은 비밀번호가 일치하지 않습니다.",
text = stringResource(id = R.string.login_error),
color = Red1,
fontSize = 13.sp
)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.kusitms.connectdog.core.designsystem.component

import android.annotation.SuppressLint
import androidx.annotation.StringRes
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.fillMaxWidth
Expand Down Expand Up @@ -30,6 +31,7 @@ import androidx.compose.ui.text.input.VisualTransformation
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import com.kusitms.connectdog.core.designsystem.R
import com.kusitms.connectdog.core.designsystem.theme.ConnectDogTheme
import com.kusitms.connectdog.core.designsystem.theme.Gray3
import com.kusitms.connectdog.core.designsystem.theme.Gray4
Expand All @@ -45,7 +47,7 @@ fun ConnectDogTextField(
imeAction: ImeAction = ImeAction.Next,
keyboardType: KeyboardType = KeyboardType.Text,
isError: Boolean = false,
@StringRes errorMessageRes: Int = 0,
@SuppressLint("PrivateResource") @StringRes errorMessageRes: Int = androidx.compose.ui.R.string.default_error_message,
height: Int = 65
) {
val visualTransformation =
Expand Down Expand Up @@ -114,15 +116,17 @@ fun NormalTextField(
height: Int = 65,
modifier: Modifier = Modifier,
onTextChanged: (String) -> Unit = {},
text: String = ""
text: String = "",
isError: Boolean = false
) {
ConnectDogTextField(
text = text,
onTextChanged = onTextChanged,
label = label,
placeholder = placeholder,
keyboardType = keyboardType,
height = height
height = height,
isError = isError
)
}

Expand Down Expand Up @@ -185,14 +189,16 @@ fun ConnectDogTextFieldWithButton(
keyboardType: KeyboardType = KeyboardType.Text,
padding: Int,
onclick: () -> Unit = {},
onTextChanged: (String) -> Unit = {}
onTextChanged: (String) -> Unit = {},
isError: Boolean = false
) {
Box {
NormalTextField(
label = textFieldLabel,
placeholder = placeholder,
keyboardType = keyboardType,
onTextChanged = onTextChanged
onTextChanged = onTextChanged,
isError = isError
)

ConnectDogOutlinedButton(
Expand Down
1 change: 1 addition & 0 deletions core/designsystem/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,5 @@
<string name="phone">전화번호</string>
<string name="vehicle">이동봉사 수단</string>
<string name="volunteer_comment">봉사자의 한마디</string>
<string name="login_error">아이디 혹은 비밀번호가 일치하지 않습니다</string>
</resources>
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,7 @@ private fun Content() {
buttonLabel = "인증 요청",
keyboardType = KeyboardType.Number,
padding = 5
) {
}
)
Spacer(modifier = Modifier.height(12.dp))
ConnectDogTextFieldWithButton(
width = 62,
Expand All @@ -92,8 +91,7 @@ private fun Content() {
buttonLabel = "인증 확인",
keyboardType = KeyboardType.Number,
padding = 5
) {
}
)
}
}

Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,13 @@ constructor(
private val _volunteerLoginSuccess = MutableLiveData<LoginResponseItem?>()
val volunteerLoginSuccess: LiveData<LoginResponseItem?> = _volunteerLoginSuccess

private val _intermediatorLoginSuccess = MutableLiveData<LoginResponseItem?>()
val intermediatorLoginSuccess: LiveData<LoginResponseItem?> = _intermediatorLoginSuccess

private val _loginError = MutableLiveData<String>()
val loginError: LiveData<String> = _loginError

fun normalLogin(email: String, password: String) {
fun normalVolunteerLogin(email: String, password: String) {
viewModelScope.launch {
try {
val response = loginRepository.postLoginData(NormalLoginBody(email, password))
Expand All @@ -64,6 +67,22 @@ constructor(
}
}

fun intermediatorLogin(email: String, password: String) {
viewModelScope.launch {
try {
val response = loginRepository.postIntermediatorLoginData(NormalLoginBody(email, password))
_intermediatorLoginSuccess.postValue(response)

viewModelScope.launch {
dataStoreRepository.saveAccessToken(response.accessToken)
}
} catch (e: Exception) {
_loginError.postValue(e.message ?: "로그인 실패")
Log.d(TAG, e.message.toString())
}
}
}

private fun postSocialLoginData(provider: Provider, accessToken: String) {
viewModelScope.launch {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import androidx.compose.ui.unit.dp
import androidx.hilt.navigation.compose.hiltViewModel
import androidx.navigation.NavController
import com.kusitms.connectdog.core.designsystem.R
import com.kusitms.connectdog.core.designsystem.component.ConnectDogErrorCard
import com.kusitms.connectdog.core.designsystem.component.ConnectDogTopAppBar
import com.kusitms.connectdog.core.designsystem.component.NormalTextField
import com.kusitms.connectdog.core.designsystem.component.TopAppBarNavigationType
Expand All @@ -46,16 +47,22 @@ fun EmailLoginScreen(
val focusManager = LocalFocusManager.current
val interactionSource = remember { MutableInteractionSource() }
val volunteerLoginSuccess by viewModel.volunteerLoginSuccess.observeAsState()
val intermediatorLoginSuccess by viewModel.intermediatorLoginSuccess.observeAsState()
val loginFail by viewModel.loginError.observeAsState(null)

var isError = false

if (volunteerLoginSuccess != null) {
Log.d(TAG, volunteerLoginSuccess.toString())
initVolunteer()
when (volunteerLoginSuccess!!.roleName) {
"VOLUNTEER" -> initVolunteer()
"INTERMEDIARY" -> initIntermediator()
}
}

if (intermediatorLoginSuccess != null) {
initIntermediator()
}

if (loginFail != null) { isError = true }

Scaffold(
modifier = Modifier.clickable(
onClick = { focusManager.clearFocus() },
Expand All @@ -73,12 +80,12 @@ fun EmailLoginScreen(
)
}
) {
Content(initVolunteer, viewModel)
Content(initVolunteer, viewModel, isError)
}
}

@Composable
private fun Content(onClick: () -> Unit, viewModel: LoginViewModel) {
private fun Content(onClick: () -> Unit, viewModel: LoginViewModel, isError: Boolean) {
Column(
modifier = Modifier
.fillMaxSize()
Expand All @@ -104,27 +111,34 @@ private fun Content(onClick: () -> Unit, viewModel: LoginViewModel) {
label = "이메일",
placeholder = "이메일 입력",
keyboardType = KeyboardType.Text,
onTextChanged = onPhoneNumberChanged
onTextChanged = onPhoneNumberChanged,
isError = isError
)
Spacer(modifier = Modifier.height(12.dp))
NormalTextField(
text = password,
label = "비밀번호",
placeholder = "비밀번호 입력",
keyboardType = KeyboardType.Password,
onTextChanged = onPasswordChanged
onTextChanged = onPasswordChanged,
isError = isError
)
Spacer(modifier = Modifier.height(12.dp))
NormalButton(
content = "로그인",
color = MaterialTheme.colorScheme.primary,
onClick = {
viewModel.normalLogin(phoneNumber, password)
viewModel.normalVolunteerLogin(phoneNumber, password)
viewModel.intermediatorLogin(phoneNumber, password)
},
modifier = Modifier
.fillMaxWidth()
.height(56.dp)
)
Spacer(modifier = Modifier.height(12.dp))
if (isError) {
ConnectDogErrorCard()
}
}

Spacer(modifier = Modifier.weight(1f))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,7 @@ fun RegisterEmailScreen(
placeholder = "이메일 입력",
buttonLabel = "인증 요청",
padding = 5
) {
}
)
Spacer(modifier = Modifier.height(12.dp))

ConnectDogTextFieldWithButton(
Expand All @@ -84,8 +83,7 @@ fun RegisterEmailScreen(
placeholder = "숫자 6자리",
buttonLabel = "인증 확인",
padding = 5
) {
}
)
}
NormalButton(
content = "다음",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,7 @@ fun ProfileScreen(navigator: NavController, viewModel: SelectProfileImageViewMod
placeholder = "닉네임 입력",
buttonLabel = "중복 확인",
padding = 5
) {
}
)
Text(
text = "사용할 수 있는 닉네임입니다.",
color = PetOrange,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ internal fun MainScreen(navigator: MainNavigator = rememberMainNavigator()) {
mypageNavGraph(
padding = it,
onClick = {},
onLogoutClick = {},
onBackClick = navigator::popBackStackIfNotHome,
onEditProfileClick = { navigator.navigateEditProfile() },
onManageAccountClick = { navigator.navigateManageAccount() },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,7 @@ private fun Content() {
placeholder = "닉네임 입력",
buttonLabel = "중복 확인",
padding = 5
) {
}
)
Spacer(modifier = Modifier.weight(1f))
NormalButton(content = "완료")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ import com.kusitms.connectdog.core.designsystem.theme.Gray4
fun SettingScreen(
onBackClick: () -> Unit,
onManageAccountClick: () -> Unit,
onLogoutClick: () -> Unit = {}
onLogoutClick: () -> Unit
) {
Scaffold(
topBar = {
Expand All @@ -54,7 +54,7 @@ fun SettingScreen(
@Composable
private fun Content(
onClick: () -> Unit,
onLogout: () -> Unit
onLogoutClick: () -> Unit
) {
var checked by remember { mutableStateOf(true) }

Expand Down Expand Up @@ -118,7 +118,7 @@ private fun Content(
fontSize = 16.sp,
color = Gray2,
modifier = Modifier.clickable {
onLogout()
onLogoutClick()
}
)
}
Expand Down
Loading

0 comments on commit df3df84

Please sign in to comment.