humhub / app

20 stars 8 forks source link

Opener Dialog: Hide Until Logout #5

Closed luke- closed 1 year ago

luke- commented 1 year ago

When the user goes back, the opener dialog should no longer appear. Even after reopening the app, the previous entered URL should be opened directly in the WebAppView.

If the WebView HTTP Response contains the header 'X-HumHub-Logout', the entered URL should be deleted and the Opener dialog should be displayed again. If this is not reliably possible with headers, a solution via Javascript Channel or similar would also be an option.

luke- commented 1 year ago

Open question is: What happens if the HumHub installation under the saved URL is no longer accessible and the user can not log out. how does he get back to the dialog?

luke- commented 1 year ago

@PrimozRatej I have seen that there are Javascript channels in Flutter to realise a communication with the WebApp and the Flutter App.

One goal would be to no longer display the "Opener" dialogue after a successful login. It should only appear again after a logout in the WebApp.

Would it be possible for me to use HumHub, e.g.

<script>
window.FLUTTER_CHANNEL_NAME.postMessage('humhub.login');
</script>

Or:

<script>
window.FLUTTER_CHANNEL_NAME.postMessage('humhub.logout');
</script>

The behaviour on the Flutter side should be that as soon as humhub.login is received via the channel, the current URL of the opener is permanently saved and the opener is no longer displayed even after an app restart.

The behaviour on the Flutter side should be that as soon as humhub.login is received via the channel, the current URL of the opener is "locked" and the opener is no longer displayed even after an app restart.

If the message humhub.logout is received, the URL "lock" is removed and the opener is displayed directly.

It would be nice if the URL remained preset even after a logout.

PrimozRatej commented 1 year ago

Q: When the user goes back, the opener dialog should no longer appear. Even after reopening the app, the previous entered URL should be opened directly in the WebAppView.

Q: If the WebView HTTP Response contains the header 'X-HumHub-Logout', the entered URL should be deleted and the Opener dialog should be displayed again. If this is not reliably possible with headers, a solution via Javascript Channel or similar would also be an option.

The SafeStorage feature of the app can handle redirections and logins. When a user successfully redirects or logs in, the app saves the URL to its internal storage. Every time the user opens the app, the stored URL is read. The issue is that the WebView has limited capabilities when it comes to working with headers. Even setting headers seems to be a problem.

Image

A possible workaround would be to create a wrapper that makes a request using something similar to "var html = Get(url, headers).html" and then loading the HTML string using the loadHtmlString method. However, I smell trouble here. An alternative suggestion would be to work with cookies or JavaScript channels. I have had experience working with channels in the past, and they have been effective.

Example of how we pass data from WebView to Flutter app for credit card token.

Image

Lets say if you would want to send something back to WebView you can always run .js

Image

Q: Open question is: What happens if the HumHub installation under the saved URL is no longer accessible and the user can not log out. how does he get back to the dialog? Since we are already checking the manifest.json file and only navigating to the HumHub installation if it exists, it should not be a problem. In case we receive a 404 response, we can redirect the user to an opener dialog where they can input a valid URL again.

PrimozRatej commented 1 year ago

If there is no other way than working with headers, I can check the new plugin flutter_inappwebview it seems that it has more in-depth and advanced functionalities.

luke- commented 1 year ago

@PrimozRatej Please see my reply regarding headers here: https://github.com/luke-/app/issues/17

luke- commented 1 year ago

@PrimozRatej Ok, then let's use Javascript Channels to Hide/Show the Opener Dialog.

Can you then provide me Javascript Code which I can use to hide and show the Opener dialoge. I'll then add this to your test HumHub installation for testing.

luke- commented 1 year ago

@PrimozRatej Ok, then we'll use:

After a successful login, we trigger to hide the Opener permantly:

<script>
if (window.flutterChannel) {
   window.flutterChannel.postMessage('humhub.mobile.hideOpener');
}
</script>

After a logout, we trigger this to show the Opener instantly:

<script>
if (window.flutterChannel) {
   window.flutterChannel.postMessage('humhub.mobile.showOpener');
}
</script>
PrimozRatej commented 1 year ago

When a user enters a URL, we set the HumHub prop hideOpenerto trueif the corresponding manifest exists. The parsed manifest is saved in local storage so that if the user reopens the app and the data is present, they will be redirected directly to the selected instance. If the JS channel flutterChannelwith data humhub.mobile.showOpener is detected, local storage is cleared and the user is redirected to the Opener dialog.

luke- commented 1 year ago

@PrimozRatej Thanks.

I would prefer that hideOpener is also triggered by the Javascript Channel like the showOpener. That way we can only do this after a successful login.

The check of the URL with the manifest shouldstill take place.

Thanks!

PrimozRatej commented 1 year ago

Of course, the value isHideDialog is always affected by the JS Channel, image

So if I trigger the msg. 'humhub.mobile.hideOpener' the dialog will not be displayed when the user goes back. Only in the case if the installation does not exist anymore or the user has cleared the local storage where the data for an instance was saved. (clear cache).

luke- commented 1 year ago

@PrimozRatej To prevent the user from having to clear the LocalCache manually if the installation has been deleted or moved, we can implement the following:

Every time the app is started, the "manifest.json" is read first and the validity of the installation is checked. If this is not the case, the opener is displayed. (In other words, HideOpener is reset). However, it would be good here if the last URL is still in the field.

PrimozRatej commented 1 year ago

It works exactly as you described. The Redirectorclass implements the redirect functionality. The method ref.read(humHubProvider).getInstance() retrieves the previously executed instance of HumHub. This instance contains an action method to verify the installation's validity. Regarding the "the URL is still in the field", I will create an issue for that feature.

luke- commented 1 year ago

Okay, thanks. That sounds good. Then I'll close the issue here.

luke- commented 1 year ago

@PrimozRatej FYI: On sometestproject12345 now automatically on Login hideOpener and on Logout showOpener is triggered. It works quite well!