-
Notifications
You must be signed in to change notification settings - Fork 743
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[SDK] Allow passwords to be set at the point of reset confirmation #6171
Changes from all commits
e3d46cf
35163f7
cc8f17b
93a247e
32389a9
fa5b7c6
edfabb0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Allows new passwords to be passed at the point of confirmation when resetting a password |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -128,7 +128,7 @@ class OnboardingViewModel @AssistedInject constructor( | |
val isRegistrationStarted: Boolean | ||
get() = authenticationService.isRegistrationStarted() | ||
|
||
private val loginWizard: LoginWizard? | ||
private val loginWizard: LoginWizard | ||
get() = authenticationService.getLoginWizard() | ||
|
||
private var loginConfig: LoginConfig? = null | ||
|
@@ -246,21 +246,15 @@ class OnboardingViewModel @AssistedInject constructor( | |
|
||
private fun handleLoginWithToken(action: OnboardingAction.LoginWithToken) { | ||
val safeLoginWizard = loginWizard | ||
setState { copy(isLoading = true) } | ||
|
||
if (safeLoginWizard == null) { | ||
setState { copy(isLoading = false) } | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. by making the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I have noticed this warning. I think this is relatively new, probably since a Kotlin version upgrade. I am also wondering why the compiler is not failing, since warnings are errors on our project. So looks more like a IDE inspection warning. |
||
_viewEvents.post(OnboardingViewEvents.Failure(Throwable("Bad configuration"))) | ||
} else { | ||
setState { copy(isLoading = true) } | ||
|
||
currentJob = viewModelScope.launch { | ||
try { | ||
val result = safeLoginWizard.loginWithToken(action.loginToken) | ||
onSessionCreated(result, authenticationDescription = AuthenticationDescription.Login) | ||
} catch (failure: Throwable) { | ||
setState { copy(isLoading = false) } | ||
_viewEvents.post(OnboardingViewEvents.Failure(failure)) | ||
} | ||
currentJob = viewModelScope.launch { | ||
try { | ||
val result = safeLoginWizard.loginWithToken(action.loginToken) | ||
onSessionCreated(result, authenticationDescription = AuthenticationDescription.Login) | ||
} catch (failure: Throwable) { | ||
setState { copy(isLoading = false) } | ||
_viewEvents.post(OnboardingViewEvents.Failure(failure)) | ||
} | ||
} | ||
} | ||
|
@@ -377,7 +371,7 @@ class OnboardingViewModel @AssistedInject constructor( | |
setState { | ||
copy( | ||
isLoading = false, | ||
resetPasswordEmail = null | ||
resetState = ResetState() | ||
) | ||
} | ||
} | ||
|
@@ -447,59 +441,52 @@ class OnboardingViewModel @AssistedInject constructor( | |
|
||
private fun handleResetPassword(action: OnboardingAction.ResetPassword) { | ||
val safeLoginWizard = loginWizard | ||
|
||
if (safeLoginWizard == null) { | ||
setState { copy(isLoading = false) } | ||
_viewEvents.post(OnboardingViewEvents.Failure(Throwable("Bad configuration"))) | ||
} else { | ||
setState { copy(isLoading = true) } | ||
|
||
currentJob = viewModelScope.launch { | ||
try { | ||
safeLoginWizard.resetPassword(action.email, action.newPassword) | ||
} catch (failure: Throwable) { | ||
setState { copy(isLoading = false) } | ||
_viewEvents.post(OnboardingViewEvents.Failure(failure)) | ||
return@launch | ||
} | ||
|
||
setState { | ||
copy( | ||
isLoading = false, | ||
resetPasswordEmail = action.email | ||
) | ||
} | ||
|
||
_viewEvents.post(OnboardingViewEvents.OnResetPasswordSendThreePidDone) | ||
} | ||
setState { copy(isLoading = true) } | ||
currentJob = viewModelScope.launch { | ||
runCatching { safeLoginWizard.resetPassword(action.email) }.fold( | ||
onSuccess = { | ||
setState { | ||
copy( | ||
isLoading = false, | ||
resetState = ResetState(email = action.email, newPassword = action.newPassword) | ||
) | ||
} | ||
_viewEvents.post(OnboardingViewEvents.OnResetPasswordSendThreePidDone) | ||
}, | ||
onFailure = { | ||
setState { copy(isLoading = false) } | ||
_viewEvents.post(OnboardingViewEvents.Failure(it)) | ||
} | ||
) | ||
} | ||
} | ||
|
||
private fun handleResetPasswordMailConfirmed() { | ||
val safeLoginWizard = loginWizard | ||
|
||
if (safeLoginWizard == null) { | ||
setState { copy(isLoading = false) } | ||
_viewEvents.post(OnboardingViewEvents.Failure(Throwable("Bad configuration"))) | ||
} else { | ||
setState { copy(isLoading = false) } | ||
|
||
currentJob = viewModelScope.launch { | ||
try { | ||
safeLoginWizard.resetPasswordMailConfirmed() | ||
} catch (failure: Throwable) { | ||
setState { copy(isLoading = true) } | ||
currentJob = viewModelScope.launch { | ||
val resetState = awaitState().resetState | ||
when (val newPassword = resetState.newPassword) { | ||
null -> { | ||
setState { copy(isLoading = false) } | ||
_viewEvents.post(OnboardingViewEvents.Failure(failure)) | ||
return@launch | ||
_viewEvents.post(OnboardingViewEvents.Failure(IllegalStateException("Developer error - No new password has been set"))) | ||
} | ||
setState { | ||
copy( | ||
isLoading = false, | ||
resetPasswordEmail = null | ||
else -> { | ||
runCatching { loginWizard.resetPasswordMailConfirmed(newPassword) }.fold( | ||
onSuccess = { | ||
setState { | ||
copy( | ||
isLoading = false, | ||
resetState = ResetState() | ||
) | ||
} | ||
_viewEvents.post(OnboardingViewEvents.OnResetPasswordMailConfirmationSuccess) | ||
}, | ||
onFailure = { | ||
setState { copy(isLoading = false) } | ||
_viewEvents.post(OnboardingViewEvents.Failure(it)) | ||
} | ||
) | ||
} | ||
|
||
_viewEvents.post(OnboardingViewEvents.OnResetPasswordMailConfirmationSuccess) | ||
} | ||
} | ||
} | ||
|
@@ -519,25 +506,19 @@ class OnboardingViewModel @AssistedInject constructor( | |
|
||
private fun handleLogin(action: AuthenticateAction.Login) { | ||
val safeLoginWizard = loginWizard | ||
|
||
if (safeLoginWizard == null) { | ||
setState { copy(isLoading = false) } | ||
_viewEvents.post(OnboardingViewEvents.Failure(Throwable("Bad configuration"))) | ||
} else { | ||
setState { copy(isLoading = true) } | ||
currentJob = viewModelScope.launch { | ||
try { | ||
val result = safeLoginWizard.login( | ||
action.username, | ||
action.password, | ||
action.initialDeviceName | ||
) | ||
reAuthHelper.data = action.password | ||
onSessionCreated(result, authenticationDescription = AuthenticationDescription.Login) | ||
} catch (failure: Throwable) { | ||
setState { copy(isLoading = false) } | ||
_viewEvents.post(OnboardingViewEvents.Failure(failure)) | ||
} | ||
setState { copy(isLoading = true) } | ||
currentJob = viewModelScope.launch { | ||
try { | ||
val result = safeLoginWizard.login( | ||
action.username, | ||
action.password, | ||
action.initialDeviceName | ||
) | ||
reAuthHelper.data = action.password | ||
onSessionCreated(result, authenticationDescription = AuthenticationDescription.Login) | ||
} catch (failure: Throwable) { | ||
setState { copy(isLoading = false) } | ||
_viewEvents.post(OnboardingViewEvents.Failure(failure)) | ||
} | ||
} | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is it possible to avoid the not-null assertion operator ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it's possible (we're avoiding it in the OnboardingViewModel) but I've taken a shortcut here in the LoginViewModel2 as this entire package will be removed once the FTUE is finished
for context,
Login2
is the proof of concept which has lead to the FTUE projectI'd prefer to avoid making tooo many changes to this package, but would be happy to make the change if you feel it's worth doing 👍