diff --git a/hiboo/application/templates/application_writefreely.html b/hiboo/application/templates/application_writefreely.html index 5b46b5970ed7662f3203cf61ff1a43d50bb7caee..29adf013576822da955e551497145d39487f6b85 100644 --- a/hiboo/application/templates/application_writefreely.html +++ b/hiboo/application/templates/application_writefreely.html @@ -14,4 +14,55 @@ inspect_endpoint = {{ url_for("sso.oidc_userinfo", service_uuid=service.uuid, auth_endpoint = {{ url_for("sso.oidc_authorize", service_uuid=service.uuid, _external=False) }} </pre> +<h3>Migrating accounts</h3> +<p>If you are running an existing WriteFreely server, you may import your existing accounts as claimable + profiles under Hiboo. +</p> +<p>Accounts are stored in the <i>users</i> table of the database. The following SQL query exports + userid, username, password hash, and user email as alternate claim to a CSV file. It dynamically converts the password + to use a proper crypt context hash identifier, so that Hiboo will recognize the hash. +</p> +<pre> + use writefreely; + select + username, password from users + into + outfile 'usersWF.csv' + fields terminated by ','; +</pre> +<p>Run the following command to import these profiles as unclaimed:</p> +<pre> + flask profile csv-unclaimed {{ service.uuid }} /var/lib/mysql/writefreely/usersWF.csv +</pre> +<p> + Click on "View profiles" on top of this page and click on "Export unclaimed profiles", save the csv file in /var/lib/mysql/writefreely/unclaimedWF.csv. + Use this script onWritefreely database: +</p> +<pre> + use writefreely; + + CREATE TABLE tmp_hiboo ( + service_client_id VARCHAR(36) NOT NULL, + profile_name VARCHAR(36) NOT NULL, + profile_uuid VARCHAR(36) NOT NULL, + PRIMARY KEY (profile_uuid) + ); + + LOAD DATA INFILE 'unclaimedWF.csv' + INTO TABLE tmp_hiboo + FIELDS TERMINATED BY ',' + ENCLOSED BY '"' + LINES TERMINATED BY '\n' + IGNORE 1 ROWS; + + INSERT INTO oauth_users (user_id, remote_user_id, provider, client_id) + SELECT wf.id, h.profile_uuid, 'generic', h.service_client_id + FROM tmp_hiboo h + left join + users wf + ON h.profile_name = wf.username + + +</pre> + {% include "application_oidc.html" %} \ No newline at end of file diff --git a/hiboo/profile/admin.py b/hiboo/profile/admin.py index 1a99cb0dd1a8e750cdec4df3238b3674b89206ad..3afc2080936112f707109ef9c687cf1d5169535a 100644 --- a/hiboo/profile/admin.py +++ b/hiboo/profile/admin.py @@ -23,6 +23,14 @@ def list_for_service(service_uuid): service=service) +@blueprint.route("/unclaimedexport/service/<service_uuid>.csv") +@security.admin_required() +def unclaimed_export_for_service(service_uuid): + service = models.Service.query.get(service_uuid) or flask.abort(404) + return flask.render_template("profile_unclaimed_export.html", profiles=service.profiles, + service=service) + + @blueprint.route("/details/<profile_uuid>") @security.admin_required() def details(profile_uuid): diff --git a/hiboo/profile/templates/profile_list.html b/hiboo/profile/templates/profile_list.html index 08b1e6f95eb9f315be662bc011bbeaa9b82cf688..11626efdd79a93c5b82e9ed242989ceec91aa5e0 100644 --- a/hiboo/profile/templates/profile_list.html +++ b/hiboo/profile/templates/profile_list.html @@ -23,6 +23,7 @@ {% endif %} <th>{% trans %}Profile username{% endtrans %}</th> <th>{% trans %}Owned by{% endtrans %}</th> + <th>{% trans %}UUID{% endtrans %}</th> <th>{% trans %}Status{% endtrans %}</th> <th>{% trans %}Created on{% endtrans %}</th> <th>{% trans %}Actions{% endtrans %}</th> @@ -40,6 +41,7 @@ <td>{{ profile.username }}</td> <td>-</td> {% endif %} + <td>{{ profile.uuid }}</td> <td><span class="badge bg-{{ status[0] }}">{{ status[1] }}</span></td> <td>{{ profile.created_at.date() }}</td> <td> @@ -64,6 +66,7 @@ {% block actions %} {% if service %} +<a href="{{ url_for(".unclaimed_export_for_service", service_uuid=service.uuid) }}" class="btn btn-success" download>{% trans %}Export unclaimed profiles{% endtrans %}</a> <a href="{{ url_for(".create_for", service_uuid=service.uuid) }}" class="btn btn-success">{% trans %}Create profile{% endtrans %}</a> {% endif %} {% endblock %} diff --git a/hiboo/profile/templates/profile_unclaimed_export.html b/hiboo/profile/templates/profile_unclaimed_export.html new file mode 100644 index 0000000000000000000000000000000000000000..b61bf6acbc2ee22dd6c535b145c1df7e5cbfe699 --- /dev/null +++ b/hiboo/profile/templates/profile_unclaimed_export.html @@ -0,0 +1,3 @@ +service_client_id,profile_name,profile_uuid +{% for profile in profiles %}{% if profile.user_uuid %}{% else %}{{service.config["client_id"]}},{{ profile.username }},{{ profile.uuid }} +{% endif %}{% endfor %} \ No newline at end of file