Changing password and email

This commit is contained in:
BarsTiger
2022-02-03 18:38:11 +02:00
parent 6927bd6286
commit 3df906bb93
5 changed files with 101 additions and 17 deletions

View File

@@ -1,6 +1,5 @@
import requests
import modules.gui as gui
import threading
from modules.auth import del_auth, get_auth
import modules.vars as horsy_vars
import json
@@ -8,27 +7,38 @@ from PyQt5 import QtWidgets
def change(oldpass, newpass):
ui = gui.Ui_MainWindow()
ui.setupUi(QtWidgets.QMainWindow())
UiLoginWindow = QtWidgets.QMainWindow()
login_ui = gui.Ui_LoginWindow()
login_ui.setupUi(UiLoginWindow)
if oldpass == "" or newpass == "":
gui.popup('Error', 'Please enter both old and new passwords.')
return
with open(horsy_vars.horsypath + 'config.cfg') as f:
config = json.load(f)
config = get_auth(True, gui.Ui_LoginWindow(), QtWidgets.QMainWindow())
try:
if oldpass != config['auth']['password']:
if oldpass != config['password']:
gui.popup('Error', 'Old password does not match with password in config.cfg')
return
except KeyError:
except:
gui.popup('Error', 'You don\'t have a password set in config.cfg')
return
try:
r = requests.put(horsy_vars.protocol + horsy_vars.server_url + '/users',
json={'auth': config['auth'], 'password': newpass}).text
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')
@@ -38,14 +48,8 @@ def change(oldpass, newpass):
gui.popup('Error', 'Internal server error')
return 'Internal server error'
elif r == '':
gui.popup('Success', 'Success, your password has been changed')
config['auth'] = {'email': config['auth']['email'], 'password': newpass}
with open(horsy_vars.horsypath + 'config.cfg', 'w') as f:
json.dump(config, f)
else:
print('[red]Unknown error, please try again[/red]')
print('Unknown error, please try again')
print('Server response:')
print(r)
return 'Unknown error, please try again, \n Server response: \n' + str(r)