def create_user(username=None, email=None, password=None, role=None, enabled=True): if not username or not password or not role: raise NameError('You must specify a username, password, and role') db = application.get_db_connection() user_key = schema.USER_KEY.format(username) data = schema.user(username=username, email=email, \ password=encrypt_password(password, settings.SECRET_KEY), \ role=role, enabled=enabled) db.set(user_key, json.dumps(data)) return True
def create_user(username=None, email=None, password=None, role=None, enabled=True): if not username or not password or not role: raise NameError('You must specify a username, password, and role') db = application.get_db_connection() # check for existing if list(db.users.find({'username': username})): raise RuntimeError('An account with that username already exists') data = schema.user(username=username, email=email, \ password=encrypt_password(password, settings.SECRET_KEY), \ role=role, enabled=enabled) db.users.insert(data) return True
def create(data, createStreams=True): """ Create a new user. Parameters: data - a dictionary containing the new user's data. createStreams - defaults to True. If True, will generate the user's public, private, and message streams. """ db = core.connect() data["joined"] = utils.utctime() newUser = schema.user() newUser.update(data) newUser["type"] = "user" userId = db.create(newUser) userRef = ref(userId) # create public stream for user # for when the user publishes her/his own content publicStream = stream.create({ "objectRef": userRef, "uniqueName": ref(userId,"public"), "private": False, "meta": "public", "createdBy": userId }, False) # private stream for when shifts are sent directly to a user privateStream = stream.create({ "objectRef": userRef, "uniqueName": ref(userId,"private"), "private": True, "meta": "private", "createdBy": userId }, False) # create the message stream for the user messageStream = stream.create({ "objectRef": userRef, "uniqueName": ref(userId, "messages"), "private": True, "meta": "message", "createdBy": userId }, False) theUser = db[userId] theUser.update({ "messageStream": messageStream["_id"], "publicStream": publicStream["_id"], "privateStream": privateStream["_id"] }) db[userId] = theUser return db[userId]