Ejemplo n.º 1
0
def logout():
    try:
        logout_user()
        return redirect(url_for('login'))
    except Exception as e:
        log_unrecognized_exception(e)
        abort(500)
Ejemplo n.º 2
0
def admin_add_image():
    form = UploadImageForm()

    # GET
    if request.method == "GET":
        try:
            data = images_data_provider.get_add_data(form=form)
            return render_template("admin/images/add-image.html", data=data)
        except Exception as e:
            log_unrecognized_exception(e)
            abort(500)

    # POST
    else:
        try:
            if not form.validate_on_submit():
                data = images_data_provider.get_add_data(form=form)
                return render_template("admin/images/add-image.html",
                                       data=data)

            image = request.files[form.image.name]
            filename = secure_filename(image.filename)
            image.save(
                os.path.join(app.config['UPLOADED_IMAGES_FOLDER'], filename))

            flash("Imagem \"%s\" foi adicionada com sucesso." % filename,
                  "success")
            return redirect(url_for("admin_add_image"))
        except Exception as e:
            log_unrecognized_exception(e)
            abort(500)
Ejemplo n.º 3
0
def email_confirmed(token):
    try:
        email = ts.loads(token, salt="email-confirm-key")
        user = db_manager.get_user(email=email)
        if not user:
            abort(404)
        user.email_confirmed = True
        db_manager.add(user)
        db_manager.commit()
        flash("Email confirmado com sucesso.", "success")
        return redirect(url_for('login'))
    except BadSignature:
        db_manager.rollback()
        log_exception(name="BadSignature")
        abort(404)
    except DatabaseAccessError:
        db_manager.rollback()
        current_url = url_for('email_confirmed', token=token)
        flash(DatabaseAccessError.msg, "danger")
        data = failed_to_get_data_provider.get_data(current_url=current_url)
        return render_template('customer/shared/failed-to-get.html', data=data)
    except Exception as e:
        db_manager.rollback()
        log_unrecognized_exception(e)
        abort(500)
Ejemplo n.º 4
0
def about_us():
    try:
        data = about_us_data_provider.get_data()
        return render_template('customer/general/about-us.html', data=data)
    except Exception as e:
        log_unrecognized_exception(e)
        abort(500)
Ejemplo n.º 5
0
def admin_dashboard():
    try:
        data = home_data_provider.get_data()
        return render_template("admin/general/home.html", data=data)
    except Exception as e:
        log_unrecognized_exception(e)
        abort(500)
Ejemplo n.º 6
0
 def remove_all_images():
     try:
         remove_all_images_implementation()
         return redirect(url_for("admin_dashboard"))
     except Exception as e:
         log_unrecognized_exception(e)
         return "Falha ao reiniciar as imagens"
Ejemplo n.º 7
0
def home():
    try:
        data = home_data_provider.get_data()
        return render_template('customer/general/home.html', data=data)
    except Exception as e:
        log_unrecognized_exception(e)
        abort(500)
Ejemplo n.º 8
0
def cart_remove_product(product_id, quantity):
    try:
        # TODO: Implement
        return redirect(url_for('cart'))
    except Exception as e:
        log_unrecognized_exception(e)
        abort(500)
Ejemplo n.º 9
0
def my_account():
    # GET
    if request.method == 'GET':
        try:
            # Getting optional parameters
            user_info_editable = request.args.get("editar")

            # Setting default value to optional parameters
            if user_info_editable and user_info_editable == "sim":
                user_info_editable = True
            else:
                user_info_editable = False

            data = my_account_data_provider.get_data(user_info_editable)
            return render_template('customer/general/my-account.html',
                                   data=data)
        except Exception as e:
            log_unrecognized_exception(e)
            abort(500)

    # POST
    else:
        try:
            # TODO: Implement
            return redirect(url_for('my_account'))
        except Exception as e:
            log_unrecognized_exception(e)
            abort(500)
Ejemplo n.º 10
0
def cart_delete_all_products():
    try:
        # TODO: Implement
        return redirect(url_for('cart'))
    except Exception as e:
        log_unrecognized_exception(e)
        abort(500)
