Ejemplo n.º 1
0
def load(**args):
    """load an existing sesion from cookies or start a new guest session"""
    from lib.chai import req, res

    if 'sid' in req.cookies and req.cookies['sid'] != 'guest':
        sess = objstore.get(type='session', name=req.cookies['sid'])
        if sess:
            sess['userobj'] = objstore.get(type='user', name=sess['user'])
            return sess

    # no session, start a new one as guest (no need to save)
    sess = dict(type='session', name='guest', user='******')
    return sess
Ejemplo n.º 2
0
def load(**args):
	"""load an existing sesion from cookies or start a new guest session"""
	from lib.chai import req, res
		
	if 'sid' in req.cookies and req.cookies['sid']!='guest':
		sess = objstore.get(type='session', name=req.cookies['sid'])
		if sess:
			sess['userobj'] = objstore.get(type='user', name=sess['user'])
			return sess
	
	# no session, start a new one as guest (no need to save)
	sess = dict(type='session', name='guest', user='******')	
	return sess
Ejemplo n.º 3
0
	def test_update_with_children(self):
		objstore.insert(type="user", name="testuser", userrole=['Admin', 'Manager'])
		objstore.update(type="user", name="testuser", userrole=['Admin', 'MX'])
		obj = objstore.get(type="user", name="testuser")
		self.assertTrue('Admin' in obj['userrole'])
		self.assertFalse('Manager' in obj['userrole'])
		self.assertTrue('MX' in obj['userrole'])
Ejemplo n.º 4
0
	def test_insert(self):
		objstore.insert(type='page', name='r1')
		objstore.insert(type='page', parent='r1', name='p1', idx=0)
		objstore.insert(type='page', parent='r1', name='p2', idx=1)

		rebuild('page')

		r1 = objstore.get(type='page', name='r1')
		p1 = objstore.get(type='page', name='p1')
		p2 = objstore.get(type='page', name='p2')
	
		self.assertEquals(r1['lft'], 1)
		self.assertEquals(p1['lft'], 2)
		self.assertEquals(p1['rgt'], 3)
		self.assertEquals(p2['lft'], 4)
		self.assertEquals(p2['rgt'], 5)
		self.assertEquals(r1['rgt'], 6)
Ejemplo n.º 5
0
 def test_update_with_children(self):
     objstore.insert(type="user",
                     name="testuser",
                     userrole=['Admin', 'Manager'])
     objstore.update(type="user", name="testuser", userrole=['Admin', 'MX'])
     obj = objstore.get(type="user", name="testuser")
     self.assertTrue('Admin' in obj['userrole'])
     self.assertFalse('Manager' in obj['userrole'])
     self.assertTrue('MX' in obj['userrole'])
Ejemplo n.º 6
0
def forgot_password(**args):
	"""email the user with a unique link to generate the password"""	
	user = db.sql("""select name from user where name=%s or email=%s""", (args['email'], args['email']))
	if not user:
		return 'No such user'
		
	userobj = model.get(objstore.get(type="user", name=user[0]['name']))
	userobj.request_reset_password()
	return 'ok'
Ejemplo n.º 7
0
def forgot_password(**args):
    """email the user with a unique link to generate the password"""
    user = db.sql("""select name from user where name=%s or email=%s""",
                  (args['email'], args['email']))
    if not user:
        return 'No such user'

    userobj = model.get(objstore.get(type="user", name=user[0]['name']))
    userobj.request_reset_password()
    return 'ok'
Ejemplo n.º 8
0
def content(**args):
	"""get page html with header and footer"""
	obj = objstore.get(type='page', name=args.get('name', 'index'))
	
	if not 'html' in obj:
		obj['html'] = """<h1>Not Found</h1><p>This link is not active. 
			<a href="#index">Go back to Home Page</a></p>"""
		
	return {'html': header(obj) + obj["html"] + footer(obj), 
		'js': obj.get('js', ''), 'css':obj.get('css', '')}
Ejemplo n.º 9
0
	def test_get(self):
		obj = dict(type="user", name="testuser", email="testmail", fullname="Test User")
		objstore.insert(**obj)
		obj1 = objstore.get(type="user", name="testuser")
		# clear nulls
		del obj1['_updated']
		for key in obj1.keys():
			if not obj1[key]: 
				del obj1[key]
		self.assertEquals(obj, obj1)
