Skip to content

Commit

Permalink
feat: Fix # presentation (#100):
Browse files Browse the repository at this point in the history
Add new features for registering properly. Also, add validation logics to # screen.
  • Loading branch information
behzodhalil committed Oct 9, 2023
1 parent e1d3a14 commit ebc5520
Show file tree
Hide file tree
Showing 12 changed files with 538 additions and 187 deletions.
28 changes: 28 additions & 0 deletions androidApp/proguard-rules.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Add project specific ProGuard rules here.
# You can control the set of applied configuration files using the
# proguardFiles setting in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html

# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}

# Uncomment this to preserve the line number information for
# debugging stack traces.
#-keepattributes SourceFile,LineNumberTable

# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile

-keepclassmembers enum * {
public static **[] values();
public static ** valueOf(java.lang.String);
}

-keepnames class * implements android.os.Parcelable*
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ interface NameValidation {
class DefaultNameValidation : NameValidation {

override fun execute(name: String): Boolean {
return name.length in 2..20 && name.all { it.isLetter() }
return name.length in 3..15 && name.all { it.isLetter() }
}
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
package io.spherelabs.validation

interface PasswordValidation {
interface PasswordValidation {
suspend fun execute(password: String): Boolean
}

class DefaultPasswordValidation : PasswordValidation {

override suspend fun execute(password: String): Boolean {
return password.length in 6..30 && password.any { it.isLowerCase() }
return password.length in 6..16 &&
password.any { it.isLowerCase() } &&
password.any { it.isUpperCase() } &&
password.any { it.isDigit() }
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package io.spherelabs.authpresentation.signin

import io.spherelabs.authdomain.HasCurrentUserExist
import io.spherelabs.authdomain.NameValidation
import io.spherelabs.authdomain.PasswordValidation
import io.spherelabs.authdomain.SignInWithEmailAndPassword
import io.spherelabs.meteor.middleware.Middleware

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package io.spherelabs.authpresentation.signin

import io.spherelabs.authdomain.EmailValidation
import io.spherelabs.authdomain.PasswordValidation

import io.spherelabs.meteor.middleware.Middleware
import io.spherelabs.validation.EmailValidation
import io.spherelabs.validation.PasswordValidation

class SignInValidateMiddleware(
private val validatePassword: PasswordValidation,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,30 +4,32 @@ import io.spherelabs.authdomain.CreateEmailAndPassword
import io.spherelabs.meteor.middleware.Middleware

class #Middleware(private val createEmailAndPassword: CreateEmailAndPassword) :
Middleware<#State, #Wish> {
Middleware<#State, #Wish> {

override suspend fun process(
state: #State,
wish: #Wish,
next: suspend (#Wish) -> Unit
) {
when (wish) {
#Wish.# -> {
val result =
createEmailAndPassword.execute(
email = state.email,
password = state.password,
name = state.name
)
override suspend fun process(
state: #State,
wish: #Wish,
next: suspend (#Wish) -> Unit,
) {
when (wish) {
#Wish.# -> {
val result =
createEmailAndPassword.execute(
email = state.email,
password = state.password,
name = state.name,
keyPassword = state.keyPassword
)

result
.onSuccess { next.invoke(#Wish.#Success) }
.onFailure { newException ->
val failureMsg = newException.message ?: "Error is occurred!"
next.invoke(#Wish.#Failure(failureMsg))
}
}
else -> {}
result
.onSuccess { next.invoke(#Wish.#Success) }
.onFailure { newException ->
val failureMsg = newException.message ?: "Error is occurred!"
next.invoke(#Wish.#Failure(failureMsg))
}
}

else -> {}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,47 +8,109 @@ import io.spherelabs.meteor.reducer.Reducer

class #Reducer : Reducer<#State, #Wish, #Effect> {

override fun reduce(state: #State, wish: #Wish): Change<#State, #Effect> {
return when (wish) {
is #Wish.OnEmailChanged -> {
expect { state.copy(email = wish.email, emailFailed = false, isLoading = false) }
}
#Wish.OnEmailFailed -> {
expect { state.copy(emailFailed = true) }
}
is #Wish.OnNameChanged -> {
expect { state.copy(name = wish.name, nameFailed = false, isLoading = false) }
}
#Wish.OnNameFailed -> {
expect { state.copy(nameFailed = true, isLoading = false) }
}
is #Wish.OnPasswordChanged -> {
expect { state.copy(passwordFailed = false, password = wish.password, isLoading = false) }
}
#Wish.OnPasswordFailed -> {
expect { state.copy(passwordFailed = true) }
}
#Wish.On#Click -> {
expect { state.copy(isLoading = true) }
}
is #Wish.#Failure -> {
expect(
stateAction = { state.copy(isLoading = false) },
effectAction = { #Effect.Failure(wish.message) }
)
}
#Wish.#Success -> {
route { #Effect.AddPrivatePassword }
}
#Wish.TogglePasswordVisibility -> {
expect { state.copy(isPasswordVisibility = !state.isPasswordVisibility) }
}
#Wish.Back -> {
route { #Effect.Back }
}
else -> {
unexpected { state }
}
override fun reduce(state: #State, wish: #Wish): Change<#State, #Effect> {
return when (wish) {
is #Wish.OnEmailChanged -> {
expect { state.copy(email = wish.email, emailFailed = false, isLoading = false) }
}

#Wish.OnEmailFailed -> {
expect { state.copy(emailFailed = true) }
}

is #Wish.OnNameChanged -> {
expect { state.copy(name = wish.name, nameFailed = false, isLoading = false) }
}

#Wish.OnNameFailed -> {
expect { state.copy(nameFailed = true, isLoading = false) }
}

is #Wish.OnKeyPasswordChanged -> {
expect {
state.copy(
keyPassword = wish.password,
isKeyPasswordSame = false,
isLoading = false,
)
}
}

is #Wish.OnConfirmKeyPasswordChanged -> {
expect {
state.copy(
confirmKeyPassword = wish.confirmPassword,
isKeyPasswordSame = false,
isLoading = false,
)
}
}

#Wish.OnPasswordFailed -> {
expect { state.copy(passwordFailed = true) }
}

is #Wish.#Failure -> {
expect(
stateAction = { state.copy(isLoading = false) },
effectAction = { #Effect.Failure(wish.message) },
)
}

#Wish.#Success -> {
route { #Effect.AddPrivatePassword }
}

#Wish.TogglePasswordVisibility -> {
expect { state.copy(isPasswordVisibility = !state.isPasswordVisibility) }
}

#Wish.OnKeyPasswordSameFailed -> {
expect {
state.copy(
isKeyPasswordSame = true,
isLoading = false
)
}
}

#Wish.ToggleKeyPasswordVisibility -> {
expect { state.copy(isKeyPasswordVisibility = !state.isKeyPasswordVisibility) }
}

#Wish.ToggleConfirmKeyPasswordVisibility -> {
expect {
state.copy(
isConfirmKeyPasswordVisibility = !state.isConfirmKeyPasswordVisibility,
)
}
}

is #Wish.OnPasswordChanged -> {
expect {
state.copy(
password = wish.password,
passwordFailed = false,
isLoading = false,
)
}
}

#Wish.Back -> {
route { #Effect.Back }
}

is #Wish.OnLoadingChanged -> {
expect {
state.copy(
isLoading = wish.loading,
)
}
}

else -> {
unexpected { state }
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,15 @@ data class #State(
val emailFailed: Boolean = false,
val passwordFailed: Boolean = false,
val nameFailed: Boolean = false,
val keyPasswordFailed: Boolean = false,
val keyPassword: String = "",
val confirmKeyPassword: String = "",
val passwordLengthThanEight: Boolean = false,
val isLoading: Boolean = false,
val isPasswordVisibility: Boolean = false
val isPasswordVisibility: Boolean = false,
val isKeyPasswordVisibility: Boolean = false,
val isConfirmKeyPasswordVisibility: Boolean = false,
val isKeyPasswordSame: Boolean = false,
) {
companion object {
val Empty = #State()
Expand Down
Loading

0 comments on commit ebc5520

Please # to comment.