Ejemplo n.º 11
0
def admin_product_categories(page):
    simple_submit_form = SimpleSubmitForm()
    filter_form = CategoryFilterForm()

    try:
        # Getting optional parameters
        active = request.args.get('active')

        # Setting default value to optional parameters
        if not active:
            active = "True"

        url_args = {
            "active": active,
            "page": page,
        }

        # Converting query parameters from string type to his respective python type
        active = ast.literal_eval(active)

        data = categories_data_provider.get_data(
            page=page,
            filter_form=filter_form,
            simple_submit_form=simple_submit_form,
            url_args=url_args,
            active=active)
        return render_template("admin/products/categories.html", data=data)
    except Exception as e:
        log_unrecognized_exception(e)
        abort(500)
Ejemplo n.º 12
0
def product(product_id):
    try:
        data = product_data_provider.get_data(product_id)
        return render_template('customer/products/product.html', data=data)
    except Exception as e:
        log_unrecognized_exception(e)
        abort(500)
Ejemplo n.º 13
0
def admin_add_product_category():
    form = AddCategoryForm()

    # GET
    if request.method == "GET":
        try:
            data = categories_data_provider.get_add_data(form=form)
            return render_template("admin/products/add_category.html",
                                   data=data)
        except Exception as e:
            log_unrecognized_exception(e)
            abort(500)

    # POST
    else:
        try:
            if not form.validate_on_submit():
                data = categories_data_provider.get_add_data(form=form)
                return render_template("admin/products/add_category.html",
                                       data=data)

            category = Category(name=form.category.data)
            db_manager.add(category)
            db_manager.commit()

            flash(
                "Categoria \"%s\" foi adicionada com sucesso." %
                form.category.data, "success")
            return redirect(url_for("admin_add_product_category"))
        except Exception as e:
            db_manager.rollback()
            log_unrecognized_exception(e)
            abort(500)
Ejemplo n.º 14
0
def admin_update_stock(product_id):
    update_stock_form = StockOperationForm()

    try:
        product = db_manager.get_product(product_id=product_id)

        if not product:
            return "", 404

        if not update_stock_form.validate_on_submit():
            return "", 422

        product.stock = int(update_stock_form.amount.data)

        db_manager.add(product)
        db_manager.commit()

        response = {
            "new_stock": product.stock,
        }
        return json.dumps(response), 200
    except Exception as e:
        db_manager.rollback()
        log_unrecognized_exception(e)
        return "", 500
Ejemplo n.º 15
0
def order(order_id):
    try:
        data = order_data_provider.get_data(order_id)
        return render_template('customer/general/order.html', data=data)
    except Exception as e:
        log_unrecognized_exception(e)
        abort(500)
Ejemplo n.º 16
0
def blog(page):
    try:
        data = blog_data_provider.get_data(page=page)
        return render_template('customer/blog/blog.html', data=data)
    except Exception as e:
        log_unrecognized_exception(e)
        abort(500)
Ejemplo n.º 17
0
def sent_recover_password_email(email):
    try:
        data = sent_recover_password_email_data_provider.get_data(email=email)
        return render_template(
            'customer/user_management/sent-recover-password-email.html',
            data=data)
    except Exception as e:
        log_unrecognized_exception(e)
        abort(500)
Ejemplo n.º 18
0
def admin_edit_product_subcategory(subcategory_id):
    form = EditSubcategoryForm()

    # Getting optional parameters
    url_args = request.args.get('url_args')

    # Setting default value to optional parameters
    # Converting optional parameters from string type to its corresponded python type
    if not url_args:
        url_args = {}
    else:
        url_args = ast.literal_eval(url_args)

    # GET
    if request.method == "GET":
        try:
            subcategory = db_manager.get_subcategory(subcategory_id)
            if not subcategory:
                raise InvalidUrlArgError()

            form.add_category_choices()

            data = subcategories_data_provider.get_edit_data(
                form, subcategory_id=subcategory_id, url_args=url_args)
            return render_template("admin/products/edit_subcategory.html",
                                   data=data)
        except Exception as e:
            log_unrecognized_exception(e)
            abort(500)

    # POST
    else:
        try:
            subcategory = db_manager.get_subcategory(subcategory_id)
            if not subcategory:
                raise InvalidUrlArgError()

            form.add_category_choices()

            if not form.validate_on_submit():
                data = subcategories_data_provider.get_edit_data(
                    form, subcategory_id=subcategory_id, url_args=url_args)
                return render_template("admin/products/edit_subcategory.html",
                                       data=data)

            subcategory.name = form.subcategory.data
            subcategory.category_id = form.category_id.data
            db_manager.add(subcategory)
            db_manager.commit()

            flash("Subcategoria #%s foi editada com sucesso." % subcategory_id,
                  "success")
            return redirect(url_for("admin_product_subcategories", **url_args))
        except Exception as e:
            db_manager.rollback()
            log_unrecognized_exception(e)
            abort(500)
