Skip to content

Commit

Permalink
Merge pull request #159 from Team-Ampersand/feature/158_create_regula…
Browse files Browse the repository at this point in the history
…r_expression

🔀 :: (#158) create regular expression
  • Loading branch information
diejdkll authored Feb 24, 2024
2 parents 2b9d424 + a2a1834 commit e778013
Show file tree
Hide file tree
Showing 8 changed files with 74 additions and 33 deletions.
2 changes: 1 addition & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
android:fullBackupContent="@xml/backup_rules"
android:icon="@mipmap/logo"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:roundIcon="@mipmap/logo"
android:supportsRtl="true"
android:theme="@style/Theme.DotoriAndroid"
tools:targetApi="31">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.msg.presentation.view.login

import android.annotation.SuppressLint
import android.util.Log
import android.widget.Toast
import androidx.compose.foundation.background
import androidx.compose.foundation.clickable
import androidx.compose.foundation.interaction.MutableInteractionSource
Expand All @@ -16,13 +16,15 @@ import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.material.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.focus.onFocusChanged
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.text.input.PasswordVisualTransformation
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.tooling.preview.Preview
Expand All @@ -37,9 +39,9 @@ import com.dotori.dotori_components.theme.LockIcon
import com.dotori.dotori_components.theme.PersonIcon
import com.dotori.dotori_components.theme.XMarkIcon
import com.msg.domain.model.auth.LoginRequestModel
import com.msg.domain.model.auth.LoginResponseModel
import com.msg.presentation.viewmodel.LoginViewModel
import com.msg.presentation.viewmodel.util.Event
import com.msg.presentation.view.util.isStrongEmail

@SuppressLint("RememberReturnType")
@Composable
Expand All @@ -49,16 +51,21 @@ fun LoginScreen(
navigateToMain: () -> Unit,
navigateToSignUp: () -> Unit
) {
val context = LocalContext.current
var idText by remember { mutableStateOf("") }
var passwordText by remember { mutableStateOf("") }
var isIdClicked by remember { mutableStateOf(false) }
var isPasswordClicked by remember { mutableStateOf(false) }

val loginUiState by loginViewModel.loginState.collectAsState()

when (loginUiState) {
is Event.Success -> navigateToMain()
else -> {}
LaunchedEffect(loginUiState) {
when (loginUiState) {
is Event.Success -> navigateToMain()
is Event.BadRequest -> Toast.makeText(context, "비밀번호가 일치하지 않습니다.", Toast.LENGTH_SHORT).show()
is Event.NotFound -> Toast.makeText(context, "해당 유저가 존재하지 않습니다.", Toast.LENGTH_SHORT).show()
else -> Unit
}
}

Column(
Expand Down Expand Up @@ -144,12 +151,16 @@ fun LoginScreen(
.height(52.dp),
text = "로그인"
) {
loginViewModel.login(
LoginRequestModel(
email = idText,
password = passwordText
if (isStrongEmail(idText)) {
loginViewModel.login(
LoginRequestModel(
email = idText,
password = passwordText
)
)
)
} else {
Toast.makeText(context, "gsm메일 형식에 맞게 입력해주세요.", Toast.LENGTH_SHORT).show()
}
}
Spacer(modifier = Modifier.height(16.dp))
Row(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.msg.presentation.view.signup

import android.widget.Toast
import androidx.compose.foundation.background
import androidx.compose.foundation.clickable
import androidx.compose.foundation.interaction.MutableInteractionSource
Expand All @@ -22,6 +23,7 @@ import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.focus.onFocusChanged
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.unit.dp
import androidx.lifecycle.ViewModelStoreOwner
Expand All @@ -35,6 +37,7 @@ import com.dotori.dotori_components.theme.XMarkIcon
import com.msg.domain.model.email.EmailVerifyRequestModel
import com.msg.domain.model.email.SendEmailRequestModel
import com.msg.presentation.view.signup.component.SignUpDatIndicator
import com.msg.presentation.view.util.isStrongEmail
import com.msg.presentation.viewmodel.util.Event
import com.msg.presentation.viewmodel.util.SignUpViewModelProvider

Expand All @@ -47,6 +50,7 @@ fun AuthenticationScreen(
navigateToPassword: () -> Unit
) {
SignUpViewModelProvider(viewModelStoreOwner = viewModelStoreOwner) { signUpViewModel ->
val context = LocalContext.current
var emailText by remember { mutableStateOf("") }
var numberText by remember { mutableStateOf("") }
var isEmailClicked by remember { mutableStateOf(false) }
Expand Down Expand Up @@ -140,8 +144,12 @@ fun AuthenticationScreen(
.height(52.dp),
text = "인증하기"
) {
signUpViewModel.email.value = emailText
signUpViewModel.sendEmail(SendEmailRequestModel(signUpViewModel.email.value))
if (isStrongEmail(emailText)) {
signUpViewModel.email.value = emailText
signUpViewModel.sendEmail(SendEmailRequestModel(signUpViewModel.email.value))
} else {
Toast.makeText(context, "gsm메일 형식에 맞게 입력해주세요.", Toast.LENGTH_SHORT).show()
}
}
}
Spacer(modifier = Modifier.height(24.dp))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.msg.presentation.view.signup

import android.widget.Toast
import androidx.compose.foundation.background
import androidx.compose.foundation.clickable
import androidx.compose.foundation.interaction.MutableInteractionSource
Expand All @@ -22,6 +23,7 @@ import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.focus.onFocusChanged
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.text.input.PasswordVisualTransformation
import androidx.compose.ui.text.input.VisualTransformation
import androidx.compose.ui.text.style.TextAlign
Expand All @@ -38,6 +40,7 @@ import com.dotori.dotori_components.theme.EyeOpenIcon
import com.dotori.dotori_components.theme.XMarkIcon
import com.msg.domain.model.auth.SignUpRequestModel
import com.msg.presentation.view.signup.component.SignUpDatIndicator
import com.msg.presentation.view.util.isStrongPassword
import com.msg.presentation.viewmodel.util.Event
import com.msg.presentation.viewmodel.util.SignUpViewModelProvider

Expand All @@ -49,6 +52,7 @@ fun PasswordScreen(
navigateToLogin: () -> Unit
) {
SignUpViewModelProvider(viewModelStoreOwner = viewModelStoreOwner) { signUpViewModel ->
val context = LocalContext.current
var passwordText by remember { mutableStateOf("") }
var checkPasswordText by remember { mutableStateOf("") }
var isPasswordVisible by remember { mutableStateOf(false) }
Expand Down Expand Up @@ -190,7 +194,11 @@ fun PasswordScreen(
.height(52.dp),
text = "회원가입"
) {
if (passwordText == checkPasswordText) {
if (passwordText != checkPasswordText) {
Toast.makeText(context, "비밀번호가 서로 일치하지 않습니다..", Toast.LENGTH_SHORT).show()
} else if (!isStrongPassword(passwordText)) {
Toast.makeText(context, "비밀번호 형식에 맞게 입력해주세요.", Toast.LENGTH_SHORT).show()
} else {
signUpViewModel.password.value = passwordText
signUpViewModel.signUp(
SignUpRequestModel(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.msg.presentation.view.util

fun isStrongEmail(email: String): Boolean {
val regex = Regex("^s\\d{5}@gsm\\.hs\\.kr\$")
return regex.matches(email)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.msg.presentation.view.util

fun isStrongPassword(password: String): Boolean {
val regex = Regex("^(?=.*[A-Za-z])(?=.*\\d)(?=.*[@\$!%*#?&])[A-Za-z\\d@\$!%*#?&]{8,20}\$")
return regex.matches(password)
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,23 +27,24 @@ class LoginViewModel @Inject constructor(
val loginState = _loginState.asStateFlow()

fun login(loginRequestModel: LoginRequestModel) = viewModelScope.launch {
loginUseCase(loginRequestModel)
.onSuccess {
_loginState.value = Event.Success(it)
saveTokenUseCase(
accessToken = it.accessToken,
refreshToken = it.refreshToken,
expiresAt = it.expiresAt
)
saveRoleUseCase(it.roles.toString())
Log.d("failure", "success")
}
.onFailure {
Log.d("failure", it.message.toString())
it.exceptionHandling(
badRequestAction = { _loginState.value = Event.BadRequest },
notFoundAction = { _loginState.value = Event.NotFound }
)
}
}
_loginState.value = Event.Loading
loginUseCase(loginRequestModel)
.onSuccess {
_loginState.value = Event.Success(it)
saveTokenUseCase(
accessToken = it.accessToken,
refreshToken = it.refreshToken,
expiresAt = it.expiresAt
)
saveRoleUseCase(it.roles.toString())
Log.d("failure", "success")
}
.onFailure {
Log.d("failure", it.message.toString())
it.exceptionHandling(
badRequestAction = { _loginState.value = Event.BadRequest },
notFoundAction = { _loginState.value = Event.NotFound }
)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ class SignUpViewModel @Inject constructor(


fun signUp(body: SignUpRequestModel) = viewModelScope.launch {
_signUpState.value = Event.Loading
signUpUseCase(body)
.onSuccess {
_signUpState.value = Event.Success()
Expand Down

0 comments on commit e778013

Please sign in to comment.