Skip to content

Commit

Permalink
fix: Switching between sms and pwd may trigger loop
Browse files Browse the repository at this point in the history
  • Loading branch information
itsHenry35 committed Jun 22, 2023
1 parent 60071e4 commit 7a42a70
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 67 deletions.
82 changes: 41 additions & 41 deletions gui/login1.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,42 +4,33 @@
import tkinter.messagebox as mb
import sys

def login1():
global sms
global root
global username
def switchshowpwd():
if password['show'] == '':
password['show'] = '*'
else:
password["show"] = ''
def switchtosms():
global username_
global sms
sms = 'True'
username_ = username.get().replace('\r','').replace('\n','').replace('\t','')

def switchshowpwd(password):
if password['show'] == '':
password['show'] = '*'
else:
password["show"] = ''
def switchtosms(username, root):
global username_value, sms, exitbool
exitbool = False
sms = 'True'
username_value = username.get().replace('\r','').replace('\n','').replace('\t','')
root.destroy()

def nextpage(username, password, root):
global username_value, password_value, sms, exitbool
sms = 'False'
username_value = username.get().replace('\r','').replace('\n','').replace('\t','')
password_value = password.get().replace('\r','').replace('\n','').replace('\t','')
if not username_value or not password_value:
mb.showwarning("警告", "请填写用户名与密码!")
else:
exitbool = False
root.destroy()
if sms == 'False':
return {'success' : 'True',
'usrname':username_,
'pwd':password_,
}
if sms == 'True':
return {
'success' : 'False',
'phonenum' : username_
}
def nextpage():
global username_
global password_
global sms
sms = 'False'
username_ = username.get().replace('\r','').replace('\n','').replace('\t','')
password_ = password.get().replace('\r','').replace('\n','').replace('\t','')
if not username_ or not password_:
mb.showwarning("警告", "请填写用户名与密码!")
else:
root.destroy()

def login1(username_default=""):
global exitbool
exitbool = True
root = ttk.Window(title = '乐读视频下载器-登陆', themename="morph")
root.geometry('1280x720')
title = ttk.Label(text = '登陆', font = ('等线 (Body Asian)', 20))
Expand All @@ -48,22 +39,31 @@ def nextpage():
text1.grid(row=1)
username = ttk.Entry(bootstyle="primary")
username.grid(row=1,column=1)
username.insert(0, username_default)
text2 = ttk.Label(text = '密码:')
text2.grid(row=2)
password = ttk.Entry(bootstyle="primary", show="*")
password.grid(row=2,column=1)
showpwd = ttk.Button(text='显示/隐藏密码', bootstyle="defaulte", command=switchshowpwd)
showpwd = ttk.Button(text='显示/隐藏密码', bootstyle="defaulte", command=lambda: switchshowpwd(password))
showpwd.grid(row=2,column=2)
smsswitch = ttk.Button(text='短信验证码登陆', bootstyle="default-outline", command=switchtosms)
smsswitch = ttk.Button(text='短信验证码登陆', bootstyle="default-outline", command=lambda: switchtosms(username, root))
smsswitch.grid(row=2,column=3)
submit = ttk.Button(text='提交', bootstyle="primary", command=nextpage)
submit = ttk.Button(text='提交', bootstyle="primary", command=lambda: nextpage(username, password, root))
submit.grid(row=3, column=2)
root.mainloop()
importlib.reload(ttk.style)
try:
sms
except NameError:
if exitbool:
sys.exit()
if sms == 'False':
return {'pwdlogin' : 'True',
'usrname':username_value,
'pwd':password_value,
}
if sms == 'True':
return {
'pwdlogin' : 'False',
'phonenum' : username_value
}

if __name__ == '__main__':
print(login1())
45 changes: 26 additions & 19 deletions gui/login1_sms.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import requests
import time
import threading

import sys
import inspect
import tkinter.messagebox as mb
import ctypes
Expand Down Expand Up @@ -36,24 +36,32 @@ def after_sending(send):
time.sleep(1)
send.configure(text='重新发送', state="enabled")

def switch_to_pwd(root):
global ispwd
def switch_to_pwd(username,root):
global credentials, exitbool
exitbool = False
credentials = {
'pwdlogin' : 'True',
'phonenum':username.get(),
}
root.destroy()
ispwd = 'True'

def next_page(username, password, root, zonevar):
phonenum_ = username.get()
smscode_ = password.get()
global credentials, exitbool
exitbool = False
credentials = {
'pwdlogin' : 'False',
'phonenum':username.get(),
'code': password.get(),
'zonecode' : zonelist[zonevar.get()]
}
if not password.get().isdigit():
mb.showwarning('警告', '请输入正确的验证码')
return
root.destroy()
return {'success' : 'True',
'phonenum':phonenum_,
'code': smscode_,
'zonecode' : zonelist[zonevar.get()]
}

def send_msg(username, zonevar, send, thread_):
if not username.get().isdigit():
mb.showerror('错误', '请输入正确的手机号码')
mb.showwarning('警告', '请输入正确的手机号码')
return
url= "https://passport.100tal.com/v1/web/login/sms/send"
headers = {
Expand Down Expand Up @@ -81,8 +89,8 @@ def send_msg(username, zonevar, send, thread_):
return thread_

def login1_sms(phonenum):
global root
ispwd = 'False'
global root, exitbool
exitbool = True
phonenum = str(phonenum)
thread_ = 0
root = ttk.Window(title = '乐读视频下载器-登陆', themename="morph")
Expand All @@ -104,15 +112,14 @@ def login1_sms(phonenum):
password.grid(row=2,column=2)
send = ttk.Button(text='发送验证码', bootstyle="default", command=lambda: send_msg(username, zonevar, send, thread_))
send.grid(row=2,column=3)
smsswitch = ttk.Button(text='返回账号密码登陆', bootstyle="default-outline", command=lambda: switch_to_pwd(root))
smsswitch = ttk.Button(text='返回账号密码登陆', bootstyle="default-outline", command=lambda: switch_to_pwd(username, root))
smsswitch.grid(row=2,column=4)
submit = ttk.Button(text='提交', bootstyle="primary", command=lambda: next_page(username, password, root, zonevar))
submit.grid(row=3, column=3)
root.mainloop()
if thread_ == 1:
stop_thread(thread)
importlib.reload(ttk.style)
if ispwd == 'False':
return next_page(username, password, root)
if ispwd == 'True':
return {'success' : 'False',}
if exitbool:
sys.exit()
return credentials
14 changes: 7 additions & 7 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,17 @@ def set_alldata(data):
uid = str(data['pu_uid'])

def perform_login(credentials):
if credentials['success'] == 'True':
if credentials['pwdlogin'] == 'True':
return login2(credentials['usrname'], credentials['pwd'])
else:
smscredential = login1_sms(credentials['phonenum'])
if smscredential['success'] == 'True':
return login2_sms(credentials['phonenum'], smscredential['code'], smscredential['zonecode'])
if smscredential['success'] == 'False':
return login()
if smscredential['pwdlogin'] == 'False':
return login2_sms(smscredential['phonenum'], smscredential['code'], smscredential['zonecode'])
if smscredential['pwdlogin'] == 'True':
return perform_login(login(username=str(smscredential['phonenum'])))

def login():
credentials = login1()
def login(username=""):
credentials = login1(username)
loginresult = perform_login(credentials)
while loginresult['success'] == 'False':
loginresult = login()
Expand Down

0 comments on commit 7a42a70

Please sign in to comment.