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

@@ -24,6 +24,7 @@ def get_auth(is_gui=False, login_ui=None, Ui_LoginWindow=None):
print('[OK] Auth created')
return config['auth']
else:
login_ui.setupUi(Ui_LoginWindow)
Ui_LoginWindow.show()
login_ui.login_button.clicked.connect(lambda: get_gui_auth(login_ui=login_ui,
Ui_LoginWindow=Ui_LoginWindow))

View File

@@ -0,0 +1,57 @@
import requests
import modules.gui as gui
from modules.auth import del_auth, get_auth
import modules.vars as horsy_vars
import json
import threading
from PyQt5 import QtWidgets
def change(email):
UiLoginWindow = QtWidgets.QMainWindow()
login_ui = gui.Ui_LoginWindow()
login_ui.setupUi(UiLoginWindow)
if email == "":
gui.popup('Error', 'Please enter new email address')
return
auth = get_auth(True, login_ui, QtWidgets.QMainWindow())
try:
def change_in_new_thread():
try:
r = requests.put(horsy_vars.protocol + horsy_vars.server_url + '/users',
json={'auth': auth, 'email': email})
try:
r = r.json()
except:
if r.text == '':
gui.cpopup('Success', 'Success, your email has been changed')
with open(horsy_vars.horsypath + 'config.cfg') as f:
config = json.load(f)
config['auth'] = {'email': email, 'password': config['auth']['password']}
with open(horsy_vars.horsypath + 'config.cfg', 'w') as f:
json.dump(config, f)
try:
if r['message'] == 'Unauthorized':
gui.cpopup('Error', 'Invalid credentials \nDeleting auth from config')
del_auth()
elif r['message'] == 'Internal server error':
gui.cpopup('Error', 'Internal server error')
return 'Internal server error'
else:
print('Unknown error, please try again')
print('Server response:')
print(r.text)
return 'Unknown error, please try again, \n Server response: \n' + str(r.text)
except:
pass
except:
gui.cpopup('Error', 'Unexpected error.')
threading.Thread(target=change_in_new_thread).start()
gui.popup('Started', 'Check your email for confirmation')
except:
gui.popup('Error', 'Unexpected error.')

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)

View File

@@ -1,6 +1,6 @@
from PyQt5 import QtCore, QtGui, QtWidgets
import modules.images
import requests
import modules.images # import images from binaries
import ctypes
class Ui_MainWindow(object):
@@ -801,9 +801,25 @@ class Ui_DownloadWindow(object):
"<p style=\"-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\"><br /></p></body></html>"))
self.logs_box.setPlaceholderText(_translate("MainWindow", "Logs"))
def popup(title, text):
QtWidgets.QMessageBox.information(None, title, text)
def cpopup(title, text, style=0):
"""
Styles:
0 : OK
1 : OK | Cancel
2 : Abort | Retry | Ignore
3 : Yes | No | Cancel
4 : Yes | No
5 : Retry | Cancel
6 : Cancel | Try Again | Continue
"""
return ctypes.windll.user32.MessageBoxW(0, text, title, style)
if __name__ == "__main__":
import sys