def db_info(self, state, step, user_id, text): """ Манипуляция с базой данных :param state: Текущее контекст (хранит последнее действие от пользователя) :param step: текущий шаг :param user_id: id пользователя :param text: текст от пользователя :return: False, если в сценарии 'registration' найдено совпадения по зарегистрированному email; continue - в сценарии 'coffee' найден пользователь; True - нет подходящего сценария """ if state.scenario_name == 'registration': for i in Registration.select(): if text == i.email: text_to_send = step['failure_text2'].format(**state.context) self.send_text(text_to_send, user_id) return False elif state.scenario_name == 'coffee': res = BonusCardCoffee.select(lambda x: x.count < 10 and x.email_card == text) if res: for user in res: user.count += 1 self.send_text('Да, сегодня ещё есть бесплатный кофе', user_id) return 'continue' else: self.send_text(step['failure_text'], user_id) else: return True
def get_section_roster(self): section_id = self.get_payload()['section_id'] query = (Registration.select( Student.first_name, Student.last_name, Student.id, Registration.letter_grade, Registration.percent_grade).join(Student).where( Registration.section_id == section_id).dicts()) return query
def get_student_terms(self): student_id = self.get_payload()['id'] query = (Registration.select(Term.title, Term.id).distinct().join( Section, on=(Registration.section_id == Section.id)).join( Term, on=(Section.term_id == Term.id)).where( Registration.student_id == student_id).dicts()) return query
def post(self): email = request.args['email'] # Gets or creates a new entry for a hacker hacker, created = Hacker.get_or_create( id=request.args['id'], username=request.args['username'], discriminator=request.args['discriminator']) # If the account exists and is verified return an error if not created and hacker.verified: abort(409, message="Hacker already verified") # Get all registration entries under that email entries = Registration.select().where( fn.Lower(Registration.email) == email.lower()).order_by( Registration.submit_time) if entries.exists(): if entries[0].hacker_discord != None and entries[ 0].hacker_discord != hacker: abort(409, message= "Registration verification started with another hacker") # Start hacker verification hacker.verification = secrets.token_hex(8) hacker.verification_expiration = datetime.datetime.now( ) + datetime.timedelta(hours=1) hacker.save() query = Registration.update(hacker_discord=hacker).where( Registration.email == email) # Email hacker! response = mail.send_verification_email(entries[0], hacker.verification) if response: query.execute() res = jsonify({"status": "Email sent!", "code": 0}) res.status_code = 201 return res else: abort(501, message="Unable to send email") else: abort(404, message="Unable to find registration")
def post(self): if typeform.authorize(request.headers["typeform-signature"], request.data): event = request.json vals = typeform.parse_responses(event) try: reg = Registration.create(**vals) entries = Registration.select().where( Registration.email == reg.email).order_by( Registration.submit_time) if entries.exists(): reg.hacker_discord = entries[0].hacker_discord reg.save() except: traceback.print_exc() abort(409, message="Registration not recorded") r = sendy.add_to_mailing_list(reg) if r.status_code == 200: res = jsonify({"status": "Registration recorded"}) res.status_code = 201 return res else: abort(501, message="Registered but unable to send email") abort(401, message="Unauthorized")