def handle(self, *args, **options): slug = options['slug'] try: institution = Institution.objects.get(slug=slug) except Institution.DoesNotExist: raise CommandError("No institution with slug '%s' exists." % slug) message = ( "This command is intended to migrate projects " "previously using CAS for authentication to using Uniauth.\n\nYou " "should only proceed with this command if your project was " "previously using CAS for authentication, and the usernames for " "all existing Users are equivalent to their CAS ID. This command " "will create UserProfiles for each user with the Institution " "specified by the slug argument.\n\nDo you still wish to " "continue?\n\nAnswer [y/n]: ") answer = get_input(message) if answer != "y" and answer != "yes": self.stdout.write("\nCanceled.\n") return self.stdout.write("\nProceeding... ") for user in get_user_model().objects.all(): # Skip users that already have UserProfiles if hasattr(user, "uniauth_profile"): continue # Update the username to the proper format cas_id = user.username user.username = "******" % (slug, cas_id) user.save() # Add the profile profile = UserProfile.objects.create(user=user) self.stdout.write("Done!\n")
def handle(self, *args, **options): message = ("This command is intended to migrate projects " "previously using custom User authentication to using Uniauth.\n\n" "You should only proceed with this command if your project had " "users sign up with a username / email address and password. This " "command will create UserProfile for each user with a username or " "email address, and a non-blank password. A verified LinkedEmail " "will also be created if the email field is non-blank.\n\n" "Do you still wish to continue?\n\nAnswer [y/n]: ") answer = get_input(message) if answer != "y" and answer != "yes": self.stdout.write("\nCanceled.\n") return self.stdout.write("\nProceeding... ") skipped = [] for user in get_user_model().objects.all(): # Skip users that already have UserProfiles if hasattr(user, "uniauth_profile"): continue # Skip users lacking a username/email address or password if (not user.username and not user.email) or not user.password: skipped.append(user.username or user.email or "(none)") continue # Add the profile + LinkedEmail if email field is non-blank profile = UserProfile.objects.create(user=user) if user.email: LinkedEmail.objects.create(profile=profile, address=user.email, is_verified=True) self.stdout.write("Done!\n") if len(skipped) > 0: self.stdout.write("\nThe following users could not be " + "migrated: %s\n" % str(skipped))
def handle(self, *args, **options): days = options['days'] answer = get_input("Are you sure you want to delete all temporary" + "users more than %d days old?\nAnswer [y/n]:" % days) if answer == "y" or answer == "yes": num_deleted = flush_old_tmp_users(days=days) self.stdout.write("Deleted %d temporary users.\n") else: self.stdout.write("Canceled.\n")
def handle(self, *args, **options): slug = options['slug'] try: institution = Institution.objects.get(slug=slug) except Institution.DoesNotExist: raise CommandError("No institution with slug '%s' exists." % slug) answer = get_input("Are you sure you want to delete institution '" + str(institution) +"'?\nThis will also delete all " + "InstitutionAccounts for that institution.\nAnswer [y/n]: ") if answer == "y" or answer == "yes": institution.delete() self.stdout.write("Deleted institution '%s'.\n" % str(institution)) else: self.stdout.write("Canceled.\n")