Commit e4b1d433 authored by Noe Nieto's avatar Noe Nieto 💬
Browse files

Use JWT to validate username and password; do not create a new woocommerce...

Use JWT to validate username and password; do not create a new woocommerce user when creating the ldap user; use settings.WOO_URL; ref liberty/host/middleware#88;
parent b88fdb56
......@@ -23,7 +23,7 @@ def get_jwt_token(user, password):
def get_wc_userid(jwt_token):
with requests.Session() as s:
r = s.get(
f'{settings.WOO_URL}/wp-json/wp/v2/users/me?_fields[]=id',
url=f'{settings.WOO_URL}/wp-json/wp/v2/users/me?_fields[]=id',
headers={'Authorization': f'Bearer {jwt_token}'}
)
if r.status_code == 200:
......@@ -32,22 +32,23 @@ def get_wc_userid(jwt_token):
return None
def update_wc_username(wc_userid, username, email):
def update_wc_username(jwt_token, ldh_username, recovery_email):
"""
Returns True for success, False for failure
Note: WP can't update username and email using wp-json/wp/v2/users/me, so
we need to use
Returns True for success, False for failure.
"""
wc_api = get_woo_connection()
wc_api.version = 'wp/v2'
res = wc_api.post(
endpoint=f'users/{wc_userid}',
data={
'ldh_username': username,
'name': username,
'nickname': username,
'slug': username
with requests.Session() as s:
import pdb; pdb.set_trace()
payload = {
'ldh_username': f'{ldh_username}@{settings.SITE_DOMAIN}',
'nickname': ldh_username,
'slug': ldh_username,
'email': recovery_email,
}
)
r = s.post(
url=f'{settings.WOO_URL}/wp-json/wp/v2/users/me',
data=payload,
headers={'Authorization': f'Bearer {jwt_token}'}
)
return r.status_code == 200
return False
return res
......@@ -23,9 +23,8 @@ class WC_UpgradeView(FormView):
user.save()
update_wc_username(
wc_userid=form.wc_user_id,
username=form.cleaned_data['l1_username'],
email=form.cleaned_data['wc_email'],
jwt_token=form.wc_jwt_token
jwt_token=form.wc_jwt_token,
ldh_username=form.cleaned_data['l1_username'],
recovery_email=form.cleaned_data['wc_email'],
)
return redirect(self.success_url)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment