コード例 #1
0
from sweetscomplete.entity.product import Product
from sweetscomplete.entity.product_purchased import ProductPurchased
from sweetscomplete.domain.purchase import PurchaseService
from sweetscomplete.entity.purchase import Purchase

# create CustomerService instance
cust_conn = Connection('localhost', 27017, Customer)
cust_service = CustomerService(cust_conn, 'sweetscomplete')
prod_conn = Connection('localhost', 27017, Product)
prod_service = ProductService(prod_conn, 'sweetscomplete')
purch_conn = Connection('localhost', 27017, Purchase)
purch_service = PurchaseService(purch_conn, 'sweetscomplete')

# init vars
sess_storage = os.path.realpath("../data")
auth = SimpleAuth(cust_service, sess_storage)
cust = auth.getIdentity()
html_out = Html('templates/purchase.html')

# go to login page if not authenticated
if not cust:
    print("Location: /chapter_05/index.py\r\n")
    print()
    quit()

# check for form posting
import cgi

form = cgi.FieldStorage()

if 'purchase' in form:
コード例 #2
0
from web.responder import Html
html_out = Html('templates/index.html')

# check for form posting
import cgi
form = cgi.FieldStorage()
if 'username' in form and 'password' in form:
    # pull username and pasword
    username = form['username'].value
    password = form['password'].value
    # do imports for authentication
    from web.auth import SimpleAuth
    from db.mongodb.connection import Connection
    from sweetscomplete.domain.customer import CustomerService
    from sweetscomplete.entity.customer import Customer
    # create CustomerService instance
    conn = Connection('localhost', 27017, Customer)
    cust_service = CustomerService(conn, 'sweetscomplete')
    # perform simple auth
    auth = SimpleAuth(cust_service, sess_storage)
    if auth.authenticate(username, password):
        success = True
        html_out.addHeader('Set-Cookie: token=' + auth.getToken() + ';path=/')
        message = "<b>HOORAY!  Successful Login.</b>"
    else:
        message = "<b>SORRY!  Unable to Login.</b>"

# output login form + message
html_out.addInsert('%message%', message)
print(html_out.render())
コード例 #3
0
from db.mongodb.connection import Connection
from sweetscomplete.domain.customer import CustomerService
from sweetscomplete.entity.customer import Customer
from sweetscomplete.domain.product import ProductService
from sweetscomplete.entity.product import Product

# create CustomerService instance
config       = Config()
db_config    = config.getConfig('db')
cust_conn    = Connection(db_config['host'], db_config['port'], Customer)
cust_service = CustomerService(cust_conn, db_config['database'])
prod_conn    = Connection(db_config['host'], db_config['port'], Product)
prod_service = ProductService(prod_conn, db_config['database'])

# init vars
auth     = SimpleAuth(cust_service, config.getConfig('session_storage'))
cust     = auth.getIdentity()

# HTML output
response = HtmlResponder('templates/select.html')
response.addInsert('%message%', '<br>')
response.addInsert('%ajax_url%', config.getConfig('ajax_url'))

# output
if cust :
    # display customer name
    response.addInsert('%name%', cust.getFullName())
else :
    response.addInsert('%name%', 'guest')

print(response.render())