def mk_user(self, args): """Create a new user. Ask in the terminal for mandatory fields""" if not args['<name>']: username = raw_input("Please enter the user's username: "******"utf-8") if User.find(username): self.print_error(u"Username {} already exists".format(username)) return admin = raw_input("Is this an administrator? [y/N] ") email = "" while not email: email = raw_input("Please enter the user's email address: ") password = "" while not password: password = getpass("Please enter the user's password: "******"User {} has been created".format(username)
def new_user(request): if request.method == 'POST': form = UserForm(request.POST) if form.is_valid(): data = form.cleaned_data user = User.create( name=data.get("username"), # TODO: Check if we can't harmonize unicode use for passwords between django and CLI password=data.get("password").encode("ascii", "ignore"), email=data.get("email", ""), administrator=data.get("administrator", False), active=data.get("active", False), username=request.user.name) messages.add_message( request, messages.INFO, "The user '{}' has been created".format(user.name)) return redirect('users:home') else: form = UserForm() ctx = { "form": form, } return render(request, 'users/new.html', ctx)