def create(cls, username, auth_id, **kwargs): #def create(cls, username, auth_id, profile_url, profile_image_url, **kwargs): """Creates a new user and returns it. If the username already exists, returns None. :param username: Unique username. :param auth_id: Authentication id, according the the authentication method used. :param kwargs: Additional entity attributes. :returns: The newly created user or None if the username already exists. """ kwargs['username'] = username kwargs['key_name'] = username now = datetime.datetime.now() kwargs['access_token_expires'] = now + datetime.timedelta(seconds=int(kwargs['expires_seconds'])) #kwargs['profile_url'] = profile_url #kwargs['profile_image_url'] = profile_image_url kwargs['domain'] = auth_id.split('|')[0] kwargs['auth_id'] = auth_id # Generate an initial session id. kwargs['session_id'] = gen_salt(length=32) kwargs['friend_ids'] = [] if 'password_hash' in kwargs: # Password is already hashed. kwargs['password'] = kwargs.pop('password_hash') elif 'password' in kwargs: # Password is not hashed: generate a hash. kwargs['password'] = gen_pwhash(kwargs['password']) config = Config.get_for_current_environment() def txn(): if cls.get_by_username(username) is not None: # Username already exists. return None user = cls(**kwargs) character = Character.create(config=config, user=user, image_url=user.profile_image_url, is_fake=False) user.character = character db.put((user, character)) return user return db.run_in_transaction(txn)
def get_game_config(self): return Config.get_for_current_environment()