Exemplo n.º 1
0
def get_if_admin_role(username):
    user = get_user_by_username(json.loads(request.values['username']))

    response = app.response_class(
        response=json.dumps(True if len(user.roles) > 0 else False),
        status=200,
        mimetype="application/json"
    )
    return response
Exemplo n.º 2
0
def delete_role(username):
    user = get_user_by_username(json.loads(request.values['username']))
    delete_admin_role_from_user(user)
    resp = f"removed role"
    response = app.response_class(
        response=json.dumps(resp),
        status=200,
        mimetype="application/json"
    )
    return response
Exemplo n.º 3
0
def post_message(username):
    chat = get_chat_by_id(request.values['chat'])
    message = Message(sent_by=get_user_by_username(request.values['sent_by']), text=request.values['message'])
    add_message_to_chat(chat, message)
    response = app.response_class(
        response=json.dumps("sent"),
        status=200,
        mimetype="application/json"
    )
    return response
Exemplo n.º 4
0
def get_chat(username):
    friend = get_user_by_username(request.values['friend'])
    chat = get_chat_between_users(current_user, friend)
    print(chat.members)
    response = app.response_class(
        response=json.dumps(chat.to_json()),
        status=200,
        mimetype="application/json"
    )
    return response
Exemplo n.º 5
0
def add_role(username):
    user = get_user_by_username(json.loads(request.values['username']))
    admin_role = get_role_by_name("admin")
    add_role_to_user(user=user, role=admin_role)
    resp = f"added role"
    response = app.response_class(
        response=json.dumps(resp),
        status=200,
        mimetype="application/json"
    )
    return response
Exemplo n.º 6
0
def post_friendship(username):
    found_friend = get_user_by_username(request.values['username'])
    logged_in_user = get_user_by_username(current_user.username)

    if found_friend:
        if found_friend in logged_in_user.friends:
            resp = f"you are already friend with {found_friend.username}"
        else:
            add_friendship(user=logged_in_user, friend=found_friend)
            resp = f"You are now friends with {found_friend.username}"
            initiate_chat(user_1=logged_in_user, user_2=found_friend)
    else:
        resp = f"Found no user with username {request.values['username']}"

    response = app.response_class(
        response=json.dumps(resp),
        status=200,
        mimetype="application/json"
    )

    return response
Exemplo n.º 7
0
def sign_up():
    form = RegisterForm()
    errors = []
    if request.method == "POST":

        if get_user_by_email(form.email.data):
            errors.append("Email is already in use")

        if get_user_by_username(form.username.data):
            errors.append("Username is already taken")

        if form.validate_on_submit() and len(errors) == 0:
            create_user(first_name=form.first_name.data,
                        last_name=form.last_name.data,
                        email=form.email.data,
                        password=form.password.data,
                        username=form.username.data)
            return redirect(url_for('index.sign_in'))

    return render_template('signup.html', register_form=form, errors=errors)
Exemplo n.º 8
0
def remove_user(username):
    user = get_user_by_username(username)
    ru(user)
    remove_user_chats(user)
    return redirect(url_for('index._index'))
Exemplo n.º 9
0
def user(username):
    return render_template('user.html', user=get_user_by_username(username))
Exemplo n.º 10
0
def friend(username):
    return render_template("friend.html",
                           user=current_user,
                           friend=get_user_by_username(username))