Beispiel #1
0
def check_user_seesion():
    try:
        if not "HTTP_COOKIE" in os.environ or not os.environ["HTTP_COOKIE"]:
            return False
        cookie = cookies.SimpleCookie(os.environ["HTTP_COOKIE"])
        sess = session.Session(expires=365*24*60*60, cookie_path='/')
        #lastvisit = sess.data.get('lastvisit')
        #sess.data['lastvisit'] = repr(time.time())
        #print print_page('index.html', "Inicio")
        #print cookie["sid"].value
        conn = Connection()
        
        result = conn.valid_username_cookie_id(sess.cookie['sid'].value)
        cookie_file = format_cookie_path(sess.cookie['sid'].value)
        #isfile = os.path.exists(cookie_file)
        #print result
        #print isfile
        #print cookie["sid"].value != sess.cookie["sid"].value
        if not result:
            return False
        else:
            return True
    
    except cookies.CookieError as error:
        return False
Beispiel #2
0
def __place_order(user):
    parser = helpers.FormParser()
    parser.discover_values()
    address = parser.get_value('address', '')
    if __validate_properties(address):
        return False

    conn = Connection()
    if not conn.place_order(user.user_id, address):
        __ERRORS[constants.VALIDATION_ERROR] = conn.errors()
        return False
    return True
Beispiel #3
0
def __build_detail_list_html():
    conn = Connection()
    product_list = conn.fetch_products_by_keywords(__field_keywords())
    detail_list = []
    if not product_list:
        return ""
    for product in product_list:
        detail_list.append(__details_html().format(product.code, product.descr,
                                                   product.price,
                                                   product.username,
                                                   product.entry_date))
    return ''.join([x for x in detail_list])
Beispiel #4
0
def __build_dynamic_content():
    parser = FormParser()
    parser.discover_values()
    code = parser.get_value("code", "")

    if not code or not parser.elements_count:
        return ''

    conn = Connection()
    product = conn.fetch_product_by_code(code)
    if not product:
        return ''

    return loadhtml("productdetail.html").format(product.code, product.descr, product.price, \
    product.username, product.entry_date).replace("**add_qty**", __form_add_qty_content().format(product.code) if helpers.check_user_session() else '')
Beispiel #5
0
def create_cookie(username):
    sess = session.Session(expires=365*24*60*60, cookie_path='/')
    #lastvisit = sess.data.get('lastvisit')
    #if lastvisit:
    #    message = 'Welcome back. Your last visit was at ' + \
    #        time.asctime(time.gmtime(float(lastvisit)))
    #else:
    #    message = 'New session'
    # Save the current time in the session
    conn = Connection()
    #sess.data['lastvisit'] = repr(time.time())

    date = datetime.fromtimestamp(int(sess.cookie['sid']['expires'])).strftime('%Y-%m-%d %H:%M:%S')
    conn.insert_user_cookie(sess.cookie['sid'].value, username, date)
    print("Location: index.py")
    print(sess.cookie)
    print("Content-type: text/html\n\n")
def __process_request(user):
    parser = FormParser()
    parser.discover_values()
    code = parser.get_value("code", "")
    descr = parser.get_value("descr", "")
    price = parser.get_value("price", "")
    if __validate_properties(code, descr, price):
        return False
    else:
        product = Product(0, user.user_id, code, current_date(), \
        descr, float(price) if is_float(price) else 0)

        conn = Connection()
        if not conn.create_product(product):
            __ERRORS[constants.VALIDATION_ERROR] = conn.errors()
            return False
    return True
def __process_update_cart_qty(user):
    parser = FormParser()
    parser.discover_values()
    code = parser.get_value("code", "")
    quantity = parser.get_value("quantity", "")
    if __validate_properties(user.user_id, code, quantity):
        return False
    conn = Connection()
    product = conn.fetch_product_by_code(code)
    if not product:
        __ERRORS[
            constants.
            VALIDATION_ERROR] = 'El producto no se encuentra registrado en el sistema.'
        return False
    if not conn.increase_cart_qty(
            ShoppingCart(user.user_id, product.product_id, quantity)):
        __ERRORS[constants.VALIDATION_ERROR] = conn.errors()
        return False
    return True
Beispiel #8
0
    """Validate the product properties before save it to database"""
    errorMessage = None
    if not message and not reason:
        errorMessage = 'all'
    elif not message:
        errorMessage = 'message'
    elif not reason:
        errorMessage = 'reason'
    return errorMessage


if query_string:
    parser = FormParser()
    parser.parse_values(query_string)

    conn = Connection()
    reason = parser.get_value("reason", "")
    message = parser.get_value("message", "")

    sess = session.Session(expires=365 * 24 * 60 * 60, cookie_path='/')
    #lastvisit = sess.data.get('lastvisit')
    #sess.data['lastvisit'] = repr(time.time())
    user = conn.autorized_session(sess.cookie['sid'].value)
    if user is not None and user is not '403':
        user_id = user.user_id
        name = user.username
        email = user.email
        if message and reason:
            suggestion = Suggestion(user_id, '', reason, message, name, email)
            creeateSuggestion = conn.create_suggestion(suggestion)
        else:
