Пример #1
0
    def post(self):
        customer_names = request.json["names"]
        email = request.json["email"]
        contact = request.json["contact"]
        profile_picture = request.json["profile_picture"]
        password = request.json["password"]
        customer_details = Customer()(name=customer_names,
                                      email=email,
                                      contact=contact,
                                      profile_picture=profile_picture,
                                      password=password)

        if customer_details:
            customer = Customer().google_sign_in(email=email)
            return customer
Пример #2
0
    def post(self):
        args = forgot_password_args.parse_args()
        user = Customer.read_customer(email=args["email"])
        if user != None:
            token_gen = TokenGenerator(user=user)
            token = token_gen.generate_password_reset_token()
            mail_ = reset_email
            mail_.context = dict(user_name=user.name, token=token)
            mail_.recipients = [user.email]
            mail_.text = "To reset your password visit the following link " + url_for(
                'set_new_password', token=token, _external=True
            ) + "\n if you did not request for this email then ignore."
            mail_.send()

            return jsonify(
                status="success",
                message="Check your email inbox for password reset link.",
                data=0)

        else:
            email = args["email"]
            return jsonify(
                status="error",
                message="This email: {} is not registered with clickeat".
                format(email),
                data=0)
Пример #3
0
def dashboard():
    product_sales_today = Sales.read_sales_sum(
        Sales.amount,
        Sales.sales_day == DateUtil().current_date.day,
        Sales.sales_month == DateUtil().current_date.month,
        Sales.sales_year == DateUtil().current_date.year,
    )

    commission_sales_today = Sales.read_sales_sum(
        Sales.commision_amount,
        Sales.sales_day == DateUtil().current_date.day,
        Sales.sales_month == DateUtil().current_date.month,
        Sales.sales_year == DateUtil().current_date.year,
    )
    customer_count = Customer.read_customer_count()
    vendors_count = Resturant.read_restaurants_count()
    products_count = Products.read_products_count()
    orders_count = Order.read_orders_count()
    total_revenue = Sales.read_sales_sum(Sales.amount)

    context = dict(product_sales_today=product_sales_today,
                   commission_sales_today=commission_sales_today,
                   total_revenue=total_revenue,
                   shipping_sales_today=0,
                   standard_shipping_sales_td=0,
                   pickup_station_sales_td=0,
                   vendors_count=vendors_count,
                   customer_count=customer_count,
                   products_count=products_count,
                   orders_count=orders_count)

    return render_template('dashboard.html', **context)
Пример #4
0
def signup():
    next_ = request.args.get("next")
    signup_form = SignupForm(next_=next_)
    if signup_form.validate_on_submit():
        data = signup_form.data
        name = data["name"]
        email = data["email"]
        telephone_code = data["telephone_code"]
        telephone = data["telephone"]
        password = data["password"]
        customer = Customer(name=name,
                            email=email,
                            contact=join_telephone(telephone_code, telephone),
                            password=password)
        session.add(customer)
        session.commit()
        if customer:
            login_user(customer, duration=timedelta(1))
            flash("Your account has been created.", "success")
        else:
            flash("There was an error creating your account.", "danger")
        if data['next_']:
            return redirect(data['next_'])
        return redirect(url_for('index_bp.index'))
    login_form = LoginForm(next_=next_)
    return render_template("signin_signup/signin-signup.html",
                           show_signup=True,
                           signup_form=signup_form,
                           login_form=login_form)
Пример #5
0
    def post(self):
        product_id = request.json["product_id"]
        customer_id = request.json["customer_id"]
        product_name = request.json["product_name"]
        product_image = request.json["product_image"]
        unit_price = request.json["unit_price"]
        quantity = request.json["quantity"]
        served_with = "none"
        if "served_with" in request.json:
            served_with = request.json["served_with"]
        
        try:
            if "free_delivery" in request.json:
                free_delivery = request.json["free_delivery"]
        except:
            free_delivery = False

        try:
            if "restaurant" in request.json:
                restaurant = request.json["restaurant"]
        except:
            restaurant = "clickEat"

        customer = Customer.read_customer(id=customer_id)

        if customer:
            cart_item = Cart()(
                product_id=product_id,
                customer_id=customer_id,
                product_name=product_name,
                product_image=product_image,
                unit_price=unit_price,
                quantity=quantity,
                served_with=served_with,
                free_delivery=free_delivery,
                restaurant=restaurant
            )

            if cart_item:
                cart_size = str(Cart.cart_total_quantity_or_item_count(customer_id))

                return jsonify(
                    status = "success",
                    message = "Product added to cart successfully!!.",
                    data = cart_size
                )
            
            else:
                return jsonify(
                    status = "failure",
                    message = "Error Whilst adding Product to Cart!!.",
                    data = 0
                )

        else:

            return jsonify(status="failure",message="Customer doesnot exits!!.",data=0)
