예제 #1
0
 def get(self, request):
     account = Account.get(request.GET.get('user'))
     if account and account.confirm_email(request.GET.get('code')):
         return Response({
             'account': AccountSerializer(account).data,
             'token': account.token(),
             'message': 'Email подтверждён'
         })
     return Response({'error': 'Неверная ссылка'})
예제 #2
0
def validation_username(text):
    from api.models import Account
    if isinstance(text, Account):
        return text
    result = re.match(r'^[a-zA-Z][a-zA-Z0-9_]*$', text)
    if result:
        username = result.group(0).lower()
        account = Account.get(username)
        return account
    return None
예제 #3
0
 def get(self, request):
     account = Account.get(request.GET.get('user'))
     code = request.GET.get('code')
     token = account.token()[6:]
     if not account or not code or code != token:
         return Response({'error': 'Неверная ссылка'})
     return Response({
         'account':
         AccountSerializer(account).data,
         'token':
         account.token(new=True),
         'message':
         'Доступ восстановлен. Рекомендуем установить новый пароль'
     })
예제 #4
0
 def confirmation_answer(message, account, sign_up=False):
     if message.contact:
         if not message.contact.phone_number:
             TelegramBot.error(message)
         phone_number = message.contact.phone_number
         chat_id = message.chat.id
         if not account:
             if not sign_up:
                 TelegramBot.error(message)
             else:
                 data = {
                     'first_name': message.contact.first_name,
                     'last_name': message.contact.last_name,
                     'phone_confirm': phone_number,
                     'telegram_chat_id': chat_id
                 }
                 from api.models import Account
                 account = Account.get(message.from_user.username)
                 if not account:
                     data['username'] = message.from_user.username
                 account = Account.create(**data)
                 if account:
                     button = types.InlineKeyboardButton(
                         'Перейти на сайт', SITE)
                     keyboard = types.InlineKeyboardMarkup().add(button)
                     bot.send_message(message.chat.id,
                                      f'Аккаунт успешно создан',
                                      reply_markup=keyboard)
                 else:
                     TelegramBot.error(message)
         else:
             keyboard = types.ReplyKeyboardRemove()
             if account.phone != phone_number and account.phone_confirm != phone_number:
                 keyboard = types.ReplyKeyboardRemove()
                 bot.send_message(message.chat.id,
                                  f'Ошибка',
                                  reply_markup=keyboard)
                 button = types.InlineKeyboardButton(
                     'Перейти на сайт', SITE)
                 keyboard = types.InlineKeyboardMarkup().add(button)
                 bot.send_message(
                     message.chat.id,
                     f'Сначала измени телефон в настройках аккаунта на сайте',
                     reply_markup=keyboard)
                 return
             if account.phone == phone_number:
                 account = account.update(phone_confirm=phone_number,
                                          phone=None,
                                          telegram_chat_id=chat_id)
                 from api.models import Account
                 if not isinstance(account, Account):
                     TelegramBot.error(message, 'Ошибка 122')
                 bot.send_message(message.chat.id,
                                  f'Номер подтвержден',
                                  reply_markup=keyboard)
             elif account.phone_confirm == phone_number:
                 bot.send_message(message.chat.id,
                                  f'Номер уже подтвержден',
                                  reply_markup=keyboard)
             button = types.InlineKeyboardButton('Перейти на сайт', SITE)
             keyboard = types.InlineKeyboardMarkup().add(button)
             bot.send_message(message.chat.id,
                              f'Можешь перейти на сайт',
                              reply_markup=keyboard)
     elif message.text == 'Отмена':
         keyboard = types.ReplyKeyboardRemove()
         bot.send_message(message.chat.id,
                          f'Ну, в другой раз',
                          reply_markup=keyboard)
     else:
         keyboard = types.ReplyKeyboardRemove()
         bot.send_message(message.chat.id,
                          f'Не понимаю тебя',
                          reply_markup=keyboard)
         keyboard = types.ReplyKeyboardMarkup(one_time_keyboard=True,
                                              resize_keyboard=True)
         send = types.KeyboardButton(text="Отправить номер телефона",
                                     request_contact=True)
         cancel = types.KeyboardButton(text="Отмена")
         keyboard.add(send)
         keyboard.add(cancel)
         next_message = bot.send_message(
             message.chat.id,
             f'Выбери одну из команд дополнительной клавиаутры',
             reply_markup=keyboard)
         bot.register_next_step_handler(next_message,
                                        Phone.confirmation_answer, account)
예제 #5
0
 def search(self, request, data):
     account = Account.get(request.user)
     profiles = account.favorites.all()
     return Response(self.get_paginator(profiles, data))