def olduser_cancel(connect,ad, pwd_wrongnumber_rep): #----------------- check the feasibility of this user -------------------- connect.sendall("Please enter your existing user name:\n>>") #====================================== (data, quit) = check_input_early(connect, ad) if quit: print "The client program on " + ad[0] + ':' + str(ad[1]) + " has quited due to some reasons (user quit or KeyboardInterupt)." connect.close() return quit #====================================== if data not in Global.u_p: connect.send("Username not existing. This de-registration session will quit, and you will go to the main log in session.\nPlease enter your username: (or you can \"quit\" or \"resigter\" or \"de-resigter\" by those commands)\n>>") disp = "Someone on " + ad[0] + ':' + str(ad[1]) + " is trying to cancel a user \"" + data + "\" but that user doesn't exist." print disp Global.log.write(disp + "\n") return False else: UNBLOCK = True #------ check blocking status ---------- for i in Global.list_block: if ad[0] == i.ip and data == i.name: if i.get_bool(): connect.send("You are blocked! Please wait, this user has been blocked. You have " + str(i.get_leftover()) + " time left to try cancel this name on this machine again!\nPlease enter your username: (or you can \"quit\" or \"resigter\" or \"de-resigter\" by those commands)\n>>") disp = "The user \"" + data + "\" on the ip address of \"" + i.ip + "\" want to cancel himself, but was blocked. It has " + str(i.get_leftover()) + " time left to perform cancelling this name again!" print disp Global.log.write(disp + "\n") return False else: Global.list_block.remove(i) pwd_wrongnumber_rep[data] = 0 break #------ check logging status ---------- for i in Global.list_user: if data == i.name: connect.send("The present user is logging in right now. So you can't cancel it. This session will quit and you will turn to the main login session.\nPlease enter your username: (or you can \"quit\" or \"resigter\" or \"de-resigter\" by those commands)\n>>") disp = "The user \"" + data + "\" actually has logged in. But another one want to cancel this user name, which is not permitted. Its IP address and port are \"" + ad[0] + ':' + str(ad[1]) +"\"." print disp Global.log.write(disp + "\n") return False exist_user = data #------------------ check the password (bring the 3-times blocking process)---------------------- connect.sendall("Please enter your password:\n>>") #====================================== (data, quit) = check_input(connect, ad) if quit: print "The client program on " + ad[0] + ':' + str(ad[1]) + " has quited due to some reasons (user quit or KeyboardInterupt)." connect.close() return True #====================================== pwd = data.strip() pwd_real = Global.u_p[exist_user] # I will set the directory later on to form a repository #---------------------- password verification module -------------------------- if pwd != pwd_real: if exist_user in pwd_wrongnumber_rep: pwd_wrongnumber_rep[exist_user] += 1 else: pwd_wrongnumber_rep[exist_user] = 1 if pwd_wrongnumber_rep[exist_user] == 3: connect.sendall("Wrong password for 3 times for this user on this machine in this logging in session. You are blocked. Please try with this user after " + str(Global.BLOCK_TIME) + " seconds. Or you can try another user in this machine.\nPlease enter your username: (or you can \"quit\" or \"resigter\" or \"de-resigter\" by those commands)\n>>") disp = "Wrong pwd 3 times for user \"" + exist_user + "\" on " + ad[0] + ':' + str(ad[1]) print disp Global.log.write(disp + "\n") block = Global.block(ad[0], time.time(), exist_user) Global.list_block.append(block) return False else: connect.send('Wrong password for this user! You have ' + str(3-pwd_wrongnumber_rep[exist_user]) + ' times to give another try for this user on this machine in this connection session!\nPlease enter your username: (or you can \"quit\" or \"resigter\" or \"de-resigter\" by those commands)\n>>') disp = 'Wrong password for \"' + exist_user + '\" on ' + ad[0] + ':' + str(ad[1]) + '. There are ' + str(3-pwd_wrongnumber_rep[exist_user]) + ' times left to give another try for this user!' print disp Global.log.write(disp + "\n") return False exist_pwd = pwd #---------------- make sure to delete --------------- connect.sendall("Password verified. Are you sure to cancel your registration for " + exist_user + "? Enter \"yes\" or \"no\":\n>>") disp = 'User \"' + exist_user + '\" on ' + ad[0] + ':' + str(ad[1]) + ' has passed the PWD verification during the cancellation process. Now he is making sure that he will cancel this account!' print disp Global.log.write(disp + "\n") bol = True N = 0 while bol: N += 1 #====================================== (data, quit) = check_input(connect, ad) if quit: print "The client program on " + ad[0] + ':' + str(ad[1]) + " has quited due to some reasons (user quit or KeyboardInterupt)." connect.close() return True #====================================== if data not in ["yes", "no"]: if N == 2: connect.sendall("Sorry you did not enter \"yes\" or \"no\". This user de-registration session will quit, and you will turn to the main login session.\nPlease enter your username: (or you can \"quit\" or \"resigter\" or \"de-resigter\" by those commands)\n>>") return False else: connect.sendall("Please re-enter \"yes\" or \"no\". You can have another try.\n>>") else: bol = False if data == "yes": del Global.u_p[exist_user] Global.de_update(exist_user) connect.sendall("You have successfully cancelled \"" + exist_user + "\". Please continue!\nPlease enter your username: (or you can \"quit\" or \"resigter\" or \"de-register\" by those commands)\n>>") disp = "New user \"" + exist_user + "\" with password \"" + exist_pwd + "\" has been successfully cancelled on " + ad[0] + ':' + str(ad[1]) + "." print disp Global.log.write(disp + "\n") else: connect.sendall("You don't cancel \"" + exist_user + "\". Please continue!\nPlease enter your username: (or you can \"quit\" or \"resigter\" or \"de-register\" by those commands)\n>>") disp = "New user \"" + exist_user + "\" with password \"" + exist_pwd + "\" has not been successfully cancelled on " + ad[0] + ':' + str(ad[1]) + "." print disp Global.log.write(disp + "\n") return False