Beispiel #9
0
def __build_dynamic_content():
    conn = Connection()
    product_list = conn.fetch_products_by_user_id(
        request_handler.fetch_authorized_user_session().user_id)
    return loadhtml("myproducts.html").replace(
        "**details**", __build_detail_list_html(product_list))
Beispiel #10
0
sess = session.Session(expires='Thu, 01 Jan 1970 00:00:00 GMT',
                       cookie_path='/')
#lastvisit = sess.data.get('lastvisit')
#if lastvisit:
#    message = 'Welcome back. Your last visit was at ' + \
#        time.asctime(time.gmtime(float(lastvisit)))
#else:
#    message = 'New session'
# Save the current time in the session
#sess.data['lastvisit'] = repr(time.time())
#cookie_file = helpers.format_cookie_path(sess.cookie['sid'].value)
#os.remove(cookie_file)
sess.cookie['sid']['expires'] = 'Thu, 01 Jan 1970 00:00:00 GMT'

conn = Connection()
delete_cookie = conn.delete_user_history(sess.cookie['sid'].value)

for cookie in sess.cookie:
    sess.cookie[cookie]['expires'] = 'Thu, 01 Jan 1970 00:00:00 GMT'
#sess.cookie["sid"] = ''
#sess.close()
#sess.cookie.clear()
print("Location: signin.py")
print("""\
%s
Content-Type: text/plain\n
sess.cookie = %s
""" % (sess.cookie, sess.cookie))
sess.cookie.clear()
#print "Content-type: text/html\n\n"
Beispiel #11
0
def fetch_authorized_user_session():
    sess = helpers.build_session_entity()
    conn = Connection()
    return conn.autorized_session(sess.cookie['sid'].value)
Beispiel #12
0
#PACKAGE_PARENT =
__SCRIPT_DIR = os.path.dirname(
    os.path.realpath(os.path.join(os.getcwd(), os.path.expanduser(__file__))))
__SCRIPT_DIR = os.path.normpath(os.path.join(__SCRIPT_DIR, '..'))
if not __SCRIPT_DIR in sys.path:
    sys.path.append(__SCRIPT_DIR)

from data.dao import Connection
from data.models import User
from utils.helpers import FormParser, pagetemplate, valiadtionMessage, ucgiprint, loadhtml
from utils import constants, helpers

if helpers.request_method() == 'GET' and helpers.check_user_session():
    helpers.redirect('index.py')

__CONN = Connection()
__ERRORS = {}
__BODY = {}


def __validate_properties(name, username, password, email):
    """Validate the product properties before save it to database"""
    helpers.validate_string_input('name', name, 50, 'Nombre', __ERRORS, False)
    helpers.validate_string_input('username', username, 50, 'Usuario',
                                  __ERRORS)
    helpers.validate_string_input('email', email, 50, 'Correo', __ERRORS)
    helpers.validate_string_input('password', password, None, 'Contraseña',
                                  __ERRORS)
    return __ERRORS

Beispiel #13
0
    if not name and not message and not email:
        errorMessage = 'all'
    elif not name:
        errorMessage = 'name'
    elif not message:
        errorMessage = 'message'
    elif not email:
        errorMessage = 'email'
    return errorMessage


if query_string:
    parser = FormParser()
    parser.parse_values(query_string)

    conn = Connection()
    name = parser.get_value("name", "")
    reason = parser.get_value("reason", "")
    message = parser.get_value("message", "")
    email = parser.get_value("email", "")
    random = parser.get_value("random", "")
    captcha = parser.get_value("captcha", "")

    user_id = None
    if name and message and email:
        valid_captcha = validate_captcha(captcha, random)
        if valid_captcha:
            suggestion = Suggestion(user_id, '', reason, message, name, email)
            creeateSuggestion = conn.create_suggestion(suggestion)
    else:
        result = validate_properties()
Beispiel #14
0
def __build_dynamic_content():
    conn = Connection()
    results = conn.fetch_cart_products_by_user_id(request_handler.fetch_authorized_user_session().user_id)
    subtotal = sum(c.total() for c in results)
    return loadhtml("cart.html").replace("**details**", __build_detail_list_html(results)) \
    .replace("**subtotal**", str(subtotal))
Beispiel #15
0
if helpers.request_method() == 'GET' and helpers.check_user_session():
    helpers.redirect('index.py')

user = False
err = False
username = None
password = None
htmlerror = ''
result = None
query_string = ''
if helpers.request_method() == 'POST':
    query_string = sys.stdin.read(
    )  # reads the parameters, username=xxx&password=xxx
    sys.stdout.flush()
__RESULT = False
conn = Connection()


def createSession():
    create_cookie(username)
    #print "Location: cookie.py"


def validate_properties():
    """Validate the product properties before save it to database"""
    errorMessage = None
    if not username and not password:
        errorMessage = 'all'
    elif not username:
        errorMessage = 'user'
    elif not password: