From 4649dfb82c77641f408ee71b9924f87079f6691a Mon Sep 17 00:00:00 2001 From: RemixDev Date: Mon, 13 Apr 2020 00:14:34 +0200 Subject: [PATCH] Added login, logout and other stuff --- server.py | 31 ++++++++++++++++++++++++++++--- 1 file changed, 28 insertions(+), 3 deletions(-) diff --git a/server.py b/server.py index 621a583..3212ece 100644 --- a/server.py +++ b/server.py @@ -54,12 +54,33 @@ def handle_init(): emit('initialization', result) @socketio.on('login') -def login(arl): - result = app.login(session['dz'], arl) +def login(arl, force=False): + emit('toast', {'msg': "Logging in...", 'icon': 'loading', 'dismiss': False, 'id': "login-toast"}) + if not session['dz'].logged_in: + result = session['dz'].login_via_arl(arl) + else: + if force: + session['dz'] = Deezer() + result = session['dz'].login_via_arl(arl) + if result == 1: + result = 3 + else: + result = 2 emit('logged_in', {'status': result, 'arl': arl, 'user': app.getUser(session['dz'])}) +@socketio.on('logout') +def logout(): + status = 0 + if session['dz'].logged_in: + session['dz'] = Deezer() + status = 0 + else: + status = 1 + emit('logged_out', status) + @socketio.on('loginpage') def login_app(): + emit('toast', {'msg': "Logging in...", 'icon': 'loading', 'dismiss': False, 'id': "login-toast"}) loginWindow = webview.create_window('Login into deezer.com', 'https://www.deezer.com/login', user_agent="Mozilla/5.0 (Linux; U; Android 4.0.3; ko-kr; LG-L160L Build/IML74K) AppleWebkit/534.30 (KHTML, like Gecko) Version/4.0 Mobile Safari/534.30") while (loginWindow and loginWindow.get_current_url().startswith("https://www.deezer.com")): time.sleep(1) @@ -68,7 +89,11 @@ def login_app(): loginWindow.destroy() arl = url[url.find("arl%3D")+6:] arl = arl[:arl.find("&")] - result = app.login(session['dz'], arl) + # Login function + if not session['dz'].logged_in: + result = session['dz'].login_via_arl(arl) + else: + result = 2 emit('logged_in', {'status': result, 'arl': arl, 'user': app.getUser(session['dz'])}) else: emit('logged_in', {'status': 0})