def test_saveEmptySession(self):
     d = DatabaseManagerMock()
     s = Session(d)
     s.save()
     self.assertTrue(
         isinstance(d.get_dict(), dict),
         "When make_new_values of the database manager was called, we did not get an empty dict.",
     )
     self.assertEquals(len(d.get_dict()), 0)
    def test_saveEmptySession(self):
        d = DatabaseManagerMock()
        s = Session(d,1)

        a = d.get_dict()
        a["ok"] = "ok"
        
        s.save()
        self.assertTrue(isinstance(d.get_dict(),dict))
        self.assertEquals(len(d.get_dict()), 2)
示例#3
0
def main():
    urls = ('/', 'HomePage', '/push/rev', 'RevScanData', '/items', 'ShowData',
            '/idact', 'id_for_Update', '/stact', 'state_for_Update',
            '/api/logincy', 'getToken', '/api/content', 'trans_content',
            '/api/weakness', 'trans_weakness', '/api/getTimeInterval',
            'getTimeInterval')
    app = application(urls, globals())
    app.internalerror = debugerror

    if web.config.get('_session') is None:
        ds = init_ds()
        session = Session(app, ds)
        web.config._session = session

    if web.config.get('_render') is None:
        render = template.render('templates', globals={'context': session})
        web.config._render = render

    if web.config.get('_cookies') is None:
        cookies = cookielib.CookieJar()
        web.config._cookies = cookies

    if web.config.get('_opener') is None:
        opener = init_opener(web.config._cookies)
        web.config._opener = opener

    if web.config.get('_rev') is None:
        web.config._rev = {}

    app.wsgifunc(StaticMiddleware)
    return app
示例#4
0
 def __init__(self, app, store, initializer=None):
     Session.__init__(self, app, store, initializer)
示例#5
0
web.config.debug = False
render = render_jinja('templates', 'utf-8')

urls = (
	'/api/', 'API',
	'/', 'Index',
	'/upload/', 'Upload',
	'/error/', 'Error',
	'/nocookie/', 'Nocookie',
	'/results/','Results',
	'/compare/','Compare',
)

app = web.application(urls, locals())

session = Session(app, DiskStore("sessions"))

class Index:
	def GET(self):
		session.test = "testcookie";
		return render.index()

class Upload:
	def GET(self):
		if session.get('test')!='testcookie':
			raise web.seeother('/nocookie/')
		return render.post_file()
	def POST(self):
		textfile = web.input(text={}).text
		if textfile.type == 'text/plain' and textfile.filename[-3:]=='txt':
			session.data = genwordcount(textfile)
示例#6
0
 def __init__(self, app, store, initializer=None):
     Session.__init__(self,app,store,initializer)
示例#7
0
 def __init__(self, service, baseDir) :
     self.service  = service
     self.session = Session(baseDir)
示例#8
0
class SimpleAuth :

    service     = None
    session     = None
    custSessKey = 'custKey'
    identity    = None

    """
    @param sweetscomplete.domain.customer.CustomerService service
    @param string baseDir
    """
    def __init__(self, service, baseDir) :
        self.service  = service
        self.session = Session(baseDir)

    def getSession(self) :
        return self.session

    """
    @param string email
    @param string password : plain text
    """
    def authByEmail(self, email, password) :
        success  = False
        customer = self.service.fetchByEmail(email)
        if customer :
            pwd_db   = customer.get('password')
            pwd_form = password
            success = bcrypt.checkpw(pwd_form.encode('utf-8'), pwd_db.encode('utf-8'))
        return customer if success else False

    """
    @param string password : plain text
    @return string hashed password
    """
    def genHash(self, password) :
        newPass = bcrypt.hashpw(bytes(password),bcrypt.gensalt())
        return newPass

    """
    @return string token
    """
    def getToken(self) :
        return self.session.getToken()

    """
    @return False | Customer : customer entity restored from JSON
    """
    def getIdentity(self) :
        if not self.session.getToken() :
            return False
        if not self.identity :
            custKey = self.session.getSessInfoByKey(self.custSessKey)
            # lookup customer info
            self.identity = self.service.fetchByKey(custKey)
        return self.identity

    """
    @param string email
    @param string password : plain text
    @return False | Customer : customer entity restored from JSON
    """
    def authenticate(self, email, password) :
        cust = self.authByEmail(email, password)
        # if auth is successful, get token, and store customer info in authfile
        if (cust) :
            # generate token
            token = self.session.genToken()
            # store customer key in session file
            return self.session.setSessInfoByKey(self.custSessKey, cust.getKey())
        else :
            return False
示例#9
0
 def __init__(self, app, store, init):
     Session.__init__(self, app, store, init)