def create_user(full_name="", birthday=arrow.get(586162800), config=None, username=None, password=None, email_addr=None, user_id=None, verified=True): """ Creates a new user and profile, and returns the user ID. """ if username is None: username = "******" + str(next(_user_index)) while True: user = add_entity( users.Login(login_name=get_sysname(username), last_login=arrow.get(0).datetime)) if user.userid not in staff.MODS and user.userid not in staff.DEVELOPERS: break db = d.connect() db.delete(user) db.flush() add_entity( users.Profile(userid=user.userid, username=username, full_name=full_name, created_at=arrow.get(0).datetime, config=config)) add_entity(users.UserInfo(userid=user.userid, birthday=birthday)) # Verify this user if verified: d.engine.execute( "UPDATE login SET voucher = userid WHERE userid = %(id)s", id=user.userid) # Set a password for this user d.engine.execute("INSERT INTO authbcrypt VALUES (%(id)s, %(bcrypthash)s)", id=user.userid, bcrypthash=_DEFAULT_PASSWORD if password is None else login.passhash(password)) # Set an email address for this user if email_addr is not None: d.engine.execute( "UPDATE login SET email = %(email)s WHERE userid = %(id)s", email=email_addr, id=user.userid) # Force the userID to a user-defined value and return it if user_id is not None: d.engine.execute( "UPDATE login SET userid = %(newid)s WHERE userid = %(oldid)s", newid=user_id, oldid=user.userid) return user_id return user.userid
def user_with_age(age): """ Create a Login, UserInfo, and Profile with the provided age. Note that the new model objects are not added to the session. Returns: Login: The user Login object created. """ birthday = arrow.get(datetime.datetime.utcnow() - relativedelta(years=age)) login_name = 'user%d' % next(_user_counter) return users.Login(info=users.UserInfo(birthday=birthday), profile=users.Profile(username=login_name, full_name=login_name, created_at=arrow.get(0).datetime), last_login=arrow.get(0).datetime, login_name=login_name)
def create_user(full_name="", birthday=arrow.get(586162800), config=None, username=None): """ Creates a new user and profile, and returns the user ID. """ if username is None: username = "******" + str(next(_user_index)) user = add_entity( users.Login(login_name=legacy.login_name(username), last_login=arrow.get(0))) add_entity( users.Profile(userid=user.userid, username=username, full_name=full_name, unixtime=arrow.get(0), config=config)) add_entity(users.UserInfo(userid=user.userid, birthday=birthday)) return user.userid
def create_user(full_name="", birthday=arrow.get(586162800), config=None, username=None, password=None, email_addr=None, user_id=None): """ Creates a new user and profile, and returns the user ID. """ if username is None: username = "******" + str(next(_user_index)) user = add_entity( users.Login(login_name=legacy.login_name(username), last_login=arrow.get(0))) add_entity( users.Profile(userid=user.userid, username=username, full_name=full_name, unixtime=arrow.get(0), config=config)) add_entity(users.UserInfo(userid=user.userid, birthday=birthday)) # Set a password for this user if password is not None: d.engine.execute( "INSERT INTO authbcrypt VALUES (%(id)s, %(bcrypthash)s)", id=user.userid, bcrypthash=login.passhash(password)) # Set an email address for this user if email_addr is not None: d.engine.execute( "UPDATE login SET email = %(email)s WHERE userid = %(id)s", email=email_addr, id=user.userid) # Force the userID to a user-defined value and return it if user_id is not None: d.engine.execute( "UPDATE login SET userid = %(newid)s WHERE userid = %(oldid)s", newid=user_id, oldid=user.userid) return user_id return user.userid