Example #1
0
def show_groups():
    try:
        # Check if we are logged in this session.
        if not session['logged_in']:
            abort(401)

        group_list = database.get_groups()
        group_member_lists = dict()  # Create a dictionary with (key, value) being (group_name, members)
        for group in group_list:
            # For each group: add a list of its members
            group_member_lists[group['name']] = database.get_group_members(group['name'])
        return render_template('show_groups.html', groups=group_list, member_lists=group_member_lists)

    except KeyError:
        # Visualize for the user that something went wrong.
        flash('You need to be logged in to view that page')
        return redirect(url_for('home'))
Example #2
0
def client_server(request):
    body = json.loads(request.body)
    res = {}
    if body['type'] == 'login':
        if (body['username'] == 'admin') and (body['password'] == 'admin'):
            res['correct'] = True
            res['val'] = database.get_groups()
            with open('myBotVK/templates/admin.html', 'r') as file:
                res['html'] = file.read()
        else:
            res['correct'] = False
        #print(res)
        return HttpResponse(json.dumps(res))
    elif body["type"] == 'postNewMessage':
        users_chat_id = database.get_member(body["group"])
        for i in users_chat_id:
            vk_api.messages.send(user_id=i,
                                 message=body['content'],
                                 random_id=random.randint(
                                     1, 50000000000000000000000),
                                 v=5.103)
        return HttpResponse(json.dumps({"res": "ok"}))
Example #3
0
def client_server(request):
    body = json.loads(request.body)
    res = {}
    if body["type"] == "login":
        if (body["username"] == "admin") and (body["password"] == "admin"):
            res["correct"] = True
            res["val"] = database.get_groups()
            with open('Weapon/templates/Admin.html', 'r') as file:
                res["html"] = file.read()
        else:
            res["correct"] = False
            print(res)
        return HttpResponse(json.dumps(res))
    elif body["type"] == "postNewMessage":
        users_chat_id = database.get_member(body["group"])
        # print("Check dV")
        for i in users_chat_id:
            vk_api.messages.send(user_id=i,
                                 message=body['content'],
                                 random_id=random.randint(
                                     1, 50000000000000000000000000),
                                 v=5.103)
        return HttpResponse(json.dumps({"res": "ok"}))
Example #4
0
def handle_groups():
    groups = jsonify({'groups': database.get_groups()})
    return groups, 200