def delete_account(clean_data: dict) -> dict: """ { 'request URL': '/user/delete-account', 'methods': 'POST', 'Query Params': { 'input': { 'auth_token': { 'nullable': False, 'type': 'string' }, }, }, 'Response': { "code": '', "information": { 'output': {} } }, "message": "", "status": "" } """ repo = UserRepository() tkns = repo.delete(clean_data) for tkn in tkns: redis_client.delete(tkn.token) ret = dict() ret['data'] = dict() ret['code'] = DELETE_ACCOUNT_CODE ret['message'] = DELETE_ACCOUNT_MESSAGE ret['status'] = OK_STATUS return ret
def logout(clean_data: dict) -> dict: """ { 'request URL': '/logout', 'methods': 'POST', 'Query Params': { 'input': { 'auth_token': { 'nullable': False, 'type': 'string' }, }, }, 'Response': { "code": '', "information": { 'output': {} } }, "message": "", "status": "" } """ repo = UserRepository() tkn = repo.logout(clean_data) redis_client.delete(tkn) ret = { 'data': {}, 'code': LOGOUT_CODE, 'message': LOGOUT_MESSAGE, 'status': OK_STATUS } return ret
def delete_redis_cache_keys(cache_prefix, category=''): if not redis_client: return key = make_redis_cache_key(cache_prefix, category) keys_list = redis_client.keys(key) for key in keys_list: redis_client.delete(key)
def delete_redis_cache_keys(cache_prefix, category=''): """Delete a specific cache key.""" if not redis_client: return key = make_redis_cache_key(cache_prefix, category) keys_list = redis_client.keys(key) for key in keys_list: redis_client.delete(key)
def delete_contact(id): _hashed_id = hash_md5(id) if redis_client.get(_hashed_id): redis_client.delete(_hashed_id) if not mongo.contacts.find_one({'_id': ObjectId(id)}): return error_response(f'No Contact with Id: `{id}`!', 400) mongo.contacts.delete_one({'_id': ObjectId(id)}) return success_response('Contact successfully deleted!')
def delete_redis_cache_post(uuid, user_id=None, all_users=False): if all_users: cache_key = make_template_fragment_key('post', vary_on=[uuid]) else: if user_id: user_id = str(user_id) else: if current_user.is_authenticated(): user_id = current_user.string_id else: user_id = "ANONYMOUS" cache_key = make_template_fragment_key('post', vary_on=[uuid, user_id]) # Add prefix to the cache key if not redis_client: return key = '{0}{1}*'.format(app.config['CACHE_KEY_PREFIX'], cache_key) keys_list = redis_client.keys(key) for key in keys_list: redis_client.delete(key)
def delete_redis_cache_template(template_item, uuid, user_id=None, all_users=True): """Delete a redis cached template fragment. Supports various options for filtering the right keys. :type template_item: string :param template_item: Prefix for the template, e.g. 'node_view' :type uuid: string :param uuid: The unique identifier for the item displayed in the template. Usually the string version of the Node ObjectID. :type user_id: string :param user_id: User ID cache, use for filtering per-user caches (useful to display cached rating pages) """ if all_users: cache_key = make_template_fragment_key(template_item, vary_on=[uuid]) else: if user_id: user_id = str(user_id) else: if current_user.is_authenticated(): user_id = current_user.string_id else: user_id = "ANONYMOUS" cache_key = make_template_fragment_key(template_item, vary_on=[uuid, user_id]) # Add prefix to the cache key if not redis_client: return key = '{0}{1}*'.format(app.config['CACHE_KEY_PREFIX'], cache_key) keys_list = redis_client.keys(key) for key in keys_list: redis_client.delete(key)
def delete_session(clean_data: dict) -> dict: """ { 'request URL': '/user/delete-session', 'methods': 'POST', 'Query Params': { 'input': { 'auth_token': { 'nullable': False, 'type': 'string' }, 'session': { 'nullable': False, 'type': 'string' } }, }, 'Response': { "code": '', "information": { 'output': {} } }, "message": "", "status": "" } """ repo = UserRepository() repo.delete_session(clean_data) redis_client.delete(clean_data['session']) ret = dict() ret['data'] = {} ret['code'] = DEL_SESSION_CODE ret['message'] = DEL_SESSION_MESSAGE ret['status'] = OK_STATUS return ret
def update_password(clean_data: dict) -> dict: """ { 'request URL': '/user/update/password', 'methods': 'POST', 'Query Params': { 'input': { 'auth_token': { 'nullable': False, 'type': 'string' }, 'password': { 'nullable': False, 'max_length': 128, 'min_length': 8, 'type': 'string' }, }, }, 'Response': { "code": '', "information": { 'output': { 'auth_token': { 'nullable': False, 'type': 'string' }, 'role': { 'nullable': False, 'type': 'string' }, 'real_or_legal': { 'nullable': False, 'type': 'string' }, 'phone_number': { 'nullable': False, 'type': 'numerical string' }, 'email': { 'nullable': True, 'type': 'email' }, 'user_information': { 'nullable': True, 'type': 'json' }, 'company_information': { 'nullable': True, 'type': 'string' }, 'configurations': { 'nullable': True, 'type': 'json' }, } } }, "message": "", "status": "" } """ repo = UserRepository() tkns, user_name = repo.update(clean_data, 'update_password') for tkn in tkns: redis_client.delete(tkn.token) rkey, rval, ret = repo.login({ 'user_name': user_name, 'password': clean_data['password'], 'device_information': clean_data['auth_token_info_extract']['device_information'] }) redis_client.set(rkey, rval) ret['code'] = UPDATE_PASSWORD_CODE ret['message'] = UPDATE_PASSWORD_MESSAGE ret['status'] = OK_STATUS return ret
def delete_token(token: bytes): logger.info('Delete token: "{}"'.format(token)) redis_client.delete(token)