small progress on nk link
This commit is contained in:
@@ -266,7 +266,7 @@ def imports_get_token(
|
|||||||
except (ValueError,TypeError):
|
except (ValueError,TypeError):
|
||||||
expires_in = 0
|
expires_in = 0
|
||||||
else:
|
else:
|
||||||
return [0,0,0]
|
return [0,response.text,0]
|
||||||
|
|
||||||
|
|
||||||
return [thetoken,expires_in,refresh_token]
|
return [thetoken,expires_in,refresh_token]
|
||||||
|
|||||||
@@ -3187,6 +3187,7 @@ class Workout(models.Model):
|
|||||||
uploadedtorunkeeper = models.BigIntegerField(default=0)
|
uploadedtorunkeeper = models.BigIntegerField(default=0)
|
||||||
uploadedtogarmin = models.BigIntegerField(default=0)
|
uploadedtogarmin = models.BigIntegerField(default=0)
|
||||||
uploadedtorp3 = models.BigIntegerField(default=0)
|
uploadedtorp3 = models.BigIntegerField(default=0)
|
||||||
|
uploadedtonk = models.BigIntegerField(default=0)
|
||||||
forceunit = models.CharField(default='lbs',
|
forceunit = models.CharField(default='lbs',
|
||||||
choices = (
|
choices = (
|
||||||
('lbs','lbs'),
|
('lbs','lbs'),
|
||||||
|
|||||||
@@ -12,6 +12,8 @@ import requests
|
|||||||
#https://oauth-stage.nkrowlink.com/oauth/authorizegrant_type=authorization_code&response_type=code&client_id=rowsandall-staging&scope=read&state=fc8fc3d8-ce0a-443e-838a-1c06fb5317c6&redirect_uri=https%3A%2F%2Fdunav.ngrok.io%2Fnk_callback%2F
|
#https://oauth-stage.nkrowlink.com/oauth/authorizegrant_type=authorization_code&response_type=code&client_id=rowsandall-staging&scope=read&state=fc8fc3d8-ce0a-443e-838a-1c06fb5317c6&redirect_uri=https%3A%2F%2Fdunav.ngrok.io%2Fnk_callback%2F
|
||||||
#https://oauth-stage.nkrowlink.com/oauth/authorize?grant_type=authorization_code&response_type=code&client_id=rowsandall-staging&scope=read&state=1234&redirect_uri=https%3A%2F%2Fdev.rowsandall.com%2Fnk_callback
|
#https://oauth-stage.nkrowlink.com/oauth/authorize?grant_type=authorization_code&response_type=code&client_id=rowsandall-staging&scope=read&state=1234&redirect_uri=https%3A%2F%2Fdev.rowsandall.com%2Fnk_callback
|
||||||
|
|
||||||
|
from requests_oauthlib import OAuth2Session
|
||||||
|
|
||||||
import django_rq
|
import django_rq
|
||||||
queue = django_rq.get_queue('default')
|
queue = django_rq.get_queue('default')
|
||||||
queuelow = django_rq.get_queue('low')
|
queuelow = django_rq.get_queue('low')
|
||||||
@@ -48,11 +50,22 @@ oauth_data = {
|
|||||||
'expirydatename': 'nktokenexpirydate',
|
'expirydatename': 'nktokenexpirydate',
|
||||||
'bearer_auth': True,
|
'bearer_auth': True,
|
||||||
'base_url': "https://oauth-stage.nkrowlink.com/oauth/token",
|
'base_url': "https://oauth-stage.nkrowlink.com/oauth/token",
|
||||||
'grant_type': 'refresh_token',
|
|
||||||
'scope':'read',
|
'scope':'read',
|
||||||
}
|
}
|
||||||
|
|
||||||
def get_token(code):
|
def get_token(code):
|
||||||
|
#client_id = oauth_data['client_id']
|
||||||
|
#client_secret = oauth_data['client_secret']
|
||||||
|
#base_uri = oauth_data['base_url']
|
||||||
|
|
||||||
|
#callbackuri = 'https://'+callbackuri[9:]
|
||||||
|
#print(callbackuri)
|
||||||
|
|
||||||
|
#nk = OAuth2Session(client_id)
|
||||||
|
#token = nk.fetch_token(base_uri,client_secret=client_secret,authorization_response=callbackuri)
|
||||||
|
|
||||||
|
#print(token)
|
||||||
|
#return [0,0,0]
|
||||||
return imports_get_token(code, oauth_data)
|
return imports_get_token(code, oauth_data)
|
||||||
|
|
||||||
def nk_open(user):
|
def nk_open(user):
|
||||||
@@ -105,3 +118,25 @@ def get_nk_workout_list(user,fake=False):
|
|||||||
s = requests.get(url,headers=headers,params=params)
|
s = requests.get(url,headers=headers,params=params)
|
||||||
|
|
||||||
return s
|
return s
|
||||||
|
|
||||||
|
def get_nk_workout_strokes(user,nkid):
|
||||||
|
r = Rower.objects.get(user=user)
|
||||||
|
|
||||||
|
if (r.nktoken == '') or (r.nktoken is None):
|
||||||
|
return custom_exception_handler(401,s)
|
||||||
|
s = "Token doesn't exist. Need to authorize"
|
||||||
|
elif (timezone.now()>r.tokenexpirydate):
|
||||||
|
s = "Token expired. Needs to refresh."
|
||||||
|
return custom_exception_handler(401,s)
|
||||||
|
else:
|
||||||
|
# ready to fetch. Hurray
|
||||||
|
authorizationstring = str('Bearer ' + r.nktoken)
|
||||||
|
headers = {'Authorization': authorizationstring,
|
||||||
|
'user-agent': 'sanderroosendaal',
|
||||||
|
'Content-Type': 'application/json'}
|
||||||
|
url = "https://log.concept2.com/api/users/me/results/"+str(nkid)+"/strokes"
|
||||||
|
s = requests.get(url,headers=headers)
|
||||||
|
|
||||||
|
return s
|
||||||
|
#
|
||||||
|
#def get_workout(user,nkid):
|
||||||
|
|||||||
@@ -401,7 +401,7 @@ def rower_nk_authorize(request):
|
|||||||
params = {
|
params = {
|
||||||
"grant_type": "authorization_code",
|
"grant_type": "authorization_code",
|
||||||
"response_type": "code",
|
"response_type": "code",
|
||||||
"client_id": NK_ClIENT_ID,
|
"client_id": NK_CLIENT_ID,
|
||||||
"scope": scope,
|
"scope": scope,
|
||||||
"state": state,
|
"state": state,
|
||||||
"redirect_uri": NK_REDIRECT_URI,
|
"redirect_uri": NK_REDIRECT_URI,
|
||||||
@@ -776,10 +776,11 @@ def rower_process_garmincallback(request):
|
|||||||
# Process NK Callback
|
# Process NK Callback
|
||||||
@login_required()
|
@login_required()
|
||||||
def rower_process_nkcallback(request):
|
def rower_process_nkcallback(request):
|
||||||
|
uri = request.build_absolute_uri()
|
||||||
# do stuff
|
# do stuff
|
||||||
try:
|
try:
|
||||||
code = request.get['code']
|
code = request.GET.get('code',None)
|
||||||
res = nkstuff.get_token['code']
|
res = nkstuff.get_token(code)
|
||||||
except MultiValueDictKeyError:
|
except MultiValueDictKeyError:
|
||||||
message = "The resource owner or authorization server denied the request"
|
message = "The resource owner or authorization server denied the request"
|
||||||
messages.error(request,message)
|
messages.error(request,message)
|
||||||
@@ -787,6 +788,9 @@ def rower_process_nkcallback(request):
|
|||||||
url = reverse('rower_exportsettings_view')
|
url = reverse('rower_exportsettings_view')
|
||||||
return HttpResponseRedirect(url)
|
return HttpResponseRedirect(url)
|
||||||
|
|
||||||
|
uri = request.build_absolute_uri()
|
||||||
|
|
||||||
|
print(res)
|
||||||
access_token = res[0]
|
access_token = res[0]
|
||||||
if access_token == 0:
|
if access_token == 0:
|
||||||
message = res[1]
|
message = res[1]
|
||||||
|
|||||||
Reference in New Issue
Block a user