Пример #6
0
    def post(self):
        print(request.json)
        customer_names = request.json["names"]
        email = request.json["email"]
        contact = request.json["contact"]
        profile_picture = request.json["profile_picture"]
        password = request.json["password"]
        customer_details = Customer()(name=customer_names,
                                      email=email,
                                      contact=contact,
                                      profile_picture=profile_picture,
                                      password=password)

        if customer_details:
            response = {
                "status": "success",
                "message": "Your Information was stored successfully!",
                "data": 0
            }

            return response

        else:
            customer = Customer().read_customer(contact=contact)
            if customer:

                response = {
                    "status": "failure",
                    "message": "User already exists!!",
                    "data": 0
                }

                return response
            else:

                response = {
                    "status": "failure",
                    "message": "Your Information was not saved!",
                    "data": 0
                }

                return response
Пример #7
0
    def put(self, id):
        customer_names = request.json["names"]
        email = request.json["email"]
        contact = request.json["contact"]
        second_contact = request.json["secondContact"]

        customer = Customer.read_customer(id=id)

        if customer:
            if (customer.update_customer(name=customer_names,
                                         email=email,
                                         contact=contact,
                                         second_contact=second_contact)):
                new_user_info = customer.serializer()
                new_user_info["token"] = "clickEattokenmissing"

                return new_user_info
Пример #8
0
    def put(self, id):
        old_password = request.json["oldPassword"]
        new_password = request.json["newPassword"]

        customer = Customer.read_customer(id=id)

        if customer:
            if (customer.change_password(old_password=old_password,
                                         new_password=new_password)):
                return {
                    "status": "success",
                    "message": "Password was updated successfully!!.",
                    "data": 0
                }
            else:
                return {
                    "status": "error",
                    "message": "Password was not updated successfully!!.",
                    "data": 0
                }
Пример #9
0
def set_new_password(token):
    form = NewPasswordForm()
    if form.validate_on_submit():
        token_gen = TokenGenerator()
        token_gen.verify_password_token(token)
        user = token_gen.user
        if user != None:
            customer = Customer.read_customer(id=user.id)
            if customer:
                customer.password = form.new_password.data
            else:
                user.password = pwd_context.hash(form.new_password.data)
            session.commit()
            flash(
                "Your new password has been reset. Please try to log in with the new password.",
                "success")
        else:
            flash(
                "Please request a new password reset. Either this link is invalid or expired.",
                "danger")
    context = dict(form=form, token=token)
    return render_template("new_password.html", **context)
Пример #10
0
def forgot_password(user_type):
    form = ForgotPasswordForm()
    if form.validate_on_submit():
        if user_type == "customer":
            user = Customer.read_customer(email=form.email.data.strip())
        else:
            flash("Failed to send password reset.", "danger")
            return redirect(url_for(".forgot_password", user_type=user_type))

        if user is not None:
            token_gen = TokenGenerator(user=user)
            token = token_gen.generate_password_reset_token()
            mail_ = reset_email
            mail_.context = dict(user_name=user.name, token=token)
            mail_.recipients = [user.email]
            mail_.send()

        flash(
            "If you provided a right email, check your email inbox for password reset link.",
            "success")
        return redirect(url_for(".forgot_password", user_type=user_type))

    context = dict(form=form, user_type=user_type)
    return render_template("reset.html", **context)
Пример #11
0
def forgot_password(user_type):
    form = ForgotPasswordForm()
    if form.validate_on_submit():
        if user_type == "customer":
            user = Customer.read_customer(email=form.email.data.strip())
        elif user_type == "clickeat_employee":
            user = StaffAccounts.read_user(email=form.email.data)
        else:
            flash("Failed to send password reset.", "danger")
            return redirect(url_for(".forgot_password", user_type=user_type))

        if user is not None:
            try:
                token_gen = TokenGenerator(user=user)
                token = token_gen.generate_password_reset_token()
                mail_ = reset_email
                # mail_.context = dict(
                #     user_name=user.name,
                #     token=token
                # )
                mail_.text = "To reset your password visit the following link " + url_for(
                    'set_new_password', token=token, _external=True
                ) + "\n if you did not request for this email then ignore."
                mail_.recipients = [user.email]
                mail_.send()
                flash(
                    "If you provided a right email, check your email inbox for password reset link.",
                    "success")
                return redirect(
                    url_for(".forgot_password", user_type=user_type))

            except Exception as e:
                print("Error whilst sending email: ", e)

    context = dict(form=form, user_type=user_type)
    return render_template("reset.html", **context)
Пример #12
0
 def post(self):
     telephone = request.json["telephone"]
     password = request.json["password"]
     customer_details = Customer.check_user(telephone=telephone,
                                            password=password)
     return customer_details
Пример #13
0
 def post(self):
     email = request.json["email"]
     if email:
         customer = Customer().google_sign_in(email=email)
         return customer