def purches_func():
    if 'user' in session:
        if request.method == 'POST':
            post_data = request.form
            if __is_number(post_data['product_id']) and __is_alpha_space(
                    post_data['vendor']) and __is_number(post_data['amount']):
                try:
                    mycursor = mydb.cursor(dictionary=True)

                    sql = 'INSERT INTO txn (product_id,amount,vendor) VALUES (%s,%s,%s)'
                    val = (post_data['product_id'], post_data['amount'],
                           post_data['vendor'])
                    mycursor.execute(sql, val)
                    mydb.commit()
                    if (mycursor.rowcount == 1):
                        sql = 'UPDATE  product SET stock = stock+ %s WHERE id = %s '
                        val = (post_data['amount'], post_data['product_id'])
                        mycursor.execute(sql, val)
                        mydb.commit()
                        if (mycursor.rowcount == 1):
                            success_dist = {
                                'message': 'data saved successfully '
                            }
                            return render_template('trxn/purches.html',
                                                   success=success_dist)
                        else:
                            return "all not ok"
                    else:
                        error_dist = {
                            'message': 'data not save ... please try again'
                        }
                        return render_template('trxn/purches.html',
                                               error=error_dist)

                except errors.Error as e:
                    print("Db error :", e)
                    error_dist = {
                        'message': 'server error , Please try again letter'
                    }
                    return render_template('trxn/purches.html',
                                           error=error_dist)

            else:
                error_dist = {'message': 'Please provide proper information'}
                return render_template('trxn/purches.html', error=error_dist)
        else:
            return render_template('trxn/purches.html')
    else:
        return redirect('/user/login')
Example #2
0
def login_func():

    if request.method == 'POST':
        post_data = request.form
        if __is_email(post_data['email']) and len(post_data['password']) > 4:
            try:
                mycursor = mydb.cursor(dictionary=True)
                sql = 'SELECT id,name,email,password FROM users WHERE email=%s'
                val = (post_data['email'], )
                mycursor.execute(sql, val)
                user_details = mycursor.fetchone()
                if user_details == None:
                    error_dist = {
                        'message': 'sorry.. this type of user not found'
                    }
                    return render_template('user/login.html', error=error_dist)
                else:
                    if user_details['password'] == __create_encryption(
                            post_data['password']):
                        print(__create_encryption(post_data['password']))
                        session["user"] = {
                            'id': user_details['id'],
                            'name': user_details['name'],
                            'email': user_details['email']
                        }
                        return redirect('/')
                    else:
                        error_dist = {
                            'message': 'Error : Email or password mot matched'
                        }
                        return render_template('user/login.html',
                                               error=error_dist)

            except errors.Error as e:
                print("Db error :", e)
                error_dist = {
                    'message': 'Error :server error , Please try again letter'
                }
                return render_template('user/login.html', error=error_dist)
        else:
            error_dist = {
                'message': 'Error : Please provide proper information'
            }
            return render_template('user/login.html', error=error_dist)
    else:
        return render_template('user/login.html')
Example #3
0
def createuser_func():

    if request.method == 'POST':
        # ------ save all form data into : post_data variable ------#
        post_data = request.form

        # ------ sanitize user input ------#
        if __is_alpha_space(post_data['name']) and __is_email(
                post_data['email']) and len(post_data['password']) > 4:

            #------ encrypting password --------
            db_pass_to_save = __create_encryption(post_data['password'])

            try:

                mycursor = mydb.cursor(dictionary=True)
                sql = "INSERT INTO users (name, email ,password) VALUES (%s, %s , %s )"
                val = (post_data['name'], post_data['email'], db_pass_to_save)
                mycursor.execute(sql, val)
                mydb.commit()  # mysqlresult = mycursor.fetchall()
                if (mycursor.rowcount == 1):
                    success_dist = {'message': 'data save successfully'}
                    return render_template('user/create.html',
                                           success=success_dist)
                else:
                    error_dist = {
                        'message': 'data not saved , Please try again letter'
                    }
                    return render_template('user/create.html',
                                           error=error_dist)
            except errors.Error as e:
                print("Db error :", e)
                error_dist = {
                    'message': 'server error , Please try again letter'
                }
                return render_template('user/create.html', error=error_dist)
        else:
            error_dist = {'message': 'Please provide proper information'}
            return render_template('user/create.html', error=error_dist)

    else:
        return render_template('user/create.html')
Example #4
0
def all_user_func():
    if 'user' in session:

        try:
            mycursor = mydb.cursor(dictionary=True)
            sql = "SELECT id,product_name,product_price,stock,product_status FROM product "
            mycursor.execute(sql)
            user_details = mycursor.fetchall()

            if user_details == None:
                return 'no user found'
            else:
                print(user_details)
                return render_template('stock/stock.html', data=user_details)

        except errors.Error as e:
            print("Db error :", e)
            return 'not able to check ,Please try again letter'
    else:
        return redirect('/user/login')
Example #5
0
def product_add_func():
    if "user" in session:
        if request.method== 'POST':
            post_data=request.form
            if __is_alpha_space(post_data['p_name']) and __is_number(post_data['p_price']):
                try:

                    mycursor = mydb.cursor(dictionary=True)
                    sql = "INSERT INTO product (product_name,product_price) VALUES (%s, %s  )"
                    val = (post_data['p_name'], post_data['p_price'] )
                    mycursor.execute(sql, val)
                    mydb.commit()  # mysqlresult = mycursor.fetchall()
                    if (mycursor.rowcount == 1):
                        success_dist = {
                                'message' : 'data saved successfully '
                            }
                        return render_template('product/add_product.html', success=success_dist)
                    else :
                        error_dist = {
                            'message' : 'data not saved , Please try again letter'
                        }
                        return render_template('product/add_product.html', error=error_dist )
                except errors.Error as e:
                    print("Db error :",e)
                    error_dist = {
                        'message' : 'server error , Please try again letter'
                    }
                    return render_template('product/add_product.html', error=error_dist)
            else :
                error_dist = {
                    'message' : 'Please provide proper information'
                }
                return render_template('product/add_product.html', error=error_dist)
        else:
            return render_template('product/add_product.html')
    else:
        return redirect('/user/login')