def create_lti_user(lti_user_id, lti_consumer): """ Generate a new user on the edX platform with a random username and password, and associates that account with the LTI identity. """ edx_password = str(uuid.uuid4()) created = False while not created: try: edx_user_id = generate_random_edx_username() edx_email = "{}@{}".format(edx_user_id, settings.LTI_USER_EMAIL_DOMAIN) edx_user = User.objects.create_user( username=edx_user_id, password=edx_password, email=edx_email, ) # A profile is required if PREVENT_CONCURRENT_LOGINS flag is set. # TODO: We could populate user information from the LTI launch here, # but it's not necessary for our current uses. edx_user_profile = UserProfile(user=edx_user) edx_user_profile.save() created = True except IntegrityError: # The random edx_user_id wasn't unique. Since 'created' is still # False, we will retry with a different random ID. pass lti_user = LtiUser(lti_consumer=lti_consumer, lti_user_id=lti_user_id, edx_user=edx_user) lti_user.save() return lti_user
def create_lti_user(lti_user_id, lti_consumer): """ Generate a new user on the edX platform with a random username and password, and associates that account with the LTI identity. """ edx_password = str(uuid.uuid4()) created = False while not created: try: edx_user_id = generate_random_edx_username() edx_email = "{}@{}".format(edx_user_id, settings.LTI_USER_EMAIL_DOMAIN) edx_user = User.objects.create_user( username=edx_user_id, password=edx_password, email=edx_email, ) # A profile is required if PREVENT_CONCURRENT_LOGINS flag is set. # TODO: We could populate user information from the LTI launch here, # but it's not necessary for our current uses. edx_user_profile = UserProfile(user=edx_user) edx_user_profile.save() created = True except IntegrityError: # The random edx_user_id wasn't unique. Since 'created' is still # False, we will retry with a different random ID. pass lti_user = LtiUser( lti_consumer=lti_consumer, lti_user_id=lti_user_id, edx_user=edx_user ) lti_user.save() return lti_user
def create_lti_user(lti_user_id, lti_consumer): """ Generate a new user on the edX platform with a random username and password, and associates that account with the LTI identity. """ edx_password = str(uuid.uuid4()) created = False while not created: try: edx_user_id = generate_random_edx_username() edx_user = User.objects.create_user( username=edx_user_id, password=edx_password, email='{}@lti.example.com'.format(edx_user_id) ) edx_user.save() created = True except IntegrityError: # The random edx_user_id wasn't unique. Since 'created' is still # False, we will retry with a different random ID. pass lti_user = LtiUser( lti_consumer=lti_consumer, lti_user_id=lti_user_id, edx_user=edx_user ) lti_user.save() return lti_user
def create_lti_user_model(self): """ Generate and save a User and an LTI user model """ edx_user = User(username=self.edx_user_id) edx_user.save() lti_user = LtiUser(lti_consumer=self.lti_consumer, lti_user_id=self.lti_user_id, edx_user=edx_user) lti_user.save() return lti_user
def create_lti_user_model(self): """ Generate and save a User and an LTI user model """ edx_user = User(username=self.edx_user_id) edx_user.save() lti_user = LtiUser( lti_consumer=self.lti_consumer, lti_user_id=self.lti_user_id, edx_user=edx_user ) lti_user.save() return lti_user