def auth_passwordreset_reset(reset_code, new_password): """ Reset password given a reset code. """ # Try decrypting jwt string try: decrypted_dict = jwt.decode(reset_code, RESET_PASSWORD_KEY, algorithms=['HS256']) except Exception: raise InputError email = decrypted_dict['email'] # Check if password and email is valid if not validate_password(new_password) or not check_email_in_database( email): raise InputError # Reset the password database = DataBase() u_id = 0 users = database.database_dict['users'] for user in users: if user['email'] == email: break u_id += 1 target_user = database.database_dict['users'][u_id] target_user['password'] = new_password database.close() return {}
def test_channel_leave_remote(url, channel_init): ''' test_channel_leave_remote ''' requests.post(f'{url}channel/leave', json={ 'token': channel_init[1]['token'], 'channel_id': channel_init[2] }) database = DataBase() assert channel_init[1]['u_id'] not in database.get_channel_info( channel_init[2])['members_id']
def test_channel_removeowner_remote(url, channel_init): ''' test_channel_removeowner_remote ''' requests.post(f'{url}channel/removeowner', json={ 'token': channel_init[0]['token'], 'channel_id': channel_init[2], 'u_id': channel_init[0]['u_id'] }) database = DataBase() assert channel_init[0]['u_id'] not in database.get_channel_info( channel_init[2])['owners_id']
def test_channel_join_remote(url, channel_init): ''' test_channel_join_remote ''' test_channel_public_id = channels_create(channel_init[0]['token'], f"test_public{UNIQUE_ID}", True) requests.post(f'{url}channel/join', json={ 'token': channel_init[1]['token'], 'channel_id': test_channel_public_id['channel_id'] }) database = DataBase() assert channel_init[1]['u_id'] in database.get_channel_info( test_channel_public_id['channel_id'])['members_id']
def auth_logout(token): """ Logs user out of flockr (active to not active user). """ database = DataBase() token = database.token_decryptor(token) # Get active users list active_users = database.database_dict['active_users'] # Get active_users index from token active_user_index = re.search("_[0-9]*$", token).group(0) active_user_index = int(re.sub("_", "", active_user_index)) # Remove active user active_users.pop(active_user_index) database.database_dict['no_active_users'] -= 1 database.close() return {'is_success': True}
def test_channel_details_remote(channel_init, url): ''' test_channel_details_remote ''' query_string = urllib.parse.urlencode({ 'token': channel_init[0]['token'], 'channel_id': channel_init[2] }) #print(f'{url}channel/details?{query_string}') print(f'{url}channel/details?{query_string}') response = requests.get(f'{url}channel/details?{query_string}') print(response.text) payload = response.json() database = DataBase() assert database.get_channel_info( channel_init[2])['name'] == payload['name']