Ejemplo n.º 19
0
def redefine_password(token):
    form = RedefinePasswordForm()

    # GET
    if request.method == "GET":
        try:
            email = ts.loads(token, salt="recover-key")
            data = redefine_password_data_provider.get_data(form=form,
                                                            email=email,
                                                            token=token)
            return render_template(
                'customer/user_management/redefine-password.html', data=data)
        except BadSignature:
            log_exception(name="BadSignature")
            abort(404)
        except Exception as e:
            log_unrecognized_exception(e)
            abort(500)

    # POST
    else:
        email = None
        try:
            email = ts.loads(token, salt="recover-key")

            if not form.validate_on_submit():
                data = redefine_password_data_provider.get_data(form=form,
                                                                email=email,
                                                                token=token)
                return render_template(
                    'customer/user_management/redefine-password.html',
                    data=data)

            user = db_manager.get_user(email)
            user.password = form.password.data
            db_manager.add(user)
            db_manager.commit()

            flash("Senha redefinida com sucesso.", "success")
            return redirect(url_for('login'))
        except BadSignature:
            db_manager.rollback()
            log_exception(name="BadSignature")
            abort(404)
        except DatabaseAccessError:
            db_manager.rollback()
            flash(DatabaseAccessError.msg, "danger")
            data = redefine_password_data_provider.get_data(form=form,
                                                            email=email,
                                                            token=token)
            return render_template(
                'customer/user_management/redefine-password.html', data=data)
        except Exception as e:
            db_manager.rollback()
            log_unrecognized_exception(e)
            abort(500)
Ejemplo n.º 20
0
 def restart_db():
     try:
         clear_db_implementation()
         time.sleep(0.1)
         create_db_implementation()
         time.sleep(0.1)
         fill_db_implementation()
         return redirect(url_for("admin_dashboard"))
     except Exception as e:
         log_unrecognized_exception(e)
         return "Falha ao reiniciar o db"
Ejemplo n.º 21
0
def cart():
    try:
        # Getting user session identifier. Aka user_email
        user_email = session["user_id"]

        data = cart_data_provider.get_data(user_email=user_email)
        return render_template('customer/cart/cart.html',
                               cart_table_editable=True,
                               data=data)
    except Exception as e:
        log_unrecognized_exception(e)
        abort(500)
Ejemplo n.º 22
0
def admin_images(page):
    remove_form = SimpleSubmitForm()

    url_args = {"page": page}

    try:
        data = images_data_provider.get_data(page=page,
                                             remove_form=remove_form,
                                             url_args=url_args)
        return render_template("admin/images/images.html", data=data)
    except Exception as e:
        log_unrecognized_exception(e)
        abort(500)
Ejemplo n.º 23
0
def products_by_search(page):
    try:
        # Getting optional parameters
        q = request.args.get("q")

        # Setting default value to optional parameters
        if not q:
            q = ""

        data = products_data_provider.get_products_data_by_search(page=page,
                                                                  q=q)
        return render_template('customer/products/products.html', data=data)
    except Exception as e:
        log_unrecognized_exception(e)
        abort(500)
Ejemplo n.º 24
0
def blog_post(blog_post_id):
    try:
        # Getting optional parameters
        blog_page_to_return = request.args.get('blog-page-to-return')

        # Setting default value to optional parameters
        if not blog_page_to_return:
            blog_page_to_return = 1

        data = blog_post_data_provider.get_data(
            blog_post_id=blog_post_id, blog_page_to_return=blog_page_to_return)
        return render_template('customer/blog/blog-post.html', data=data)
    except Exception as e:
        log_unrecognized_exception(e)
        abort(500)
Ejemplo n.º 25
0
def admin_remove_image(image_name):
    remove_form = SimpleSubmitForm()

    try:
        if not remove_form.validate_on_submit():
            raise InsecurePostException()

        file_path = os.path.join(app.config['UPLOADED_IMAGES_FOLDER'],
                                 image_name)
        if os.path.exists(file_path):
            os.remove(file_path)

        return ('', 204)
    except Exception as e:
        log_unrecognized_exception(e)
        return ("", 500)
