Exemplo n.º 1
0
def create_website():
    if current_user.user_role != 1:
        flash('You dont have access to this page', 'danger')
        return redirect(url_for('main_panel.admin_panel'))
    if request.method == "POST":
        website_title = request.form.get('website_name')
        if not validators.domain(website_title):
            flash('Create correct domain adress like: example.com', 'info')
            return redirect(url_for('main_panel.create_website_page'))
        if is_directory_exist(website_title):
            flash('Website {website_name} exist '
                  'choose another name'.format(website_name=website_title),
                  'danger')
            return redirect(url_for('main_panel.create_website_page'))
        create_directory(website_title)
        create_home_page(website_title)
        website = Website(title=website_title)
        db.session.add(website)
        db.session.commit()
        website_link = WebsiteLink(website_name=website_title,
                                   website_id=website.id)
        db.session.add(website_link)
        db.session.commit()
        current_user.website_link_id = website_link.id
        db.session.commit()
        flash('You created your website, to watch your website click button'
              ' on left menu', 'success')
        return redirect(url_for('main_panel.admin_panel'))
    if is_user_website_created(current_user.id):
        flash('You cannot create another website. You have one!', 'info')
        return redirect(url_for('main_panel.admin_panel'))
Exemplo n.º 2
0
def page_operations():
    if current_user.user_role != 1:
        flash('You dont have access to this page', 'danger')
        return redirect(url_for('main_panel.admin_panel'))
    if not is_user_website_created(current_user.id):
        flash('You dont have a website. Create a website first!', 'info')
        return redirect(url_for('main_panel.getting_started'))
    if request.form.get('page_select') is not None:
        website = get_current_website(current_user.website_link_id)
        if request.form.get('action') == "Delete page":
            title = request.form.get('page_select')
            delete_page(title, current_user.website_link_id)
            page = Page.query.filter_by(title_page=title,
                                        website_id=website.id).first()
            db.session.delete(page)
            db.session.commit()
            flash('This page has been deleted!', 'success')
            return redirect(url_for('main_panel.pages'))
        if request.form.get('action') == "Change page name":
            title = request.form.get('page_select')
            return render_template('admin_panel/pages/change-page-name.html',
                                   title="Change page name",
                                   page_title=title, website=website)
    else:
        flash('You need to select pages', 'info')
        return redirect(url_for('main_panel.pages'))
Exemplo n.º 3
0
def users_page():
    if current_user.user_role != 1:
        flash('You dont have access to this page', 'danger')
        return redirect(url_for('main_panel.admin_panel'))
    if not is_user_website_created(current_user.id):
        flash('You dont have a website. Create a website first!', 'info')
        return redirect(url_for('main_panel.getting_started'))
    form = CreateUserForm()
    website = get_current_website(current_user.website_link_id)
    users = User.query.filter(User.user_role != 1).all()
    if form.validate_on_submit():
        hashed_password = bcrypt.generate_password_hash(form.password.data
                                                        ).decode('utf-8')
        user_role = get_user_role(form.user_role.data)
        user = User(username=form.username.data,
                    email=form.email.data,
                    password=hashed_password,
                    user_role=user_role,
                    website_link_id=current_user.website_link_id)
        db.session.add(user)
        db.session.commit()
        flash('Your create user: '******'{user_name}'.format(user_name=user.username),
              'success')
        return redirect(url_for('main_panel.users_page'))
    return render_template('admin_panel/users/users.html', website=website,
                           form=form, users=users)
Exemplo n.º 4
0
def create_website_page():
    if current_user.user_role != 1:
        flash('You dont have access to this page', 'danger')
        return redirect(url_for('main_panel.admin_panel'))
    if is_user_website_created(current_user.id):
        flash('You cannot create another website. You have one!', 'info')
        return redirect(url_for('main_panel.admin_panel'))
    return render_template('admin_panel/getting_started/create-website.html',
                           title="Create website")
Exemplo n.º 5
0
def settings_page():
    if current_user.user_role != 1:
        flash('You dont have access to this page', 'danger')
        return redirect(url_for('main_panel.admin_panel'))
    if not is_user_website_created(current_user.id):
        flash('You dont have a website. Create a website first!', 'info')
        return redirect(url_for('main_panel.getting_started'))
    website = get_current_website(current_user.website_link_id)
    return render_template('admin_panel/settings/settings.html',
                           title="settings", website=website)
Exemplo n.º 6
0
def change_nav_font_size():
    if not is_user_website_created(current_user.id):
        flash('You dont have a website. Create a website first!', 'info')
        return redirect(url_for('main_panel.getting_started'))
    if request.method == 'POST':
        navbarFont = request.form.get('navbarFontSize')
        website = get_current_website(current_user.website_link_id)
        website.navbar_font_size = navbarFont
        db.session.commit()
        flash('Navigation font size changed', 'success')
        return redirect(url_for('website.index', website_name=website.title))
