def any_msg(message):
    user = User(telegram_id=message.chat.id, username=message.chat.username)
    if user.not_in_base():
        send_welcome(message)
    else:
        user = get_user(message.chat.id)
        if "@" in message.text:
            user.add_email(message.text)
            bot.send_message(chat_id=user.user_id,
                             text=content.service_msg['email'] + message.text)
        elif "+7" in message.text or message.text.isdigit():
            user.add_phone_number(message.text)
            bot.send_message(chat_id=user.user_id,
                             text=content.service_msg['number'] + message.text)
        else:
            user.add_name(message.text)
            bot.send_message(chat_id=user.user_id,
                             text=content.service_msg['name'] + message.text)
        user.rewrite_user_info()
def callback_inline(call):
    user = get_user(telegram_id_need_to_be_found=call.message.chat.id)
    sex, answer = call.data.split('_')
    print(call.data, '----------------------------------------')
    if call.data == "start_test":
        keyboard_main = keyboard_maker(2, ["Мужчина", "Женщина"],
                                       ["man_q1aM", "woman_q1aW"],
                                       without_back_btn=True)
        bot.edit_message_text(chat_id=call.message.chat.id,
                              message_id=call.message.message_id,
                              text="Выберите ваш пол:",
                              reply_markup=keyboard_main)

    elif "result_" in call.data:
        user.update_answer(answer)
        user.rewrite_user_info()
        bot.send_message(call.message.chat.id,
                         text=content.service_msg['result'],
                         reply_markup=GET_RESULT_BUTTON)

    elif 'get_result' == call.data:
        if not user.form_filled():
            bot.send_message(chat_id=user.user_id,
                             text=content.service_msg['result'])
        if user.form_filled():
            message = user.get_result_from_answers()
            bot.send_message(chat_id=user.user_id, text=message)
            bot.send_message(chat_id=user.user_id,
                             text=content.service_msg['contacts'])
            if user.not_in_forms():
                user.add_user_in_forms()
                send_forms(user)

    else:
        journalist(call)
        user.add_sex(sex)
        user.update_answer(answer)
        user.rewrite_user_info()
        if user is None:
            print("Can't find that user")
Exemple #3
0
def edit_user(email):
    if not request.is_json:
        return jsonify({"status": "Missing JSON in request."}), 400

    user_obj = get_user(email).get("user", None)
    if not user:
        return jsonify({"status": "User not found."}), 404

    if 'email' in request.json and 'password' in request.json:
        return jsonify(
            update_user(user_obj['id'],
                        email=request.json['email'],
                        password=request.json['password'])), 200
    elif 'email' in request.json:
        return jsonify(update_user(user_obj['id'],
                                   email=request.json['email'])), 200
    elif 'password' in request.json:
        return jsonify(
            update_user(user_obj['id'],
                        password=request.json['password'])), 200
    else:
        return jsonify({'status': "no changes"}), 200
Exemple #4
0
def remove_user(email):
    user_obj = get_user(email).get("user", None)
    if user_obj:
        return jsonify(delete_user(user_obj['id'])), 200
    else:
        return jsonify({"status": "user doesn't exist"}), 404
Exemple #5
0
def user(email):
    return jsonify(get_user(email)), 200