def save(self, storage=None): " Save object to redis storage" if self.embedded: logging.warning('You should save embedded objects with high level object') return if not self.id: new_id = RedisConn.incr(mkey(REDIS_NAMESPACE, self.__class__.__name__.lower() + '_key')) if self.__salt__: self.id = hashlib.md5(str(new_id) + self.__salt__).hexdigest() else: self.id = new_id RedisConn.set(mkey(REDIS_NAMESPACE, self.collection_name, self.id), json.dumps(self.__instdict__)) if self.expire != None: RedisConn.expire(mkey(REDIS_NAMESPACE, self.collection_name, self.id), self.expire)
def index(request,room=None): authck = request.cookies.get('auth') logging.info('current auth cookie is %s (%s)'%(authck,RedisConn.get('auth.%s'%authck))) setauthck=None if not authck or not RedisConn.get('auth.%s'%authck): un = request.params.get('username','') pw = request.params.get('password','') err='' if un: u = getuser(un) if u: logging.info('user exists') u = u[0] hpw = hashlib.md5(pw).hexdigest() #raise Exception('comparing %s with %s'%(u,hpw)) if u['password']==hpw: logging.info('generating auth cookie') setauthck = ''.join(random.choice('abcdefghijklmnopqrstuvwxyz') for i in xrange(16)) else: err='invalid login' else: logging.info('creating new user') user={'id':un,'password':hashlib.md5(pw).hexdigest()} users.append(user) saveusers() err='user %s created succesfully. please log in'%un context = {'username':un,'password':pw,'err':err} rtpl='auth.html' else: rtpl='index.html' global rooms if room: openrooms = room.split(',') else: openrooms = [] openrooms = [getroom(rn) for rn in openrooms if rn[0]!='@'] context = {'rooms':json.dumps(rooms),'openrooms':json.dumps(openrooms),'user':RedisConn.get('auth.%s'%authck),'authck':authck,'rowlimit':ROWLIMIT} rendered_page = render_to_string(rtpl, context, request) rsp= Response(rendered_page) if setauthck: RedisConn.set('auth.%s'%setauthck,un) logging.info('setting auth cookie = %s (redis value = %s)'%(setauthck,RedisConn.get('auth.%s'%setauthck))) rsp = Redirect('/') rsp.set_cookie('auth',setauthck) return rsp