New handling system everywhere
This commit is contained in:
@@ -1,8 +1,8 @@
|
||||
import requests
|
||||
import modules.gui as gui
|
||||
from modules.auth import del_auth, get_auth
|
||||
from modules.auth import get_auth
|
||||
import modules.vars as horsy_vars
|
||||
import json
|
||||
from modules.http_status import handle
|
||||
from PyQt5 import QtWidgets
|
||||
|
||||
|
||||
@@ -26,34 +26,9 @@ def change(oldpass, newpass):
|
||||
return
|
||||
|
||||
try:
|
||||
r = requests.put(horsy_vars.protocol + horsy_vars.server_url + '/users',
|
||||
json={'auth': get_auth(True, login_ui, QtWidgets.QMainWindow()),
|
||||
'password': newpass})
|
||||
try:
|
||||
r = r.json()
|
||||
except:
|
||||
if r.text == '':
|
||||
gui.popup('Success', 'Success, your password has been changed')
|
||||
with open(horsy_vars.horsypath + 'config.cfg') as f:
|
||||
config = json.load(f)
|
||||
config['auth'] = {'email': config['auth']['email'], 'password': newpass}
|
||||
with open(horsy_vars.horsypath + 'config.cfg', 'w') as f:
|
||||
json.dump(config, f)
|
||||
try:
|
||||
if r['message'] == 'Unauthorized':
|
||||
gui.popup('Error', 'Invalid credentials \nDeleting auth from config')
|
||||
del_auth()
|
||||
|
||||
elif r['message'] == 'Internal server error':
|
||||
gui.popup('Error', 'Internal server error')
|
||||
return 'Internal server error'
|
||||
|
||||
else:
|
||||
print('Unknown error, please try again')
|
||||
print('Server response:')
|
||||
print(r)
|
||||
return 'Unknown error, please try again, \n Server response: \n' + str(r)
|
||||
except:
|
||||
pass
|
||||
gui.cpopup("Changing password",
|
||||
handle(requests.put(horsy_vars.protocol + horsy_vars.server_url + '/users',
|
||||
json={'auth': get_auth(True, login_ui, QtWidgets.QMainWindow()),
|
||||
'password': newpass}).status_code)[1])
|
||||
except:
|
||||
gui.popup('Error', 'Unexpected error.')
|
||||
|
||||
Reference in New Issue
Block a user