def emailAdded(): nonlocal test_id response = app.get('/update/email/confirm/' + test_code) assertResponse(response, 200, 'Ok') user = db.getUserById(test_id) assert_that(user.get('email'), equal_to(test_email)) assert_that(db.getCode(test_code), none())
def confirmCodeDeletedUser(): nonlocal test_id db.DB_CONN.execute('DELETE FROM Users WHERE id = ?', [test_id]) db.DB_CONN.commit() response = app.get('/update/email/confirm/' + test_code) assertResponse(response, 403, 'Forbidden') assert_that(db.getUserById(test_id), none())
def confirmUsedCode(): nonlocal test_id db.useCode(test_code) response = app.get('/update/email/confirm/' + test_code) assertResponse(response, 403, 'Forbidden') user = db.getUserById(test_id) assert_that(user.get('email', None), none())
def confirmEmail(code): global CODE_VALIDATOR if CODE_VALIDATOR.match(code) is None: return forbidden() code_info = db.getCode(code) if code_info is None: return forbidden() user = db.getUserById(code_info.get('user_id')) if user is None: return forbidden() user['email'] = code_info.get('email') db.updateUser(user) db.useCode(code_info.get('code')) return ok()
def register(tg_id, response): if not db.getUserById(tg_id): # if user is not registered, register them print('user not found') db.saveUser(tg_id=tg_id, first_name="", last_name="") db.getUserById(tg_id) db.saveControlBoard(tg_id, 0) # start a trace on control board table current_count = db.getCurrentCount(tg_id) # saving user details in database if current_count == 1: if response.lower() in ['no', '2']: db.deleteUser(tg_id) return 'Ok. Maybe later. You can continue registration by clicking /register .' if current_count == 2: if response.lower().strip() in ['male', '1']: db.saveGender(tg_id, 'male') elif response.lower().strip() == ['female', '2']: db.saveGender(tg_id, 'female') else: return 'Invalid gender. Try again' elif current_count == 3: try: age = int(response) if 0 < age < 120: db.saveAge(tg_id, age) else: return 'Invalid age' except ValueError: return 'Invalid age' elif current_count == 4: if not response: return 'Sorry, did you forget to write the name? Try again' else: db.saveFirstName(tg_id, response) elif current_count == 5: if not response: return 'Sorry, did you forget to write the name? Try again' else: db.saveLastName(tg_id, response) db.saveFinishedRegistration(tg_id) # if user has finished registration, stop asking registration questions, and control board trace if db.getFinishedRegistration(tg_id) is None: can_continue = True else: can_continue = False if current_count >= 6: pass else: db.saveControlBoard(tg_id, current_count + 1) # return registration question from database if user hasn't finished registering if can_continue: nextQ = db.getQuestion(current_count + 1) if 'our system' in nextQ: nextQ += '\n1 - Yes\n2 - No' elif '[male/female]' in nextQ: nextQ += '\n1 - Yes\n2 - No' return nextQ else: # go to diagnosis part if registration is complete if db.getOnGoingUser(tg_id) is None: # asking user to describe condition db.saveOnGoingUser(tg_id) return 'How are you feeling today? Describe your condition' else: INVALID_INITIAL_SYMPTOM = 'Please say that again, i couldn\'t get you. \nExplain how you feel. eg, ' \ '"i feel pain on my back" ' if response.lower() == '0': db.deleteUserOngoingDiagnosis(tg_id) db.deleteUserSymptoms(tg_id) db.deleteUserCurrentSymptom(tg_id) db.deleteCurrentQuestion(tg_id) return 'Diagnosis stoppped. You can start by typing *diagnose start*' elif response.lower() in ['yes', '1']: if db.getCurrentQuestion(tg_id) is None: return INVALID_INITIAL_SYMPTOM db.saveSymptom(tg_id, db.getCurrentQuestion(tg_id)[1], 'present') elif response.lower() in ['no', '2']: if db.getCurrentQuestion(tg_id) is None: return INVALID_INITIAL_SYMPTOM db.saveSymptom(tg_id, db.getCurrentQuestion(tg_id)[1], 'absent') elif 'dont know' in response.lower( ) or 'don\'t know' in response.lower() or response.lower() == '3': if db.getCurrentQuestion(tg_id) is None: return INVALID_INITIAL_SYMPTOM db.saveSymptom(tg_id, db.getCurrentQuestion(tg_id)[1], 'unknown') else: symptoms = sendParse(response) print(f'PARSE SYMPTOMS: {symptoms}') if len(symptoms) > 0 and 'understand' not in symptoms: for symptom in symptoms: s_id = symptom['id'] choice = symptom['choice_id'] db.saveInitialSymptom(tg_id, s_id, choice, 1) else: if db.getCurrentQuestion(tg_id): return f'Invalid answer\n\n{db.getCurrentQuestion(tg_id)[2]}\n1 - Yes\n2 - No\n3 - Dont know' \ f'\n\n0 - Cancel diagnosis and restart ' else: return 'Describe how you feel. Example, I feel pain in my joints ' symptoms = db.getSymptoms(tg_id) # print(f'API HANDLER symptoms: {symptoms}') age = db.getAge(tg_id) # print(f'API HANDLER age: {age}') sex = db.getGender(tg_id) sex = sex.lower() # print(f'API HANDLER sex: {sex}') response = make_chuka_api_request(age, sex, symptoms) # print(f'API HANDLER response: {response}') response = loads(response) if 'next_question' in response: nextQuestionId = response["next_question"]["items"][0]["id"] db.updateCurrentQuestion(tg_id, nextQuestionId, response["next_question"]["text"]) return f'{response["next_question"]["text"]}\n1 - Yes\n2 - No\n3 - Dont know\n\n_0 - Cancel diagnosis_' \ f'and restart_ ' elif 'stop' in response: conditions = response['conditions'] message = "After Diagnosis, the following conditions were discovered:\n\n" for condition in conditions: name = condition['name'] prob = float(condition['probability']) * 100 prob = round(prob, 2) prob = f'{prob} %' message += f'Name\t: {name}\nProbability: {prob}\n\n' return message else: return 'Could not get any response. Press /diagnose to restart.'