def post(self): chan_id = self.get_cookie("private_chan_id") user = model.get_user_by_channel_id(chan_id) phone = get_valid_phone_number(self.get_argument("phone", "")) #state: only accept new number in specific state if user.get_state() not in [model.States.WAIT_FOR_PHONE_NUMBER, model.States.WAIT_FOR_CALL]: logging.warn("SaveNumber State User: %s Phone: %s" % (chan_id, phone)) self.write({"result":"Only saves when call not in progress"}) return #error case: invalid phone number if not phone: logging.warn("SaveNumber Wrong # User: %s Phone: %s" % (chan_id, phone)) self.write({"result":"Invalid phone number"}) return #TODO: In the multi process scenario this breaks down. A real DB will #need to enforce uniqueness of the phone number per user #otherwise multi proc will have issues. Ignoring this issue for now. #Sample Issue: #1. User A and User B both enter a number P for the first time #then both could end up getting into the DB with same phone number #because both get past the check for duplicates then both are added. #check for duplicate phone numbers and remove them. #this really should never be more than one that needs to be removed #as each save number should remove the previous dupes. #remove all users with this phone number that don't have the same #private_channel_id #The main reason behind this is if a person uses a different computer #but specifies the same phone number we still want it to work and #not get get stuck with the old user getting the messages for u in model.get_all_users_with_caller_id(phone): #without this check they could remove themselves if they saved twice if u.channel_id != chan_id: model.remove_user(u) user.caller_id = phone logging.info("SaveNumber Success User: %s Phone: %s" % (chan_id, phone)) self.write({"result":"success"})
def del_user(): del_user= request.form['del_name'] db = model.connect_db() # Assume that all tasks are attached to user 1. user_id = model.remove_user(db, int(del_user)) return redirect("/new_task")
def del_user(): del_user= request.form['del_name'] # Assume that all tasks are attached to user 1. user_id = model.remove_user(g.db, int(del_user)) return redirect("/tasks")