def post(self, request): error = self.validate(**request.data) if request.data.get('password') != request.data.get('password2'): error = 'Пароли не совпадают' if error: return Response({'error': error}) Account.create(**request.data) return Response({})
def post(self, request): account = Account.objects.filter( telegram_chat_id=request.data['id']).first() if not account: data = { 'first_name': request.data.get('first_name'), 'last_name': request.data.get('last_name'), 'telegram_chat_id': int(request.data.get('id')) } account = Account.create(**data) return self.response(account)
def post(self, request): account = Account.objects.filter( facebook_account__id=request.data['id']).first() if not account and request.data.get('email'): account = Account.objects.filter( email_confirm=request.data['email']).first() if account: account.update(facebook_account=request.data) if not account: data = { 'first_name': request.data.get('first_name'), 'last_name': request.data.get('last_name'), 'email_confirm': request.data.get('email') } account = Account.create(**data).update( facebook_account=request.data) return self.response(account)
def configure_api(): import atexit from apscheduler.schedulers.background import BackgroundScheduler scheduler = BackgroundScheduler() scheduler.add_job(func=Account.subtract_all_holds, trigger="interval", minutes=10) scheduler.start() atexit.register(lambda: scheduler.shutdown()) db.drop_all() db.create_all() Account.create(account_id='26c940a1-7228-4ea2-a3bc-e6460b172040', name='Петров Иван Сергеевич', current_balance=1700, holds=300, status=True) Account.create(account_id='7badc8f8-65bc-449a-8cde-855234ac63e1', name='Kazitsky Jason', current_balance=200, holds=200, status=True) Account.create(account_id='5597cc3d-c948-48a0-b711-393edf20d9c0', name='ПархоменкоАнтонАлександрович', current_balance=10, holds=300, status=True) Account.create(account_id='867f0924-a917-4711-939b-90b179a96392', name='Петечкин Петр Измаилович', current_balance=1000000, holds=1, status=False)
def handle(self, *args, **options): from api.models import UserProfile profile = UserProfile.get(options.get('user')) if not profile: from api.models import Account try: n = int(options.get('number')) except: n = 1 for i in range(n): account = Account.create(password='******') account.update(email_confirm=f'{account.username}@dayspick.ru') account.user.is_staff = True account.user.save() profile = account.profile random_name(profile) random_tags(profile) print(f'\nСоздан пользователь {profile.full_name}') create_random_projects(profile) else: create_random_projects(profile)
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)