diff options
author | Frederick Muriuki Muriithi | 2023-03-14 14:06:45 +0300 |
---|---|---|
committer | Frederick Muriuki Muriithi | 2023-03-14 14:12:00 +0300 |
commit | 4428f752866014c7aaeb55236f177adf00ebe572 (patch) | |
tree | b783c09ce8654058574b57152c61c08a6599bc1d | |
parent | 2e4ac35697bf16cd53ba549268bebb730bbfd6e9 (diff) | |
download | genenetwork2-oauth2-migrate-user-details-and-data.tar.gz |
oauth2: Migrate user details and dataoauth2-migrate-user-details-and-data
Migrate the user details when the user successfully logs in using the
old system. This helps "copy" the user details over to the new auth
database.
Once the user details have been "copied" over from the older auth
system (stored in Redis), the resources data attached to each user can
then be migrated over for the user once they log in to the newer auth
system.
-rw-r--r-- | wqflask/wqflask/oauth2/users.py | 26 | ||||
-rw-r--r-- | wqflask/wqflask/user_login.py | 31 |
2 files changed, 55 insertions, 2 deletions
diff --git a/wqflask/wqflask/oauth2/users.py b/wqflask/wqflask/oauth2/users.py index d1bf0e5b..510b629f 100644 --- a/wqflask/wqflask/oauth2/users.py +++ b/wqflask/wqflask/oauth2/users.py @@ -26,6 +26,32 @@ def user_profile(): for privilege in role["privileges"]), **kwargs) + def __migrate_user_data_error__( + error, user_details, roles, group_join_request): + flash(f"Data Migration: {error['error']}: {error['error_description']}", + "alert-warning") + return __render__( + user_details, roles, group_join_request=group_join_request) + + def __migrate_user_data_success__( + msg, user_details, roles, group_join_request): + flash(f"Data Migration: {msg['description']}", + "alert-success") + return __render__( + user_details, roles, group_join_request=group_join_request) + + def __migrate_user_data__(user_details, roles, group_join_request): + return oauth2_post( + f"oauth2/data/user/{user_details['user_id']}/migrate", + data={ + "user_id": user_details["user_id"] + }).either( + lambda err: __migrate_user_data_error__( + process_error(err), user_details, roles, + group_join_request), + lambda mig_suc_msg: __migrate_user_data_success__( + mig_suc_msg, user_details, roles, group_join_request)) + def __roles_success__(roles): if bool(usr_dets.get("group")): return __render__(usr_dets, roles) diff --git a/wqflask/wqflask/user_login.py b/wqflask/wqflask/user_login.py index ae61edb0..03f968d9 100644 --- a/wqflask/wqflask/user_login.py +++ b/wqflask/wqflask/user_login.py @@ -10,7 +10,7 @@ import requests import simplejson as json from flask import (Flask, g, render_template, url_for, request, make_response, - redirect, flash, abort) + redirect, flash, abort, current_app as app) from wqflask import app from wqflask import pbkdf2 @@ -236,7 +236,34 @@ def login(): url_for('index_page', import_collections=import_col, anon_id=anon_id))) response.set_cookie( UserSession.user_cookie_name, session_id_signed, max_age=None) - return response + ## BEGIN: Data migration from redis to auth's SQLite DB + ## ===================================== + from wqflask.wqflask.oauth2.client import oauth2_get, oauth2_post + from wqflask.wqflask.oauth2.request_utils import process_error + def __user_dets_migrate_error(error): + flash(f"Data Migration: {error['error']}: " + f"{error['error_description']}", + "alert-info") + return response + + def __user_dets_migrate_success(msg): + flash(f"Data Migration: {msg['description']}", + "alert-success") + return response + + return oauth2_post("oauth2/data/user/migrate", data={ + "email": , + "full_name": , + "password": submitted_password, + "confirm_password": submitted_password, + "client_id": app.config["OAUTH2_CLIENT_ID"], + "client_secret": app.config["OAUTH2_CLIENT_SECRET"] + }).either( + lambda err: __user_dets_migrate_error__(process_error(err)), + __user_dets_migrate_success) + # return response + ## ===================================== + ## END: Data migration from redis to auth's SQLite DB else: email_ob = send_verification_email( user_details, template_name="email/user_verification.txt") |