Exemplo n.º 7
0
def change_nav_font_family():
    if current_user.user_role != 1:
        flash('You dont have access to this page', 'danger')
        return redirect(url_for('main_panel.admin_panel'))
    if not is_user_website_created(current_user.id):
        flash('You dont have a website. Create a website first!', 'info')
        return redirect(url_for('main_panel.getting_started'))
    if request.method == 'POST':
        navbarFontFamily = request.form.get('navbarFontFamily')
        website = get_current_website(current_user.website_link_id)
        website.navbar_font_style = navbarFontFamily
        db.session.commit()
        flash('Navigation font family changed', 'success')
        return redirect(url_for('website.index', website_name=website.title))
Exemplo n.º 8
0
def admin_panel():
    website = get_current_website(current_user.website_link_id)
    if current_user.user_role != 1:
        role = "disabled"
        return render_template('admin_panel/admin-panel.html',
                               title="Admin Panel",
                               website=website, role=role)
    if website is None:
        return redirect(url_for('main_panel.getting_started'))
    if not is_user_website_created(current_user.id):
        flash('You dont have a website. Create a website first!', 'info')
        return redirect(url_for('main_panel.getting_started'))
    return render_template('admin_panel/admin-panel.html', title="Admin Panel",
                           website=website)
Exemplo n.º 9
0
def change_font_size():
    if current_user.user_role != 1:
        flash('You dont have access to this page', 'danger')
        return redirect(url_for('main_panel.admin_panel'))
    if not is_user_website_created(current_user.id):
        flash('You dont have a website. Create a website first!', 'info')
        return redirect(url_for('main_panel.getting_started'))
    if request.method == 'POST':
        website = get_current_website(current_user.website_link_id)
        title_post_font = request.form.get('titlePostFont')
        website.title_post_font_size = title_post_font
        db.session.commit()
        post_text_font = request.form.get('PostTextFont')
        website.post_text_font_size = post_text_font
        db.session.commit()
        flash('Post font size changed', 'success')
        return redirect(url_for('website.index', website_name=website.title))
Exemplo n.º 10
0
def show_admin_panel():
    if current_user.user_role != 1:
        flash('You dont have access to this page', 'danger')
        return redirect(url_for('main_panel.admin_panel'))
    if not is_user_website_created(current_user.id):
        flash('You dont have a website. Create a website first!', 'info')
        return redirect(url_for('main_panel.getting_started'))
    website = get_current_website(current_user.website_link_id)
    if request.form.get('admin_panel_view'):
        flash('Admin panel turn on', 'success')
        website.show_admin_panel = True
        db.session.commit()
    else:
        flash('Admin panel turn off', 'success')
        website.show_admin_panel = False
        db.session.commit()
    return redirect(url_for('main_panel.settings_page'))
Exemplo n.º 11
0
def change_website_name():
    if current_user.user_role != 1:
        flash('You dont have access to this page', 'danger')
        return redirect(url_for('main_panel.admin_panel'))
    if not is_user_website_created(current_user.id):
        flash('You dont have a website. Create a website first!', 'info')
        return redirect(url_for('main_panel.getting_started'))
    website = get_current_website(current_user.website_link_id)
    new_website_name = request.form.get('website_name')
    if not validators.domain(new_website_name):
        flash('Create correct domain adress like: example.com', 'info')
        return redirect(url_for('main_panel.change_website_name_page'))
    change_directory_name(website.title, new_website_name)
    website.title = new_website_name
    db.session.commit()
    flash('Website name changed to {title}'.format(title=website.title),
          'success')
    return redirect(url_for('main_panel.admin_panel'))
Exemplo n.º 12
0
def delete_website():
    if current_user.user_role != 1:
        flash('You dont have access to this page', 'danger')
        return redirect(url_for('main_panel.admin_panel'))
    if not is_user_website_created(current_user.id):
        flash('You dont have a website. Create a website first!', 'info')
        return redirect(url_for('main_panel.getting_started'))
    website = get_current_website(current_user.website_link_id)
    website_link = WebsiteLink.query.filter_by(website_id=website.id).first()
    WebsiteLink.query.filter(WebsiteLink.id == website_link.id).delete()
    delete_directory(website.title)
    Website.query.filter(Website.id == website.id).delete()
    Page.query.filter(Page.website_id == website.id).delete()
    User.query.filter(User.website_link_id == website_link.id).delete()
    Post.query.filter(Post.website_link_id == website_link.id).delete()
    db.session.commit()
    flash('Website has been deleted', 'info')
    return redirect(url_for('main_panel.getting_started'))
