def create_superuser(self):
     print('Creating test superuser (admin/123456)')
     management.call_command('createsuperuser', interactive=False, username='******',
                             email='*****@*****.**')
     command = changepassword.Command()
     command._get_pass = lambda *args: '123456'
     command.execute('admin')
示例#2
0
def setup_first_use():
    os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'openeis.server.settings')

    from django.contrib.auth.management.commands import changepassword
    from django.core import management
    from django.contrib.auth.models import User

    try:
        user_count = User.objects.count()
    except:
        user_count = 0

    # If there isn't a superuser then we need to run syncdb and setup our main
    # superuser for the system.
    if user_count == 0:
        # Run the syncdb
        management.call_command('syncdb', interactive=False)

        # Create the super user and sets his password.
        # use username openeis/openeis as the super user
        management.call_command('createsuperuser',
                                interactive=False,
                                username="******",
                                email="*****@*****.**")
        command = changepassword.Command()
        command._get_pass = lambda *args: 'openeis'
        command.execute("openeis")
示例#3
0
    def test_that_max_tries_exits_1(self):
        """
        A CommandError should be thrown by handle() if the user enters in
        mismatched passwords three times.
        """
        command = changepassword.Command()
        command._get_pass = lambda *args: args or 'foo'

        with self.assertRaises(CommandError):
            command.execute("joe", stdout=self.stdout, stderr=self.stderr)
示例#4
0
    def test_that_changepassword_command_changes_joes_password(self):
        " Executing the changepassword management command should change joe's password "
        self.assertTrue(self.user.check_password('qwerty'))
        command = changepassword.Command()
        command._get_pass = lambda *args: 'not qwerty'

        command.execute("joe", stdout=self.stdout)
        command_output = self.stdout.getvalue().strip()

        self.assertEqual(command_output, "Changing password for user 'joe'\nPassword changed successfully for user 'joe'")
        self.assertTrue(models.User.objects.get(username="******").check_password("not qwerty"))
示例#5
0
def create_super_user(login, password):
    # Create the super user and sets his password.
    from django.core import management
    management.call_command('createsuperuser', 
                            interactive=False,
                            email='*****@*****.**',
                            username=login)
    from django.contrib.auth.management.commands import changepassword
    command = changepassword.Command()
    command._get_pass = lambda *args: password
    command.execute(login)
示例#6
0
    def test_that_changepassword_command_works_with_nonascii_output(self):
        """
        #21627 -- Executing the changepassword management command should allow
        non-ASCII characters from the User object representation.
        """
        # 'Julia' with accented 'u':
        models.User.objects.create_user(username='******', password='******')

        command = changepassword.Command()
        command._get_pass = lambda *args: 'not qwerty'

        command.execute(username="******", stdout=self.stdout)
示例#7
0
    def test_password_validation(self):
        """
        A CommandError should be raised if the user enters in passwords which
        fail validation three times.
        """
        command = changepassword.Command()
        command._get_pass = lambda *args: '1234567890'

        abort_msg = "Aborting password change for user 'joe' after 3 attempts"
        with self.assertRaisesMessage(CommandError, abort_msg):
            command.execute(username="******", stdout=self.stdout, stderr=self.stderr)
        self.assertIn('This password is entirely numeric.', self.stderr.getvalue())
示例#8
0
    def test_that_changepassword_command_with_database_option_uses_given_db(self):
        """
        Executing the changepassword management command with a database option
        should operate on the specified DB
        """
        self.assertTrue(self.user.check_password('qwerty'))
        command = changepassword.Command()
        command._get_pass = lambda *args: 'not qwerty'

        command.execute("joe", database='other', stdout=self.stdout)
        command_output = self.stdout.getvalue().strip()

        self.assertEqual(command_output, "Changing password for user 'joe'\nPassword changed successfully for user 'joe'")
        self.assertTrue(models.User.objects.using('other').get(username="******").check_password("not qwerty"))
示例#9
0
    def test_that_max_tries_exits_1(self):
        """
        A CommandError should be thrown by handle() if the user enters in
        mismatched passwords three times. This should be caught by execute() and
        converted to a SystemExit
        """
        command = changepassword.Command()
        command._get_pass = lambda *args: args or 'foo'

        self.assertRaises(SystemExit,
                          command.execute,
                          "joe",
                          stdout=self.stdout,
                          stderr=self.stderr)
示例#10
0
def createCredentials(username, password, email):
    '''
    This function can only be called after the Django settings file is available
    in the environment variables.
    '''

    from django.contrib.auth.management.commands import changepassword
    from django.core import management

    # Run the syncdb
    management.call_command('syncdb', interactive=False)

    # Create the super user and sets his password.
    management.call_command('createsuperuser',
                            interactive=False,
                            username=username,
                            email=email)
    command = changepassword.Command()
    command._get_pass = lambda *args: password
    command.execute(username)
import pwgen

superuser_password = pwgen.pwgen(20, 1, no_symbols=True)
adminuser_password = pwgen.pwgen(20, 1, no_symbols=True)

from django.contrib.auth.management.commands import changepassword
from django.core import management

management.call_command('createsuperuser',
                        interactive=False,
                        username='******',
                        email='*****@*****.**')

command = changepassword.Command()
command._get_pass = lambda *args: superuser_password
command.execute('superuser')

from django.contrib.auth.models import User

if not User.objects.filter(username='******').count():
    User.objects.create_superuser('admin', '*****@*****.**',
                                  adminuser_password)

print 'Django superuser password:'******'Django admin password:', adminuser_password