Skip to content

Commit

Permalink
The e-mail address of the unauthorised account is now displayed on th…
Browse files Browse the repository at this point in the history
…e error screen
  • Loading branch information
s1g53gv committed Nov 28, 2024
1 parent 2958960 commit 1e6470b
Show file tree
Hide file tree
Showing 9 changed files with 29 additions and 19 deletions.
2 changes: 1 addition & 1 deletion app/src/main/java/it/bz/noi/community/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ class MainActivity : AppCompatActivity() {
}
is AuthStateStatus.Error,
AuthStateStatus.Unauthorized.UserAuthRequired,
AuthStateStatus.Unauthorized.NotValidRole -> {
is AuthStateStatus.Unauthorized.NotValidRole -> {
goToOnboardingActivity()
}
else -> {
Expand Down
20 changes: 10 additions & 10 deletions app/src/main/java/it/bz/noi/community/oauth/AuthManager.kt
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ sealed class AuthStateStatus {
sealed class Unauthorized : AuthStateStatus() {
object UserAuthRequired : Unauthorized()
object PendingToken : Unauthorized()
object NotValidRole : Unauthorized()
data class NotValidRole(val emailAddress: String) : Unauthorized()
}

data class Authorized(val state: AuthState) : AuthStateStatus()
Expand All @@ -72,7 +72,7 @@ object AuthManager {
/**
* Check if the user has a valid email, that is if it is allowed to use the app.
*/
private suspend fun AuthState.isEmailValid(): Boolean {
private suspend fun AuthState.isEmailValid(): Pair<String,Boolean> {

fun String.isDimensionEmail() = endsWith("@dimension.it")

Expand All @@ -81,23 +81,23 @@ object AuthManager {
fun String.isWhitelisted() = isDimensionEmail() || isGooglePlayReviewEmail()

return try {
val token = obtainFreshToken() ?: return false
val token = obtainFreshToken() ?: return ("" to false)
val mail: String = getUserInfo(token, obtainAuthServiceConfig()).let { res ->
if (res.status == Status.SUCCESS) {
res.data
} else {
null
}
}?.email ?: return false
}?.email ?: return "" to false

if (mail.isWhitelisted()) {
return true
return mail to true
}

val contacts = RetrofitBuilder.communityApiService.getContacts(token.bearer()).contacts
contacts.any { it.matches(mail) }
mail to contacts.any { it.matches(mail) }
} catch (ex: Exception) {
false
"" to false
}
}

Expand All @@ -119,11 +119,11 @@ object AuthManager {
)
)

!validRole -> AuthStateStatus.Unauthorized.NotValidRole
true || !validRole -> AuthStateStatus.Unauthorized.NotValidRole("")
authState.isAuthorized -> {
authState.isEmailValid().let { isValid ->
authState.isEmailValid().let { (mail, isValid) ->
if (!isValid) {
AuthStateStatus.Unauthorized.NotValidRole
AuthStateStatus.Unauthorized.NotValidRole(mail)
} else {
AuthStateStatus.Authorized(authState)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import androidx.lifecycle.Lifecycle
import androidx.lifecycle.lifecycleScope
import androidx.lifecycle.repeatOnLifecycle
import androidx.navigation.fragment.findNavController
import androidx.navigation.fragment.navArgs
import com.google.firebase.crashlytics.FirebaseCrashlytics
import it.bz.noi.community.R
import it.bz.noi.community.databinding.FragmentAuthorizationErrorBinding
Expand All @@ -35,6 +36,8 @@ class AuthorizationErrorFragment : BaseOnboardingFragment() {
private var _binding: FragmentAuthorizationErrorBinding? = null
private val binding get() = _binding!!

private val args by navArgs<AuthorizationErrorFragmentArgs>()

override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
Expand Down Expand Up @@ -70,7 +73,10 @@ class AuthorizationErrorFragment : BaseOnboardingFragment() {
binding.message.apply {
movementMethod = LinkMovementMethod.getInstance()
text = buildSpannedString {
append(getString(R.string.outsider_user_body))
append(
getString(R.string.outsider_user_body, args.emailAddress)
.replace("() ", "") // Remove blank email address.
)
val jobsSnippet = getString(R.string.outsider_user_body_link_1_part)
addClickableSpan(jobsSnippet) {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,9 @@ class OnboardingFragment : BaseOnboardingFragment() {
showLoginInterface(false)
onboardingActivity?.goToMainActivity()
}
AuthStateStatus.Unauthorized.NotValidRole -> {
is AuthStateStatus.Unauthorized.NotValidRole -> {
showLoginInterface(false)
findNavController().navigate(OnboardingFragmentDirections.loginToError())
findNavController().navigate(OnboardingFragmentDirections.loginToError(status.emailAddress))
}
else -> {
showLoginInterface(true)
Expand Down
6 changes: 5 additions & 1 deletion app/src/main/res/navigation/onboarding.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,11 @@ SPDX-License-Identifier: CC0-1.0
<fragment
android:id="@+id/error"
android:name="it.bz.noi.community.ui.onboarding.AuthorizationErrorFragment"
android:label="@string/warning_title" />
android:label="@string/warning_title" >
<argument
android:name="email_address"
app:argType="string" />
</fragment>
<action
android:id="@+id/action_global_to_login"
app:popUpTo="@id/login" />
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/values-de/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ Please do not edit this file by hand, use the export function from Google Sheet.
<string name="app_privacy_policy_page_title" comment="Title of privacy policy page">Datenschutzrichtlinie</string>
<string name="warning_title" comment="Warning title">Oh no!</string>
<string name="outsider_user_title" comment="Title of user outsider of NOI community">Hoppla, das hat leider nicht geklappt!</string>
<string name="outsider_user_body" comment="Body of user outsider of NOI community">Die angegebene E-Mail-Adresse scheint in unserer Datenbank nicht auf. \n \nDiese App ist den Mitgliedern der NOI-Community vorbehalten. Wenn du Teil davon bist, prüfe bitte die angegebene E-Mail-Adresse und versuch es noch einmal. Klappt es dann immer noch nicht, schreib uns bitte eine E-Mail an community@noi.bz.it. \n \nDu möchtest auch zur NOI-Community gehören? Hier geht’s zu unseren Job-Angeboten.</string>
<string name="outsider_user_body" comment="Body of user outsider of NOI community">Die angegebene E-Mail-Adresse (%1$s) scheint in unserer Datenbank nicht auf. \n \nDiese App ist den Mitgliedern der NOI-Community vorbehalten. Wenn du Teil davon bist, prüfe bitte die angegebene E-Mail-Adresse und versuch es noch einmal. Klappt es dann immer noch nicht, schreib uns bitte eine E-Mail an community@noi.bz.it. \n \nDu möchtest auch zur NOI-Community gehören? Hier geht’s zu unseren Job-Angeboten.</string>
<string name="outsider_user_body_link_1_part" comment="Text to match for adding the first link inside outsider_user_body ">Job-Angeboten</string>
<string name="come_on_board_onboarding_page_title" comment="Title of come on board onboarding page">Hallo!</string>
<string name="come_on_board_onboarding_title" comment="Title of come on board onboarding">Deine Anmeldung war erfolgreich</string>
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/values-en/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ Please do not edit this file by hand, use the export function from Google Sheet.
<string name="app_privacy_policy_page_title" comment="Title of privacy policy page">Privacy policy</string>
<string name="warning_title" comment="Warning title">Oh no!</string>
<string name="outsider_user_title" comment="Title of user outsider of NOI community">Oops, that didn\'t work!</string>
<string name="outsider_user_body" comment="Body of user outsider of NOI community">The e-mail address you provided does not exist in our database. \n \nThis app is reserved for members of the NOI-Community. If you are one of them, please check the e-mail address you entered and try again. It it still doesn’t work, please email us at community@noi.bz.it. \n \nWant to join the NOI-Community? Click here for our job offers!</string>
<string name="outsider_user_body" comment="Body of user outsider of NOI community">The e-mail address you provided (%1$s) does not exist in our database. \n \nThis app is reserved for members of the NOI-Community. If you are one of them, please check the e-mail address you entered and try again. It it still doesn’t work, please email us at community@noi.bz.it. \n \nWant to join the NOI-Community? Click here for our job offers!</string>
<string name="outsider_user_body_link_1_part" comment="Text to match for adding the first link inside outsider_user_body ">here</string>
<string name="come_on_board_onboarding_page_title" comment="Title of come on board onboarding page">Hello!</string>
<string name="come_on_board_onboarding_title" comment="Title of come on board onboarding">Your registration has been successful</string>
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/values-it/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ Please do not edit this file by hand, use the export function from Google Sheet.
<string name="app_privacy_policy_page_title" comment="Title of privacy policy page">Informativa sulla privacy</string>
<string name="warning_title" comment="Warning title">Oh no!</string>
<string name="outsider_user_title" comment="Title of user outsider of NOI community">Ops, qualcosa è andato storto!</string>
<string name="outsider_user_body" comment="Body of user outsider of NOI community">L\'indirizzo e-mail inserito non è presente nel nostro database. \n \nQuesta app è riservata ai membri della NOI-Community. Se ne fai parte, controlla l\'indirizzo e-mail inserito e riprova. Se il problema persiste, invia un\'e-mail a community@noi.bz.it. \n \nVorresti entrare a far parte della NOI-Community? Clicca qui per le nostre offerte di lavoro.</string>
<string name="outsider_user_body" comment="Body of user outsider of NOI community">L\'indirizzo e-mail inserito (%1$s) non è presente nel nostro database. \n \nQuesta app è riservata ai membri della NOI-Community. Se ne fai parte, controlla l\'indirizzo e-mail inserito e riprova. Se il problema persiste, invia un\'e-mail a community@noi.bz.it. \n \nVorresti entrare a far parte della NOI-Community? Clicca qui per le nostre offerte di lavoro.</string>
<string name="outsider_user_body_link_1_part" comment="Text to match for adding the first link inside outsider_user_body ">offerte di lavoro</string>
<string name="come_on_board_onboarding_page_title" comment="Title of come on board onboarding page">Ciao!</string>
<string name="come_on_board_onboarding_title" comment="Title of come on board onboarding">La tua registrazione è andata a buon fine</string>
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ Please do not edit this file by hand, use the export function from Google Sheet.
<string name="app_privacy_policy_page_title" comment="Title of privacy policy page">Privacy policy</string>
<string name="warning_title" comment="Warning title">Oh no!</string>
<string name="outsider_user_title" comment="Title of user outsider of NOI community">Oops, that didn\'t work!</string>
<string name="outsider_user_body" comment="Body of user outsider of NOI community">The e-mail address you provided does not exist in our database. \n \nThis app is reserved for members of the NOI-Community. If you are one of them, please check the e-mail address you entered and try again. It it still doesn’t work, please email us at community@noi.bz.it. \n \nWant to join the NOI-Community? Click here for our job offers!</string>
<string name="outsider_user_body" comment="Body of user outsider of NOI community">The e-mail address you provided (%1$s) does not exist in our database. \n \nThis app is reserved for members of the NOI-Community. If you are one of them, please check the e-mail address you entered and try again. It it still doesn’t work, please email us at community@noi.bz.it. \n \nWant to join the NOI-Community? Click here for our job offers!</string>
<string name="outsider_user_body_link_1_part" comment="Text to match for adding the first link inside outsider_user_body ">here</string>
<string name="come_on_board_onboarding_page_title" comment="Title of come on board onboarding page">Hello!</string>
<string name="come_on_board_onboarding_title" comment="Title of come on board onboarding">Your registration has been successful</string>
Expand Down

0 comments on commit 1e6470b

Please sign in to comment.