Exemplo n.º 13
0
def change_page_name():
    if current_user.user_role != 1:
        flash('You dont have access to this page', 'danger')
        return redirect(url_for('main_panel.admin_panel'))
    if not is_user_website_created(current_user.id):
        flash('You dont have a website. Create a website first!', 'info')
        return redirect(url_for('main_panel.getting_started'))
    title = request.form.get('page_name')
    website = get_current_website(current_user.website_link_id)
    page = Page.query.filter_by(title_page=title,
                                website_id=website.id).first()
    page.title_page = request.form.get('new_page_name')
    change_page_name_in_html_file(title, page.title_page,
                                  current_user.id)
    db.session.commit()
    flash('Page name changed to {title}'.format(title=page.title_page),
          'success')
    return redirect(url_for('main_panel.pages'))
Exemplo n.º 14
0
def create_new_page():
    if current_user.user_role != 1:
        flash('You dont have access to this page', 'danger')
        return redirect(url_for('main_panel.admin_panel'))
    if not is_user_website_created(current_user.id):
        flash('You dont have a website. Create a website first!', 'info')
        return redirect(url_for('main_panel.getting_started'))
    if request.method == 'POST':
        title_page = request.form.get('page_name')
        website = get_current_website(current_user.website_link_id)
        create_new_empty_page(website.title, title_page)
        page = Page(title_page=title_page, website_id=website.id)
        db.session.add(page)
        db.session.commit()
        flash('You created new page!', 'success')
    pages = get_current_website_pages(current_user.website_link_id)
    website = get_current_website(current_user.website_link_id)
    return render_template('admin_panel/pages/pages.html',
                           pages=pages, website=website)
Exemplo n.º 15
0
def change_navigation():
    if current_user.user_role != 1:
        flash('You dont have access to this page', 'danger')
        return redirect(url_for('main_panel.admin_panel'))
    if not is_user_website_created(current_user.id):
        flash('You dont have a website. Create a website first!', 'info')
        return redirect(url_for('main_panel.getting_started'))
    if request.method == 'POST':
        if request.form.get('nav_style') == "green":
            nav_style = "navbar-dark bg-success"
        if request.form.get('nav_style') == "dark":
            nav_style = "navbar-dark bg-dark"
        if request.form.get('nav_style') == 'blue':
            nav_style = "navbar-dark bg-info"
        website = get_current_website(current_user.website_link_id)
        website.nav_style = nav_style
        website.footer_style = nav_style
        db.session.commit()
        flash('Navigation bar changed', 'success')
        return redirect(url_for('website.index', website_name=website.title))
Exemplo n.º 16
0
def background_style():
    if current_user.user_role != 1:
        flash('You dont have access to this page', 'danger')
        return redirect(url_for('main_panel.admin_panel'))
    if not is_user_website_created(current_user.id):
        flash('You dont have a website. Create a website first!', 'info')
        return redirect(url_for('main_panel.getting_started'))
    if request.method == 'POST':
        if request.form.get('backround_style') == "hotel":
            backround_style = "hotel.png"
        if request.form.get('backround_style') == "spikes":
            backround_style = "spikes.png"
        if request.form.get('backround_style') == 'painting':
            backround_style = "painting.png"
        if request.form.get('backround_style') == 'flower':
            backround_style = "flower.png"
        website = get_current_website(current_user.website_link_id)
        website.page_background = backround_style
        db.session.commit()
        flash('Background changed', 'success')
        return redirect(url_for('website.index', website_name=website.title))
Exemplo n.º 17
0
def user_operations():
    if current_user.user_role != 1:
        flash('You dont have access to this page', 'danger')
        return redirect(url_for('main_panel.admin_panel'))
    if not is_user_website_created(current_user.id):
        flash('You dont have a website. Create a website first!', 'info')
        return redirect(url_for('main_panel.getting_started'))
    if request.form.get('user_select') is not None:
        if request.form.get('action') == "Delete user":
            username = request.form.get('user_select')
            user = User.query.filter_by(username=username).first()
            db.session.delete(user)
            db.session.commit()
            flash('The {user} has been deleted!'.format(user=username),
                  'success')
            return redirect(url_for('main_panel.users_page'))
        if request.form.get('action') == "Change user data":
            username = request.form.get('user_select')
            user = User.query.filter_by(username=username).first()
            return redirect(url_for('main_panel.change_user_data',
                                    user_id=user.id))
    else:
        flash('You need to select user', 'info')
        return redirect(url_for('main_panel.users_page'))