def create_new_board():
    if security.check_text_validity(request.form['title'],
                                    extra_characters=" '"):
        return json.dumps(
            data_manager.create_new_board(request.form,
                                          session.get('user_id', -1)))
    return json.dumps({'error': 'incorrect name'})
def board_rename():
    board = data_manager.get_board_by_id(request.form['board_id'])
    if session['user_id'] == board['user_id'] or board['user_id'] == -1:
        if security.check_text_validity(request.form['new_title'],
                                        extra_characters=" '"):
            return json.dumps(
                data_manager.rename_board(request.form['board_id'],
                                          request.form['new_title']))
        return json.dumps(False)
    return json.dumps(False)
def register():
    if len(request.form['username']) == 0 or len(
            request.form['password']) == 0:
        return json.dumps({'error': 'username or password is empty'})

    if security.check_text_validity(request.form['username']):
        if not security.check_password_validity(request.form['password']):
            return json.dumps({'error': 'invalid character in password'})
        if data_manager.get_username(request.form['username']):
            return json.dumps({'error': 'username already exists'})

        password = security.hash_password(request.form['password'])
        user = data_manager.user_register(request.form['username'], password)
        print(user)
        session['username'] = user['username']
        session['user_id'] = user['id']
        return json.dumps({'redirect': True})
    return json.dumps({'error': 'invalid character in username'})