Skip to content

Commit e5437a8

Browse files
Fixed login Issue using mifos/password(Login credentials) (#3071)
Co-authored-by: Biplab Dutta <biplabdutta27@gmail.com>
1 parent f638e19 commit e5437a8

3 files changed

Lines changed: 30 additions & 17 deletions

File tree

feature/auth/src/commonMain/composeResources/values-en/strings.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
<string name="no_internet_connection">No Internet Connection</string>
1313
<string name="register">Register</string>
1414
<string name="login_failed">Login Failed, Please Try Again Later.</string>
15+
<string name="no_client_assigned">No Client Assigned</string>
1516
<string name="toast_welcome">Welcome %1$s</string>
1617
<string name="password">Password</string>
1718
<string name="login">Login</string>

feature/auth/src/commonMain/composeResources/values/strings.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@
7272
<string name="feature_sign_in_sign_up">Sign up!</string>
7373
<string name="feature_sign_in_username_error">Email address not found</string>
7474
<string name="feature_sign_in_password_error">Your password is not correct!</string>
75+
<string name="no_client_assigned">No clients are assigned to this account</string>
7576

7677
<string name="feature_signup_title">Sign up</string>
7778
<string name="feature_signup_sub_title">Create an account to continue!</string>

feature/auth/src/commonMain/kotlin/org/mifos/mobile/feature/auth/login/LoginViewModel.kt

Lines changed: 28 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import mifos_mobile.core.ui.generated.resources.internal_server_error
2020
import mifos_mobile.feature.auth.generated.resources.Res
2121
import mifos_mobile.feature.auth.generated.resources.feature_sign_in_password_error
2222
import mifos_mobile.feature.auth.generated.resources.feature_sign_in_username_error
23+
import mifos_mobile.feature.auth.generated.resources.no_client_assigned
2324
import org.jetbrains.compose.resources.StringResource
2425
import org.jetbrains.compose.resources.getString
2526
import org.mifos.mobile.core.common.DataState
@@ -123,24 +124,34 @@ class LoginViewModel(
123124
is DataState.Success -> {
124125
updateState { it.copy(showOverlay = false) }
125126
val user = action.loginResult.data
126-
val userData = UserData(
127-
userId = user.userId,
128-
userName = user.username.orEmpty(),
129-
clientId = if (user.clients.isNotEmpty()) {
130-
user.clients[0]
131-
} else {
132-
user.userId
133-
},
134-
isAuthenticated = user.isAuthenticated,
135-
base64EncodedAuthenticationKey = user.base64EncodedAuthenticationKey.orEmpty(),
136-
officeName = user.officeName.orEmpty(),
137-
password = state.password,
138-
)
139-
viewModelScope.launch {
140-
userPreferencesRepositoryImpl.updateUser(userData)
141-
userPreferencesRepositoryImpl.setIsAuthenticated(true)
127+
if (user.clients.isEmpty()) {
128+
val noClientsMsg = getString(Res.string.no_client_assigned)
129+
viewModelScope.launch {
130+
userPreferencesRepositoryImpl.updateUser(UserData.DEFAULT)
131+
userPreferencesRepositoryImpl.setIsAuthenticated(false)
132+
}
133+
updateState {
134+
it.copy(
135+
isError = true,
136+
dialogState = LoginState.DialogState.Error(noClientsMsg),
137+
)
138+
}
139+
} else {
140+
val userData = UserData(
141+
userId = user.userId,
142+
userName = user.username.orEmpty(),
143+
clientId = user.clients[0],
144+
isAuthenticated = user.isAuthenticated,
145+
base64EncodedAuthenticationKey = user.base64EncodedAuthenticationKey.orEmpty(),
146+
officeName = user.officeName.orEmpty(),
147+
password = state.password,
148+
)
149+
viewModelScope.launch {
150+
userPreferencesRepositoryImpl.updateUser(userData)
151+
userPreferencesRepositoryImpl.setIsAuthenticated(true)
152+
}
153+
sendEvent(LoginEvent.NavigateToPasscode)
142154
}
143-
sendEvent(LoginEvent.NavigateToPasscode)
144155
}
145156
}
146157
}

0 commit comments

Comments
 (0)