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())
from db.mongodb.connection import Connection from datetime import date from sweetscomplete.entity.customer import Customer from sweetscomplete.domain.customer import CustomerService from sweetscomplete.authenticate.auth import SimpleAuth # seed for random password generation abc = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz~!@#$%^&*()_+=-{}|[];:<>?,.' length = len(abc) - 1 # open CSV file f = open('sweetscomplete_customers_passwords.csv', 'w') # setting up the connection + collection + auth conn = Connection('localhost', 27017, Customer) service = CustomerService(conn, 'sweetscomplete') auth = SimpleAuth(service, os.path.realpath('.')) # running a query all customers print("\nResetting all passwords") for doc in service.fetchAll(): print('Processing: ' + doc.getFullName() + ' [' + doc.getKey() + ']') newPass = '' # generate random password pos = random.randint(0, length) newPass += abc[pos:pos + 1] newPass += str(random.randint(0, 99)) pos = random.randint(0, length) newPass += abc[pos:pos + 1]
import os, sys sys.path.append(os.path.realpath("src")) import pprint import db.mongodb.connection test = Customer() from datetime import date from sweetscomplete.entity.customer import Customer from sweetscomplete.domain.customer import CustomerService # setting up the connection + collection conn = db.mongodb.connection.Connection() service = CustomerService(conn, 'sweetscomplete') # initialize test data key = '00000000000' doc = '''\ { "customerKey" : "%key%", "PrimaryContactInfo": { "firstName" : "Fred", "lastName" : "Flintstone", "phoneNumber" : "+0-000-000-0000", "email" : "*****@*****.**", "socialMedia": { "GO": { "label": "google", "url": "https:\/\/google.com\/fflintstone"
# custom imports from config.config import Config from web.responder.html import HtmlResponder from web.auth import SimpleAuth 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
# sweetscomplete.entity.customer.Customer read/add/edit/delete # tell python where to find module source code import os, sys sys.path.append(os.path.realpath("src")) import pprint import db.mongodb.connection from datetime import date from sweetscomplete.entity.customer import Customer from sweetscomplete.domain.customer import CustomerService # setting up the connection + collection conn = db.mongodb.connection.Connection('localhost', 27017, Customer) service = CustomerService(conn, 'sweetscomplete') # initialize test data key = '00000000000' doc = '''\ { "customerKey" : "%key%", "firstName" : "Fred", "lastName" : "Flintstone", "phoneNumber" : "+0-000-000-0000", "email" : "*****@*****.**", "socialMedia": { "GO": { "label": "google", "url": "https:\/\/google.com\/fflintstone" },