Exemplo n.º 1
0
def get_predictions():
    form_data = request.get_json()
    user_repository = UserRepository()
    predictions = user_repository.get_predictions(form_data['email'])

    if predictions:
        print(predictions)
        return_data = json.dumps(predictions)
        print(return_data)
        return return_data, status.HTTP_200_OK
    else:
        return {
            "message": "Error. No predictions made"
        }, status.HTTP_204_NO_CONTENT
Exemplo n.º 2
0
def login():
    form_data = request.get_json()
    user_repository = UserRepository()
    account = user_repository.login(form_data['email'], form_data['password'])
    if account:
        content = {
            'user_email': form_data['email'],
            'user_first_name': account[1]
        }
        return content, status.HTTP_200_OK
    else:
        return {
            "message": "Invalid login details. Please try again."
        }, status.HTTP_401_UNAUTHORIZED
Exemplo n.º 3
0
def register_user():
    form_data = request.get_json()
    user_repository = UserRepository()
    success = user_repository.register(form_data['firstName'],
                                       form_data['lastName'],
                                       form_data['email'],
                                       form_data['password'])
    if success:
        return {
            "message": "Successfully registered the user."
        }, status.HTTP_201_CREATED
    else:
        return {
            "message": "Failed registering the user with the supplied details."
        }, status.HTTP_400_BAD_REQUEST
Exemplo n.º 4
0
    def get_user_schedule(self, user_id: int) -> DefaultResponse:
        """
        gets schedule by user id
        :param user_id: user id in Telegram
        :return: DefaultResponse object
        """
        user_repository = UserRepository(self.session)
        user = user_repository.get_user_by_id(user_id)

        current_week = get_current_week().week

        response = self.get_schedule(user.group_id, current_week)
        self.session.close()

        return response
Exemplo n.º 5
0
    def set_group(self, group_id: int, user_id: int) -> DefaultResponse:
        """
        Sets user group.
        :param group_id: group id in university site
        :param user_id: user id in Telegram
        :return: DefaultResponse object
        """
        session = self.session
        user_repository = UserRepository(session)
        user = user_repository.get_user_by_id(user_id)
        user_repository.set_group(user.id, group_id)
        session.commit()

        response = DefaultResponse()
        group_repository = GroupRepository(session)
        response.text = group_repository.get_group_by_id(group_id).name
        session.close()

        return response
Exemplo n.º 6
0
def send_schedule_inline(update: Update, context: CallbackContext):
    session = Session()
    user_repository = UserRepository(session)
    user = user_repository.get_user_by_id(update.inline_query.from_user.id)

    if not user.group_id:
        schedule_not_found_message = InlineQueryResultArticle(
            id="3",
            title="Нажми на меня",
            input_message_content=InputTextMessageContent(
                message_text="У вас не указана группа. Перейдите в @schedule_unecon_bot и установите свою группу",
                parse_mode="HTML"
            )
        )

        update.inline_query.answer([schedule_not_found_message])
    else:
        inline_response_creator = ScheduleCreator(group_id=user.group_id)
        inline_response = inline_response_creator.form_inline_response()
        if inline_response.is_valid():
            update.inline_query.answer(inline_response.items)
 def test_get_predictions(self, db_connection):
     result = UserRepository().get_predictions('*****@*****.**')
     print(result)
     self.assertEqual([[4, 3, 'Christian Snail', [('James', )], [(1, )]]],
                      result)
Exemplo n.º 8
0
def check_duplicate_email():
    form_data = request.get_json()
    user_repository = UserRepository()
    return {
        "result": user_repository.check_email(form_data['email'])
    }, status.HTTP_200_OK