Changing password and email
This commit is contained in:
@@ -165,6 +165,11 @@ def change_password_gui():
|
|||||||
change(ui.oldpass_box.toPlainText(), ui.newpass_box.toPlainText())
|
change(ui.oldpass_box.toPlainText(), ui.newpass_box.toPlainText())
|
||||||
|
|
||||||
|
|
||||||
|
def change_email_gui():
|
||||||
|
from modules.change_email import change
|
||||||
|
change(ui.email_box.toPlainText())
|
||||||
|
|
||||||
|
|
||||||
# Run functions on startup
|
# Run functions on startup
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
# Checking version
|
# Checking version
|
||||||
@@ -206,6 +211,7 @@ if __name__ == "__main__":
|
|||||||
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)
|
ui.changepass_button.clicked.connect(change_password_gui)
|
||||||
|
ui.changeemail_button.clicked.connect(change_email_gui)
|
||||||
|
|
||||||
# Handle GUI exiting to exit whole program
|
# Handle GUI exiting to exit whole program
|
||||||
sys.exit(app.exec_())
|
sys.exit(app.exec_())
|
||||||
|
|||||||
@@ -24,6 +24,7 @@ def get_auth(is_gui=False, login_ui=None, Ui_LoginWindow=None):
|
|||||||
print('[OK] Auth created')
|
print('[OK] Auth created')
|
||||||
return config['auth']
|
return config['auth']
|
||||||
else:
|
else:
|
||||||
|
login_ui.setupUi(Ui_LoginWindow)
|
||||||
Ui_LoginWindow.show()
|
Ui_LoginWindow.show()
|
||||||
login_ui.login_button.clicked.connect(lambda: get_gui_auth(login_ui=login_ui,
|
login_ui.login_button.clicked.connect(lambda: get_gui_auth(login_ui=login_ui,
|
||||||
Ui_LoginWindow=Ui_LoginWindow))
|
Ui_LoginWindow=Ui_LoginWindow))
|
||||||
|
|||||||
@@ -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.')
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
import requests
|
import requests
|
||||||
import modules.gui as gui
|
import modules.gui as gui
|
||||||
import threading
|
|
||||||
from modules.auth import del_auth, get_auth
|
from modules.auth import del_auth, get_auth
|
||||||
import modules.vars as horsy_vars
|
import modules.vars as horsy_vars
|
||||||
import json
|
import json
|
||||||
@@ -8,27 +7,38 @@ from PyQt5 import QtWidgets
|
|||||||
|
|
||||||
|
|
||||||
def change(oldpass, newpass):
|
def change(oldpass, newpass):
|
||||||
ui = gui.Ui_MainWindow()
|
UiLoginWindow = QtWidgets.QMainWindow()
|
||||||
ui.setupUi(QtWidgets.QMainWindow())
|
login_ui = gui.Ui_LoginWindow()
|
||||||
|
login_ui.setupUi(UiLoginWindow)
|
||||||
|
|
||||||
if oldpass == "" or newpass == "":
|
if oldpass == "" or newpass == "":
|
||||||
gui.popup('Error', 'Please enter both old and new passwords.')
|
gui.popup('Error', 'Please enter both old and new passwords.')
|
||||||
return
|
return
|
||||||
|
|
||||||
with open(horsy_vars.horsypath + 'config.cfg') as f:
|
config = get_auth(True, gui.Ui_LoginWindow(), QtWidgets.QMainWindow())
|
||||||
config = json.load(f)
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
if oldpass != config['auth']['password']:
|
if oldpass != config['password']:
|
||||||
gui.popup('Error', 'Old password does not match with password in config.cfg')
|
gui.popup('Error', 'Old password does not match with password in config.cfg')
|
||||||
return
|
return
|
||||||
except KeyError:
|
except:
|
||||||
gui.popup('Error', 'You don\'t have a password set in config.cfg')
|
gui.popup('Error', 'You don\'t have a password set in config.cfg')
|
||||||
return
|
return
|
||||||
|
|
||||||
try:
|
try:
|
||||||
r = requests.put(horsy_vars.protocol + horsy_vars.server_url + '/users',
|
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:
|
try:
|
||||||
if r['message'] == 'Unauthorized':
|
if r['message'] == 'Unauthorized':
|
||||||
gui.popup('Error', 'Invalid credentials \nDeleting auth from config')
|
gui.popup('Error', 'Invalid credentials \nDeleting auth from config')
|
||||||
@@ -38,14 +48,8 @@ def change(oldpass, newpass):
|
|||||||
gui.popup('Error', 'Internal server error')
|
gui.popup('Error', 'Internal server error')
|
||||||
return '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:
|
else:
|
||||||
print('[red]Unknown error, please try again[/red]')
|
print('Unknown error, please try again')
|
||||||
print('Server response:')
|
print('Server response:')
|
||||||
print(r)
|
print(r)
|
||||||
return 'Unknown error, please try again, \n Server response: \n' + str(r)
|
return 'Unknown error, please try again, \n Server response: \n' + str(r)
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
from PyQt5 import QtCore, QtGui, QtWidgets
|
from PyQt5 import QtCore, QtGui, QtWidgets
|
||||||
import modules.images
|
import modules.images # import images from binaries
|
||||||
import requests
|
import ctypes
|
||||||
|
|
||||||
|
|
||||||
class Ui_MainWindow(object):
|
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>"))
|
"<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"))
|
self.logs_box.setPlaceholderText(_translate("MainWindow", "Logs"))
|
||||||
|
|
||||||
|
|
||||||
def popup(title, text):
|
def popup(title, text):
|
||||||
QtWidgets.QMessageBox.information(None, 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__":
|
if __name__ == "__main__":
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user