Skip to content

Commit

Permalink
비밀번호 초기화 로직 변경 (#375)
Browse files Browse the repository at this point in the history
  • Loading branch information
JuTaK97 authored Oct 30, 2024
1 parent f982a66 commit daa3c16
Show file tree
Hide file tree
Showing 20 changed files with 1,155 additions and 354 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,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.dp
import androidx.compose.ui.unit.sp
import com.wafflestudio.snutt2.ui.SNUTTColors
import com.wafflestudio.snutt2.ui.SNUTTTypography

Expand All @@ -46,6 +47,8 @@ fun EditText(
value: String,
onValueChange: (String) -> Unit,
hint: String? = null,
hintTextColor: Color = SNUTTColors.EditTextHint,
hintTextStyle: TextStyle = SNUTTTypography.body1.copy(fontSize = 15.sp),
underlineEnabled: Boolean = true,
underlineColor: Color = SNUTTColors.Gray200,
underlineColorFocused: Color = SNUTTColors.Black900,
Expand Down Expand Up @@ -86,11 +89,11 @@ fun EditText(
modifier = Modifier.weight(1f),
) {
it()
if (value.isEmpty() && isFocused.not()) { // FIXME: lectureDetail 에서는 focus 되어 있어도 empty이면 hint 가 나와야 한다.
if (value.isEmpty()) {
hint?.let {
Text(
text = it,
style = textStyle.copy(color = SNUTTColors.Gray200),
style = hintTextStyle.copy(color = hintTextColor),
)
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
package com.wafflestudio.snutt2.components.compose

import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.text.BasicTextField
import androidx.compose.foundation.text.KeyboardActions
import androidx.compose.foundation.text.KeyboardOptions
import androidx.compose.foundation.text.selection.LocalTextSelectionColors
import androidx.compose.foundation.text.selection.TextSelectionColors
import androidx.compose.material.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.CompositionLocalProvider
import androidx.compose.runtime.LaunchedEffect
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.graphics.Color
import androidx.compose.ui.graphics.SolidColor
import androidx.compose.ui.platform.LocalFocusManager
import androidx.compose.ui.text.TextStyle
import androidx.compose.ui.text.input.TextFieldValue
import androidx.compose.ui.text.input.VisualTransformation
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import com.wafflestudio.snutt2.ui.SNUTTColors
import com.wafflestudio.snutt2.ui.SNUTTTypography

@Composable
fun EditTextFieldValue(
modifier: Modifier = Modifier,
leadingIcon: @Composable (() -> Unit) = {},
trailingIcon: @Composable (() -> Unit) = {},
keyboardOptions: KeyboardOptions = KeyboardOptions(),
keyboardActions: KeyboardActions = KeyboardActions(),
singleLine: Boolean = false,
enabled: Boolean = true,
visualTransformation: VisualTransformation = VisualTransformation.None,
value: TextFieldValue,
onValueChange: (TextFieldValue) -> Unit,
hint: String? = null,
hintTextColor: Color = SNUTTColors.EditTextHint,
hintTextStyle: TextStyle = SNUTTTypography.body1.copy(fontSize = 15.sp),
underlineEnabled: Boolean = true,
underlineColor: Color = SNUTTColors.Gray200,
underlineColorFocused: Color = SNUTTColors.Black900,
underlineWidth: Dp = 1.dp,
clearFocusFlag: Boolean = false,
textStyle: TextStyle = SNUTTTypography.subtitle1.copy(color = SNUTTColors.Black900),
) {
val focusManager = LocalFocusManager.current
LaunchedEffect(clearFocusFlag) {
if (clearFocusFlag) focusManager.clearFocus()
}

var isFocused by remember { mutableStateOf(false) }
val customTextSelectionColors = TextSelectionColors(
handleColor = SNUTTColors.Black900,
backgroundColor = SNUTTColors.Black300,
)
CompositionLocalProvider(
LocalTextSelectionColors provides customTextSelectionColors,
) {
BasicTextField(
modifier = modifier
.onFocusChanged { isFocused = it.isFocused },
keyboardOptions = keyboardOptions,
keyboardActions = keyboardActions,
value = value,
textStyle = textStyle,
enabled = enabled,
onValueChange = onValueChange,
singleLine = singleLine,
visualTransformation = visualTransformation,
cursorBrush = SolidColor(SNUTTColors.Black900),
decorationBox = {
Column {
Row(modifier = Modifier.fillMaxWidth()) {
leadingIcon()
Box(
modifier = Modifier.weight(1f),
) {
it()
if (value.text.isEmpty()) {
hint?.let {
Text(
text = it,
style = hintTextStyle.copy(color = hintTextColor),
)
}
}
}
trailingIcon()
}

if (underlineEnabled) {
Box(
modifier = Modifier
.padding(top = 8.dp)
.background(if (isFocused) underlineColorFocused else underlineColor)
.fillMaxWidth()
.height(underlineWidth),
)
}
}
},
)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
package com.wafflestudio.snutt2.components.compose

import androidx.compose.animation.AnimatedContent
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
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.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.drawWithCache
import androidx.compose.ui.geometry.Offset
import androidx.compose.ui.graphics.ColorFilter
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import com.wafflestudio.snutt2.ui.SNUTTColors
import com.wafflestudio.snutt2.ui.SNUTTTypography

@Composable
fun IOSStyleTopBar(
modifier: Modifier = Modifier,
title: String,
backButtonText: String,
onBack: () -> Unit,
) {
Box(
modifier = modifier
.fillMaxWidth()
.background(color = SNUTTColors.White900)
.height(40.dp)
.drawWithCache {
onDrawWithContent {
drawLine(
color = SNUTTColors.EditTextHint,
start = Offset(0f, this.size.height), end = Offset(this.size.width, this.size.height),
strokeWidth = 0.5.dp.toPx(),
)
drawContent()
}
}
.padding(horizontal = 5.dp),
contentAlignment = Alignment.CenterStart,
) {
Row(
modifier = Modifier.clicks(1000L) { onBack() },
verticalAlignment = Alignment.CenterVertically,
) {
ArrowBackIcon(
colorFilter = ColorFilter.tint(SNUTTColors.Black900),
)
AnimatedContent(backButtonText, label = "") {
Text(
text = it,
style = SNUTTTypography.button,
)
}
}
Box(modifier = Modifier.fillMaxSize(), contentAlignment = Alignment.Center) {
Text(
text = title,
style = SNUTTTypography.h3,
)
}
}
}

@Preview
@Composable
fun IOSStyleTopBarPreview() {
IOSStyleTopBar(
title = "비밀번호 재설정",
backButtonText = "로그인",
) { }
}
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,13 @@ fun CustomDialog(
}
}
}
} ?: positiveButtonText?.let {
Row(modifier = Modifier.padding(vertical = 20.dp, horizontal = 30.dp)) {
Box(modifier = Modifier.weight(1f))
Box(modifier = Modifier.clicks { onConfirm() }) {
Text(text = positiveButtonText, style = SNUTTTypography.body1)
}
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package com.wafflestudio.snutt2.components.compose
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
Expand All @@ -22,8 +23,8 @@ fun WebViewStyleButton(
Box(
modifier = modifier
.clicks { if (enabled) onClick() }
.background(if (enabled) enabledColor else disabledColor)
.height(60.dp),
.background(shape = RoundedCornerShape(6.dp), color = if (enabled) enabledColor else disabledColor)
.height(47.dp),
contentAlignment = Alignment.Center,
) {
content()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ interface UserRepository {

suspend fun verifyPwResetCode(id: String, code: String)

suspend fun resetPassword(id: String, password: String)
suspend fun resetPassword(id: String, password: String, code: String)

suspend fun sendCodeToEmail(email: String)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -258,9 +258,9 @@ class UserRepositoryImpl @Inject constructor(
)
}

override suspend fun resetPassword(id: String, password: String) {
override suspend fun resetPassword(id: String, password: String, code: String) {
api._postResetPassword(
PostResetPasswordParams(id, password),
PostResetPasswordParams(id, password, code),
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,4 +173,6 @@ object SNUTTStringUtils {
append("(${quota - freshmanQuota})")
}
}.toString()

fun String.isValidPassword(): Boolean = Regex("^(?=.*[A-Za-z])(?=.*\\d)[A-Za-z\\d]{6,20}$").matches(this)
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ import com.squareup.moshi.JsonClass
data class PostResetPasswordParams(
@Json(name = "user_id") val id: String,
@Json(name = "password") val password: String,
@Json(name = "code") val code: String,
)
4 changes: 4 additions & 0 deletions app/src/main/java/com/wafflestudio/snutt2/ui/Colors.kt
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ object SNUTTColors {

val VacancyRed = Color(0xffed6c58)

val EditTextLabel = Color(0xff8a898e)
val EditTextHint = Color(0xffc4c4c4)
val EditTextUnderline = Color(0xffdcdcde)

val Colors.VacancyBlue @Composable get() = if (isLight) Color(0xff446cc2) else Color(0xff7aaaf3)
val VacancyBlue @Composable get() = MaterialTheme.colors.VacancyBlue

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ import com.wafflestudio.snutt2.views.logged_in.table_lectures.LecturesOfTablePag
import com.wafflestudio.snutt2.views.logged_in.vacancy_noti.VacancyPage
import com.wafflestudio.snutt2.views.logged_in.vacancy_noti.VacancyViewModel
import com.wafflestudio.snutt2.views.logged_out.*
import com.wafflestudio.snutt2.views.logged_out.reset_password.ResetPasswordPage
import dagger.hilt.android.AndroidEntryPoint
import kotlinx.coroutines.launch
import javax.inject.Inject
Expand Down Expand Up @@ -348,7 +349,7 @@ class RootActivity : AppCompatActivity() {
}

composable2(NavigationDestination.FindPassword) {
FindPasswordPage()
ResetPasswordPage()
}

composable2(NavigationDestination.EmailVerification) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,8 @@ class UserViewModel @Inject constructor(
userRepository.verifyPwResetCode(id, code)
}

suspend fun resetPassword(id: String, password: String) {
userRepository.resetPassword(id, password)
suspend fun resetPassword(id: String, password: String, code: String) {
userRepository.resetPassword(id, password, code)
}

suspend fun sendCodeToEmail(email: String) {
Expand Down
Loading

0 comments on commit daa3c16

Please sign in to comment.