Ejemplo n.º 10
0
	def test_new(self):
		self.test_insert()
		objstore.insert(type='page', name='p11', parent='p1')

		rebuild('page')

		r1 = objstore.get(type='page', name='r1')
		p1 = objstore.get(type='page', name='p1')
		p2 = objstore.get(type='page', name='p2')
		p11 = objstore.get(type='page', name='p11')

		self.assertEquals(r1['lft'], 1)
		self.assertEquals(p1['lft'], 2)
		self.assertEquals(p11['lft'], 3)
		self.assertEquals(p11['rgt'], 4)
		self.assertEquals(p1['rgt'], 5)
		self.assertEquals(p2['lft'], 6)
		self.assertEquals(p2['rgt'], 7)
		self.assertEquals(r1['rgt'], 8)
Ejemplo n.º 11
0
 def test_vector(self):
     obj = dict(type="user",
                name="testuser",
                email="testmail",
                fullname="Test User")
     objstore.insert(type="user",
                     name="testuser",
                     userrole=['Admin', 'Manager'])
     obj1 = objstore.get(type="user", name="testuser")
     self.assertTrue('Admin' in obj1['userrole'])
     self.assertTrue('Manager' in obj1['userrole'])
Ejemplo n.º 12
0
def content(**args):
    """get page html with header and footer"""
    obj = objstore.get(type='page', name=args.get('name', 'index'))

    if not 'html' in obj:
        obj['html'] = """<h1>Not Found</h1><p>This link is not active. 
			<a href="#index">Go back to Home Page</a></p>"""

    return {
        'html': header(obj) + obj["html"] + footer(obj),
        'js': obj.get('js', ''),
        'css': obj.get('css', '')
    }
Ejemplo n.º 13
0
 def test_get(self):
     obj = dict(type="user",
                name="testuser",
                email="testmail",
                fullname="Test User")
     objstore.insert(**obj)
     obj1 = objstore.get(type="user", name="testuser")
     # clear nulls
     del obj1['_updated']
     for key in obj1.keys():
         if not obj1[key]:
             del obj1[key]
     self.assertEquals(obj, obj1)
Ejemplo n.º 14
0
def login(**args):
	"""login"""
	from lib.chai import res
	
	import hashlib
	pwd = db.sql("select password from user where name=%s", (args['user'],))
	if pwd: 
		pwd = pwd[0]['password']
	
	if pwd == hashlib.sha256(args.get("password")).hexdigest():
		d = dict(type='session', name=new_sid(), user=args['user'])
		objstore.insert(**d)
		res.set_cookie('sid', d['name'])
		d.update({"message":"ok", "userobj":objstore.get(type='user', name=args['user'])})
		return d
	else:
		return {"error":"Invalid Login"}
Ejemplo n.º 15
0
def login(**args):
    """login"""
    from lib.chai import res

    import hashlib
    pwd = db.sql("select password from user where name=%s", (args['user'], ))
    if pwd:
        pwd = pwd[0]['password']

    if pwd == hashlib.sha256(args.get("password")).hexdigest():
        d = dict(type='session', name=new_sid(), user=args['user'])
        objstore.insert(**d)
        res.set_cookie('sid', d['name'])
        d.update({
            "message": "ok",
            "userobj": objstore.get(type='user', name=args['user'])
        })
        return d
    else:
        return {"error": "Invalid Login"}
Ejemplo n.º 16
0
 def test_update(self):
     self.test_insert()
     objstore.update(type="user", name="testuser", email="testmail2")
     objstore.get(type="user", name="testuser")['email'] == 'testmail2'
Ejemplo n.º 17
0
	def test_vector(self):
		obj = dict(type="user", name="testuser", email="testmail", fullname="Test User")
		objstore.insert(type="user", name="testuser", userrole=['Admin', 'Manager'])
		obj1 = objstore.get(type="user", name="testuser")
		self.assertTrue('Admin' in obj1['userrole'])
		self.assertTrue('Manager' in obj1['userrole'])
Ejemplo n.º 18
0
	def test_update(self):
		self.test_insert()
		objstore.update(type="user", name="testuser", email="testmail2")
		objstore.get(type="user", name="testuser")['email']=='testmail2'