def addUser(): email = raw_input("Email: ").decode("utf-8").strip() if not email: print "You must give an email address." return addUser() password = _getPassword().decode("utf-8") hasher = config.get('hashPassword') if hasher is not None: password = hasher(password) roleNames = raw_input("Roles (space-separated):").split() av = avatar.Avatar() av.email = email av.password = password avatar_store.add(av) for (position, roleName) in enumerate(roleNames): role = avatar.AvatarRole() role.avatar = av role.role_name = roleName role.position = position avatar_store.add(role) avatar_store.commit()
def setupStore(): avatar_store.__init__(create_database(config['db'])) if config.get('trace'): import sys from storm.tracer import debug debug(True, stream=sys.stdout) # Only sqlite uses this now sqlBundle = getCreationSQL(avatar_store) if not sqlBundle: return tableExists = sql['tableExists'] = sqlBundle['tableExists'] for (table, creationSQL) in sqlBundle['creations']: if not tableExists(avatar_store, table): # Unlike log.message, this works during startup print "~~~ Creating Warp table '%s'" % table if not isinstance(creationSQL, tuple): creationSQL = [creationSQL] for sqlCmd in creationSQL: avatar_store.execute(sqlCmd) avatar_store.commit()
def __storm_flushed__(self): avatar_store.execute(DELETE_SQL, (self.__class__.__name__, self.id)) if get_obj_info(self).get("store") is not None: vals = [v for v in self.getSearchVals() if v is not None] if vals: text = self._searchSeparator.join(vals).encode("utf-8") avatar_store.execute(INSERT_SQL, (self.__class__.__name__, self.id, self.getSearchLanguage(), text)) avatar_store.commit()
def finish(self): rv = Request.finish(self) avatar_store.rollback() avatar_store.commit() # Some requests, like those for static files, don't have store store = getattr(self, 'store', None) if store: # Roll back and then commit, so that no transaction # is left open between requests. if store is not avatar_store: store.rollback() store.commit() # Some use cases involve setting store.request in # getRequestStore, so remove request.store here to # avoid a circular reference GC. del self.store return rv
def setupStore(): avatar_store.__init__(create_database(config['db'])) if config.get('trace'): import sys from storm.tracer import debug debug(True, stream=sys.stdout) sqlBundle = getCreationSQL(avatar_store) tableExists = sql['tableExists'] = sqlBundle['tableExists'] for (table, creationSQL) in sqlBundle['creations']: if not tableExists(avatar_store, table): # Unlike log.message, this works during startup print "~~~ Creating Warp table '%s'" % table if not isinstance(creationSQL, tuple): creationSQL = [creationSQL] for sqlCmd in creationSQL: avatar_store.execute(sqlCmd) avatar_store.commit()
def ok(result, request): print >>config["log"], "Ok ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" data = json.loads(result) print >>config["log"], result if data.get("status") == "okay": email = uni(data.get("email")) avatar = avatar_store.find(Avatar, email = email).one() if not avatar: avatar = Avatar() avatar.email = email avatar_store.add(avatar) avatar_store.commit() request.session.setAvatarID(avatar.id) request.avatar = request.session.avatar return { "success": True, "data": data } else: raise Exception("Login failed")