def notification_callback(bot, job): payload = job.context # passed here via run_once(.. context=...) if payload: # chat id can be not int. e.g. '@username' is chat_id too chat_id, task_id = map(payload.get, (PAYLOAD_CHAT_ID, PAYLOAD_TASK_ID)) chat_id = int(chat_id) task = task_service.find_task_by_id_and_user_id(task_id, chat_id) if task.is_task_enabled() is False or task.is_task_completed(): log.info( f'Notification for task {task_id} in chat ({chat_id}) is disabled. Skipping' ) return lang = g.automata.get_context(chat_id)[CONTEXT_LANG] user = user_service.find_user_by_id(chat_id) reminder = message_source[lang]['state.edit_date.reminder'].format( task.get_description(), readable_datetime(task.get_create_date())) reply_text = concat_username(emoji_mortal_reminder + '*', user, ', ' + reminder) markup = kb.ViewTaskKb(task_id, lang).build() bot.send_message(chat_id=chat_id, text=emojize(reply_text, use_aliases=True), parse_mode=ParseMode.MARKDOWN, reply_markup=markup) else: log.error('No payload found in notification callback')
def index(): user_id = cookie_auth.get_user_id_via_auth_cookie(flask.request) if user_id is None: return flask.redirect('/account/login') user = user_service.find_user_by_id(user_id) if not user: return flask.redirect('/account/login') return { 'user': user, 'user_id': cookie_auth.get_user_id_via_auth_cookie(flask.request), }
def __init__(self): super().__init__() self.user = user_service.find_user_by_id(self.user_id) self.email = self.request_dict.email.lower().strip() self.doc_packages = section_service.get_all_sections() # return {'documents': doc_packages} # self.name = self.request_dict.name # self.email = self.request_dict.email.lower().strip() # self.password = self.request_dict.password.strip() # self.age = self.request_dict.age.strip() self.sec_name = self.request_dict.sec_name.strip() self.sec_id = self.request_dict.sec_id.strip() t = 1
def account(): user_id = cookie_auth.get_user_id_via_cookie(flask.request) # If an attacker tries to change the cookie validation they will not be allowed to login if user_id is None: return flask.redirect('/accounts/login') user = user_service.find_user_by_id(user_id) # If not the correct user return back to login if not user: return flask.redirect('/accounts/login') if flask.request.method == "POST": # Requesting of data from the forms vm = accountIndexViewModel() file = request.files['image-file'] # read the image in binary bytedata = file.read() # save the image current_image = f'images/{user.id}_image.png' with open("templates/static/" + current_image, 'wb') as f: f.write(bytedata) if file and allowed_file(file.filename): filename = secure_filename(file.filename) file.save(os.path.join(app.config['UPLOAD_FOLDER'], filename)) # If the user does not wish to update their password they may have the option of leaving blank, # doing so will allow the user to keep they previous password if vm.password == "": user_service.update_information_wop(user.email, vm.email, vm.name, current_image) return flask.redirect('/accounts') else: user_service.update_information_wp(user.email, vm.email, vm.name, vm.password, current_image) return flask.redirect('/accounts') return { 'user': user, "user_id": cookie_auth.get_user_id_via_cookie(flask.request), }
def __init__(self): super().__init__() self.user = user_service.find_user_by_id(self.user_id) t = 1
def load_user(user_id): uid = user_service.find_user_by_id(user_id) return uid
def __init__(self): super().__init__() self.user = user_service.find_user_by_id(self.user_id) self.name = self.request_dict.name.strip() self.email = self.request_dict.email.lower().strip() self.password = self.request_dict.password.strip()