DEV Password and email changing
This commit is contained in:
@@ -160,6 +160,11 @@ def upload_gui():
|
|||||||
gui.popup('Upload', str(upload(True, ui, login_ui, UiMainWindow)))
|
gui.popup('Upload', str(upload(True, ui, login_ui, UiMainWindow)))
|
||||||
|
|
||||||
|
|
||||||
|
def change_password_gui():
|
||||||
|
from modules.change_password import change
|
||||||
|
change(ui.oldpass_box.toPlainText(), ui.newpass_box.toPlainText())
|
||||||
|
|
||||||
|
|
||||||
# Run functions on startup
|
# Run functions on startup
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
# Checking version
|
# Checking version
|
||||||
@@ -200,6 +205,7 @@ if __name__ == "__main__":
|
|||||||
ui.upload_button.clicked.connect(upload_gui)
|
ui.upload_button.clicked.connect(upload_gui)
|
||||||
ui.regmessage_button.clicked.connect(lambda: webbrowser.open(f"{horsy_vars.protocol}{horsy_vars.server_url}"
|
ui.regmessage_button.clicked.connect(lambda: webbrowser.open(f"{horsy_vars.protocol}{horsy_vars.server_url}"
|
||||||
f"/registration"))
|
f"/registration"))
|
||||||
|
ui.changepass_button.clicked.connect(change_password_gui)
|
||||||
|
|
||||||
# Handle GUI exiting to exit whole program
|
# Handle GUI exiting to exit whole program
|
||||||
sys.exit(app.exec_())
|
sys.exit(app.exec_())
|
||||||
|
|||||||
0
modules/change_email.py
Normal file
0
modules/change_email.py
Normal file
52
modules/change_password.py
Normal file
52
modules/change_password.py
Normal file
@@ -0,0 +1,52 @@
|
|||||||
|
import requests
|
||||||
|
import modules.gui as gui
|
||||||
|
import threading
|
||||||
|
from modules.auth import del_auth
|
||||||
|
import modules.vars as horsy_vars
|
||||||
|
import json
|
||||||
|
from PyQt5 import QtWidgets
|
||||||
|
|
||||||
|
|
||||||
|
def change(oldpass, newpass):
|
||||||
|
ui = gui.Ui_MainWindow()
|
||||||
|
ui.setupUi(QtWidgets.QMainWindow())
|
||||||
|
|
||||||
|
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)
|
||||||
|
|
||||||
|
try:
|
||||||
|
if oldpass != config['auth']['password']:
|
||||||
|
gui.popup('Error', 'Old password does not match with password in config.cfg')
|
||||||
|
return
|
||||||
|
except KeyError:
|
||||||
|
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
|
||||||
|
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'
|
||||||
|
|
||||||
|
elif r == '':
|
||||||
|
gui.popup('Success', 'Success, your password has been changed')
|
||||||
|
|
||||||
|
else:
|
||||||
|
print('[red]Unknown error, please try again[/red]')
|
||||||
|
print('Server response:')
|
||||||
|
print(r)
|
||||||
|
return 'Unknown error, please try again, \n Server response: \n' + str(r)
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
except:
|
||||||
|
gui.popup('Error', 'Unexpected error.')
|
||||||
Reference in New Issue
Block a user