diff --git a/snikket_web/invite.py b/snikket_web/invite.py index 742509e..226b4b7 100644 --- a/snikket_web/invite.py +++ b/snikket_web/invite.py @@ -26,6 +26,8 @@ bp = Blueprint("invite", __name__) INVITE_SESSION_JID = "invite-session-jid" +EIMPORTTOOBIG = _l("The account data you tried to import is too large to" + "upload. Please contact your Snikket operator.") # https://play.google.com/store/apps/details?id=org.snikket.android&referrer={uri|urlescape}&pcampaignid=pcampaignidMKT-Other-global-all-co-prtnr-py-PartBadge-Mar2515-1 @@ -163,6 +165,7 @@ async def register(id_: str) -> typing.Union[str, quart.Response]: raise else: http_session[INVITE_SESSION_JID] = jid + await client.login(jid, form.password.data) return redirect(url_for(".success")) return await render_template( @@ -232,11 +235,36 @@ async def reset(id_: str) -> typing.Union[str, quart.Response]: ) +class DataImportForm(BaseForm): + account_data_file = wtforms.FileField( + _l("Account data file") + ) + + action_import = wtforms.SubmitField( + _l("Import data") + ) + + @bp.route("/success", methods=["GET", "POST"]) +@client.require_session() async def success() -> str: + form = DataImportForm() + if form.validate_on_submit(): + client.import_account_data() + # Re-render success page, this time with no import option + return await render_template( + "invite_success.html", + jid=http_session.get(INVITE_SESSION_JID, ""), + migration_success=True, + ) return await render_template( "invite_success.html", jid=http_session.get(INVITE_SESSION_JID, ""), + migration_success=False, + form=form, + max_import_size=5*1024*1024, # 5MB + import_too_big_warning_header=_l("Error"), + import_too_big_warning=EIMPORTTOOBIG, ) diff --git a/snikket_web/static/img/icons.svg b/snikket_web/static/img/icons.svg index 4b041a6..17ecc6d 100644 --- a/snikket_web/static/img/icons.svg +++ b/snikket_web/static/img/icons.svg @@ -98,6 +98,11 @@ licensed under the terms of the Apache 2.0 License --> + + + + + diff --git a/snikket_web/templates/invite_success.html b/snikket_web/templates/invite_success.html index 00cd482..e169633 100644 --- a/snikket_web/templates/invite_success.html +++ b/snikket_web/templates/invite_success.html @@ -1,6 +1,6 @@ {% extends "invite.html" %} {% set body_id = "invite" %} -{% from "library.j2" import form_button, clipboard_button %} +{% from "library.j2" import form_button, clipboard_button, render_errors %} {% block head_lead %} {% trans site_name=config["SITE_NAME"] %}Successfully registered on {{ site_name }} | Snikket{% endtrans %} {%- include "copy-snippet.html" -%} @@ -16,5 +16,46 @@ {%- endcall -%}

{% trans %}You can now set up your legacy XMPP client with the above address and the password you chose during registration.{% endtrans %}

{% trans login_url=url_for('main.login') %}You can now safely close this page, or log in to the web portal to manage your account.{% endtrans %}

+ + {% if migration_success %} +

{% trans %}Import successful{% endtrans %}

+

{% trans %}Congratulations! Your account data has been successfully imported.{% endtrans %}

+ {% endif %} + + {% if form %} +

{% trans %}Moving to Snikket?{% endtrans %}

+

{% trans %}If you are moving from a different Snikket instance or another XMPP-compatible service, you may optionally import the data (contacts, profile information, etc.) from your previous account. When you have exported the data from your previous account, upload it using the form below.{% endtrans %}

+ +
+

{% trans %}Upload account data{% endtrans %}

+ {{ form.csrf_token }} + {% call render_errors(form) %}{% endcall %} +
+ {{ form.account_data_file.label }} + {{ form.account_data_file(accept="application/xml", + data_maxsize=max_import_size, + data_warning_header=import_too_big_warning_header, + data_maxsize_warning=import_too_big_warning) }} +
+
+ {%- call form_button("upload", form.action_import, class="secondary") %}{% endcall -%} +
+ +
+ {% endif %} {% endblock %} diff --git a/snikket_web/user.py b/snikket_web/user.py index eb9e278..c8c1ed7 100644 --- a/snikket_web/user.py +++ b/snikket_web/user.py @@ -77,6 +77,16 @@ class ProfileForm(BaseForm): ) +class ImportAccountDataForm(BaseForm): + account_data_file = wtforms.FileField( + _l("Account data") + ) + + action_upload = wtforms.SubmitField( + _l("Upload"), + ) + + @bp.route("/") @client.require_session() async def index() -> str: diff --git a/tools/icons.list b/tools/icons.list index b68f97d..050a9e5 100644 --- a/tools/icons.list +++ b/tools/icons.list @@ -17,6 +17,7 @@ content/content_copy:copy content/link_off:remove_link content/send:send file/file_download:download +file/file_upload:upload file/folder:folder navigation/arrow_back:back navigation/arrow_forward:forward