Ejemplo n.º 26
0
def resend_confirmation_email():
    form = ResendConfirmationEmailForm()

    # GET
    if request.method == 'GET':
        try:
            data = resend_confirmation_email_data_provider.get_data(form)
            return render_template(
                'customer/user_management/resend-confirmation-email.html',
                data=data)
        except Exception as e:
            log_unrecognized_exception(e)
            abort(500)

    # POST
    else:
        try:
            if not form.validate_on_submit():
                data = resend_confirmation_email_data_provider.get_data(
                    form=form)
                return render_template(
                    'customer/user_management/resend-confirmation-email.html',
                    data=data)

            # TODO: Wait one hour to resend for the same email
            email_manager.send_create_account_confirmation_email(
                form.email.data)
            return redirect(
                url_for("sent_confirmation_email", email=form.email.data))
        except DatabaseAccessError:
            db_manager.rollback()
            flash(DatabaseAccessError.msg, "danger")
            data = resend_confirmation_email_data_provider.get_data(form=form)
            return render_template(
                'customer/user_management/resend-confirmation-email.html',
                data=data)
        except EmailSendingError:
            db_manager.rollback()
            flash(EmailSendingError.msg, "danger")
            data = resend_confirmation_email_data_provider.get_data(form=form)
            return render_template(
                'customer/user_management/resend-confirmation-email.html',
                data=data)
        except Exception as e:
            db_manager.rollback()
            log_unrecognized_exception(e)
            abort(500)
Ejemplo n.º 27
0
def create_account():
    form = CreateAccountForm()

    # GET
    if request.method == "GET":
        try:
            data = create_account_data_provider.get_data(form)
            return render_template(
                'customer/user_management/create-account.html', data=data)
        except Exception as e:
            log_unrecognized_exception(e)
            abort(500)

    # POST
    else:
        try:
            if not form.validate_on_submit():
                data = create_account_data_provider.get_data(form)
                return render_template(
                    'customer/user_management/create-account.html', data=data)

            user = User(email=form.email.data, password=form.password.data)
            db_manager.add(user)

            email_manager.send_create_account_confirmation_email(
                form.email.data)

            db_manager.commit()
            return redirect(
                url_for("sent_confirmation_email",
                        email=request.form["email"]))
        except DatabaseAccessError:
            db_manager.rollback()
            flash(DatabaseAccessError.msg, "danger")
            data = create_account_data_provider.get_data(form=form)
            return render_template(
                'customer/user_management/create-account.html', data=data)
        except EmailSendingError:
            db_manager.rollback()
            flash(EmailSendingError.msg, "danger")
            data = create_account_data_provider.get_data(form=form)
            return render_template(
                'customer/user_management/create-account.html', data=data)
        except Exception as e:
            db_manager.rollback()
            log_unrecognized_exception(e)
            abort(500)
Ejemplo n.º 28
0
def admin_edit_blog_post(post_id):
    form = None

    # GET
    if request.method == "GET":
        try:
            raise NotImplementedError()
        except Exception as e:
            log_unrecognized_exception(e)
            abort(500)

    # POST
    else:
        try:
            raise NotImplementedError()
        except Exception as e:
            log_unrecognized_exception(e)
            abort(500)
Ejemplo n.º 29
0
def admin_content_home_add_section():
    form = None

    # GET
    if request.method == "GET":
        try:
            raise NotImplementedError()
        except Exception as e:
            log_unrecognized_exception(e)
            abort(500)

    # POST
    else:
        try:
            raise NotImplementedError()
        except Exception as e:
            log_unrecognized_exception(e)
            abort(500)
Ejemplo n.º 30
0
def login():
    form = LoginForm()

    # GET
    if request.method == "GET":
        try:
            data = login_data_provider.get_data(form=form)
            return render_template('customer/user_management/login.html',
                                   data=data)
        except Exception as e:
            log_unrecognized_exception(e)
            abort(500)

    # POST
    else:
        try:
            if not form.validate_on_submit():
                data = login_data_provider.get_data(form=form)
                return render_template('customer/user_management/login.html',
                                       data=data)

            user = db_manager.get_user(form.email.data)
            user.authenticated = True
            db_manager.add(user)
            db_manager.commit()
            login_user(user)

            if user.email == app.config["ADMIN_MAIL"]:
                return redirect(url_for('admin_dashboard'))
            else:
                return redirect(url_for('my_account'))
        except DatabaseAccessError:
            db_manager.rollback()
            flash(DatabaseAccessError.msg, "danger")
            data = login_data_provider.get_data(form=form)
            return render_template('customer/user_management/login.html',
                                   data=data)
        except Exception as e:
            db_manager.rollback()
            log_unrecognized_exception(e)
            abort(500)