mirror of
https://github.com/fishyboteso/fishyboteso.git
synced 2024-08-30 18:32:13 +00:00
discord login panel reworked for backend changes
This commit is contained in:
parent
84f6b25f4f
commit
7e00771887
@ -61,7 +61,7 @@ def start_semifisher_config(gui: 'GUI'):
|
|||||||
gui._notify_check = Checkbutton(controls_frame, command=toggle_sub, variable=gui._notify)
|
gui._notify_check = Checkbutton(controls_frame, command=toggle_sub, variable=gui._notify)
|
||||||
gui._notify_check.grid(row=0, column=1)
|
gui._notify_check.grid(row=0, column=1)
|
||||||
gui._notify_check['state'] = DISABLED
|
gui._notify_check['state'] = DISABLED
|
||||||
is_subbed = web.is_subbed(config.get('uid'), lazy=False)
|
is_subbed = web.is_subbed(config.get('uid'))
|
||||||
if is_subbed[1]:
|
if is_subbed[1]:
|
||||||
gui._notify_check['state'] = NORMAL
|
gui._notify_check['state'] = NORMAL
|
||||||
gui._notify.set(is_subbed[0])
|
gui._notify.set(is_subbed[0])
|
||||||
|
@ -3,9 +3,10 @@ from tkinter import *
|
|||||||
from tkinter import messagebox
|
from tkinter import messagebox
|
||||||
from tkinter.ttk import *
|
from tkinter.ttk import *
|
||||||
|
|
||||||
from fishy import web
|
|
||||||
import typing
|
import typing
|
||||||
|
|
||||||
|
from fishy.web import web
|
||||||
|
|
||||||
from fishy.libs.tkhtmlview import HTMLLabel
|
from fishy.libs.tkhtmlview import HTMLLabel
|
||||||
from ..helper.config import config
|
from ..helper.config import config
|
||||||
|
|
||||||
@ -15,25 +16,26 @@ if typing.TYPE_CHECKING:
|
|||||||
|
|
||||||
# noinspection PyProtectedMember
|
# noinspection PyProtectedMember
|
||||||
def discord_login(gui: 'GUI'):
|
def discord_login(gui: 'GUI'):
|
||||||
if web.is_subbed(config.get("uid"))[0]:
|
if web.is_logged_in(config.get("uid")):
|
||||||
web.unsub(config.get("uid"))
|
if web.logout(config.get("uid")):
|
||||||
|
gui.login.set(0)
|
||||||
return
|
return
|
||||||
|
|
||||||
# set notification checkbutton
|
# set notification checkbutton
|
||||||
gui._notify.set(0)
|
gui.login.set(0)
|
||||||
|
|
||||||
def quit_top():
|
def quit_top():
|
||||||
top.destroy()
|
top.destroy()
|
||||||
top_running[0] = False
|
top_running[0] = False
|
||||||
|
|
||||||
def check():
|
def check():
|
||||||
if web.sub(config.get("uid"), discord_name.get()):
|
code = int(login_code.get()) if login_code.get().isdigit() else 0
|
||||||
if web.is_subbed(config.get("uid"), False)[0]:
|
if web.login(config.get("uid"), code):
|
||||||
gui._notify.set(1)
|
gui.login.set(1)
|
||||||
messagebox.showinfo("Note!", "Notification configured successfully!")
|
messagebox.showinfo("Note!", "Logged in successfuly!")
|
||||||
quit_top()
|
quit_top()
|
||||||
else:
|
else:
|
||||||
messagebox.showerror("Error", "Subscription wasn't successful")
|
messagebox.showerror("Error", "Logged wasn't successful")
|
||||||
|
|
||||||
top_running = [True]
|
top_running = [True]
|
||||||
|
|
||||||
@ -54,8 +56,8 @@ def discord_login(gui: 'GUI'):
|
|||||||
html_label.pack(pady=(20, 5))
|
html_label.pack(pady=(20, 5))
|
||||||
html_label.fit_height()
|
html_label.fit_height()
|
||||||
|
|
||||||
discord_name = Entry(top, justify=CENTER, font="Calibri 15")
|
login_code = Entry(top, justify=CENTER, font="Calibri 15")
|
||||||
discord_name.pack(padx=(15, 15), expand=True, fill=BOTH)
|
login_code.pack(padx=(15, 15), expand=True, fill=BOTH)
|
||||||
|
|
||||||
html_label = HTMLLabel(top,
|
html_label = HTMLLabel(top,
|
||||||
html=f'<div style="color: {gui._console["fg"]}; text-align: center">'
|
html=f'<div style="color: {gui._console["fg"]}; text-align: center">'
|
||||||
|
@ -3,6 +3,7 @@ import time
|
|||||||
from tkinter import *
|
from tkinter import *
|
||||||
from tkinter.ttk import *
|
from tkinter.ttk import *
|
||||||
|
|
||||||
|
from fishy.web import web
|
||||||
from ttkthemes import ThemedTk
|
from ttkthemes import ThemedTk
|
||||||
|
|
||||||
from fishy import helper
|
from fishy import helper
|
||||||
@ -39,7 +40,11 @@ def _create(gui: 'GUI'):
|
|||||||
|
|
||||||
filemenu = Menu(menubar, tearoff=0)
|
filemenu = Menu(menubar, tearoff=0)
|
||||||
|
|
||||||
filemenu.add_checkbutton(label="Login", command=lambda: discord_login(gui), variable=gui.login)
|
login = web.is_logged_in(config.get('uid'))
|
||||||
|
gui.login = IntVar()
|
||||||
|
gui.login.set(1 if login > 0 else 0)
|
||||||
|
state = DISABLED if login == -1 else ACTIVE
|
||||||
|
filemenu.add_checkbutton(label="Login", command=lambda: discord_login(gui), variable=gui.login, state=state)
|
||||||
filemenu.add_command(label="Create Shortcut", command=lambda: helper.create_shortcut(False))
|
filemenu.add_command(label="Create Shortcut", command=lambda: helper.create_shortcut(False))
|
||||||
# filemenu.add_command(label="Create Anti-Ghost Shortcut", command=lambda: helper.create_shortcut(True))
|
# filemenu.add_command(label="Create Anti-Ghost Shortcut", command=lambda: helper.create_shortcut(True))
|
||||||
|
|
||||||
|
@ -13,6 +13,7 @@ subscription = domain + "/api/notify_semifish"
|
|||||||
hole_depleted = domain + "/api/hole_depleted"
|
hole_depleted = domain + "/api/hole_depleted"
|
||||||
session = domain + "/api/session"
|
session = domain + "/api/session"
|
||||||
terms = domain + "/terms.html"
|
terms = domain + "/terms.html"
|
||||||
|
discord = domain + "/api/discord"
|
||||||
|
|
||||||
|
|
||||||
def get_notification_page(uid):
|
def get_notification_page(uid):
|
||||||
|
@ -10,6 +10,38 @@ from ..helper.config import config
|
|||||||
_session_id = None
|
_session_id = None
|
||||||
|
|
||||||
|
|
||||||
|
@fallback(-1)
|
||||||
|
def is_logged_in(uid):
|
||||||
|
if uid is None:
|
||||||
|
return -1
|
||||||
|
|
||||||
|
body = {"uid": uid}
|
||||||
|
response = requests.get(urls.discord, params=body)
|
||||||
|
logged_in = response.json()["discord_login"]
|
||||||
|
return 1 if logged_in else 0
|
||||||
|
|
||||||
|
|
||||||
|
@fallback(False)
|
||||||
|
def login(uid, login_code):
|
||||||
|
body = {
|
||||||
|
"uid": uid,
|
||||||
|
"login_code": login_code
|
||||||
|
}
|
||||||
|
reponse = requests.post(urls.discord, json=body)
|
||||||
|
result = reponse.json()
|
||||||
|
return result["success"]
|
||||||
|
|
||||||
|
|
||||||
|
@fallback(False)
|
||||||
|
def logout(uid):
|
||||||
|
body = {
|
||||||
|
"uid": uid,
|
||||||
|
}
|
||||||
|
reponse = requests.delete(urls.discord, json=body)
|
||||||
|
result = reponse.json()
|
||||||
|
return result["success"]
|
||||||
|
|
||||||
|
|
||||||
@fallback(False)
|
@fallback(False)
|
||||||
def register_user(uid):
|
def register_user(uid):
|
||||||
ip = get_ip(GoogleDnsProvider)
|
ip = get_ip(GoogleDnsProvider)
|
||||||
@ -62,6 +94,10 @@ def is_subbed(uid):
|
|||||||
|
|
||||||
body = {"uid": uid}
|
body = {"uid": uid}
|
||||||
response = requests.get(urls.subscription, params=body)
|
response = requests.get(urls.subscription, params=body)
|
||||||
|
|
||||||
|
if response.status_code != 200:
|
||||||
|
return False, False
|
||||||
|
|
||||||
is_subbed = response.json()["subbed"]
|
is_subbed = response.json()["subbed"]
|
||||||
return is_subbed, True
|
return is_subbed, True
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user