Fix login in to new instance

This commit is contained in:
localhost_frssoft 2023-06-14 15:27:15 +03:00
parent 9ec77975e5
commit dc40e5331c
2 changed files with 7 additions and 6 deletions

View file

@ -104,7 +104,7 @@ def main():
if selected == 'Sign in': if selected == 'Sign in':
print(f''' print(f'''
If You want sign in, please visit: If You want sign in, please visit:
https://{instance}/settings/applications/new https://{current_instance.instance}/settings/applications/new
And fill Name funkwhale-cli And fill Name funkwhale-cli
Scopes: Read, Write (optional): write:favorites write:listenings write:filters Scopes: Read, Write (optional): write:favorites write:listenings write:filters
@ -113,13 +113,14 @@ Insert token from "Access token" here''')
with open('.auth.json', 'rt') as f: with open('.auth.json', 'rt') as f:
tkns = json.loads(f.read()) tkns = json.loads(f.read())
with open('.auth.json', 'wt') as f: with open('.auth.json', 'wt') as f:
tkns[instance] = register_token tkns[current_instance.instance] = register_token
f.write(json.dumps(tkns)) f.write(json.dumps(tkns))
del tkns del tkns
del register_token del register_token
del f del f
os.system('clear')
current_instance.select_instance(instance) current_instance.select_instance(current_instance.instance)
if selected == 'Donate': if selected == 'Donate':
os.system(f'less <<EOF\nSupport instance message:\n{support_message}') os.system(f'less <<EOF\nSupport instance message:\n{support_message}')
if selected == 'About instance': if selected == 'About instance':

View file

@ -39,14 +39,14 @@ class current_instance:
def select_instance(new_instance=None): def select_instance(new_instance=None):
current_instance.instance = new_instance current_instance.instance = new_instance
with open(auth_file, 'rt') as f: with open(auth_file, 'rt') as f:
auth = json.loads(f.read()) auth = json.load(f)
new_token = auth.get(current_instance.instance) new_token = auth.get(current_instance.instance)
current_instance.s.headers.update({"Authorization": None}) current_instance.s.headers.update({"Authorization": None})
current_instance.token = new_token current_instance.token = new_token
current_instance.listen_token = None current_instance.listen_token = None
if new_token: if new_token:
s.get(f'https://{current_instance.instance}') current_instance.s.get(f'https://{current_instance.instance}')
s.headers.update({"Authorization": "Bearer " + new_token}) current_instance.s.headers.update({"Authorization": "Bearer " + new_token})
if current_instance.token: if current_instance.token: