-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #93 from Tiqr/Edured-100_show_error_message_on_sec…
…urity Edured 100 show error message on security Added missing error message handling for security screen. Not automatically triggering the authentication, but informing the user they must grant access.
- Loading branch information
Showing
8 changed files
with
139 additions
and
102 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 5 additions & 1 deletion
6
app/src/main/kotlin/nl/eduid/screens/security/SecurityScreenData.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,11 @@ | ||
package nl.eduid.screens.security | ||
|
||
import nl.eduid.ErrorData | ||
|
||
data class SecurityScreenData( | ||
val twoFactorEnabled: Boolean = false, | ||
val isLoading: Boolean = false, | ||
val errorData: ErrorData? = null, | ||
val twoFAProvider: String? = null, | ||
val email: String = "", | ||
val hasPassword: Boolean = false, | ||
) |
66 changes: 48 additions & 18 deletions
66
app/src/main/kotlin/nl/eduid/screens/security/SecurityViewModel.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,66 @@ | ||
package nl.eduid.screens.security | ||
|
||
import androidx.lifecycle.MutableLiveData | ||
import androidx.compose.runtime.getValue | ||
import androidx.compose.runtime.mutableStateOf | ||
import androidx.compose.runtime.setValue | ||
import androidx.lifecycle.ViewModel | ||
import androidx.lifecycle.viewModelScope | ||
import dagger.hilt.android.lifecycle.HiltViewModel | ||
import kotlinx.coroutines.flow.firstOrNull | ||
import kotlinx.coroutines.launch | ||
import nl.eduid.di.model.UserDetails | ||
import nl.eduid.screens.personalinfo.PersonalInfoRepository | ||
import nl.eduid.ErrorData | ||
import nl.eduid.R | ||
import nl.eduid.di.assist.DataAssistant | ||
import nl.eduid.di.model.UnauthorizedException | ||
import org.tiqr.data.repository.IdentityRepository | ||
import javax.inject.Inject | ||
|
||
@HiltViewModel | ||
class SecurityViewModel @Inject constructor(private val repository: PersonalInfoRepository) : | ||
ViewModel() { | ||
val securityInfo = MutableLiveData<SecurityScreenData>() | ||
class SecurityViewModel @Inject constructor( | ||
private val assistant: DataAssistant, | ||
private val identity: IdentityRepository, | ||
) : ViewModel() { | ||
var uiState: SecurityScreenData by mutableStateOf(SecurityScreenData()) | ||
private set | ||
|
||
init { | ||
viewModelScope.launch { | ||
val userDetails = repository.getUserDetails() | ||
if (userDetails != null) { | ||
val uiData = convertToUiData(userDetails) | ||
securityInfo.postValue(uiData) | ||
uiState = uiState.copy(isLoading = true, errorData = null) | ||
try { | ||
val userDetails = assistant.getErringUserDetails() | ||
uiState = if (userDetails != null) { | ||
val identity = identity.identity(userDetails.id).firstOrNull() | ||
val provider = if (identity != null) { | ||
identity.identityProvider.displayName | ||
} else { | ||
null | ||
} | ||
uiState.copy( | ||
isLoading = false, errorData = null, email = userDetails.email, | ||
twoFAProvider = provider, | ||
hasPassword = userDetails.hasPasswordSet(), | ||
) | ||
} else { | ||
uiState.copy( | ||
isLoading = false, errorData = ErrorData( | ||
titleId = R.string.err_title_load_fail, | ||
messageId = R.string.err_msg_data_history_fail | ||
) | ||
) | ||
} | ||
|
||
} catch (e: UnauthorizedException) { | ||
uiState = uiState.copy( | ||
isLoading = false, errorData = ErrorData( | ||
titleId = R.string.err_title_load_fail, | ||
messageId = R.string.err_msg_unauthorized_request_fail | ||
) | ||
) | ||
} | ||
} | ||
} | ||
|
||
private fun convertToUiData(userDetails: UserDetails): SecurityScreenData { | ||
return userDetails.eduIdPerServiceProvider.values.map { | ||
SecurityScreenData( | ||
twoFactorEnabled = false, | ||
email = userDetails.email, | ||
hasPassword = userDetails.hasPasswordSet(), | ||
) | ||
}.first() | ||
fun dismissError() { | ||
uiState = uiState.copy(errorData = null) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.