コード例 #1
0
ファイル: web_admin_auth.py プロジェクト: dangnammta/zato
    def before_execute(self, args):
        super(CreateUser, self).before_execute(args)
        self._prepare(args)

        username = getattr(args, 'username', None)
        email = getattr(args, 'email', None)

        if username or email:
            if not (username and email):
                self.logger.error(
                    'Both --username and --email are required if either is provided'
                )
                sys.exit(self.SYS_ERROR.INVALID_INPUT)
            else:
                from django.contrib.auth.management.commands.createsuperuser import is_valid_email
                from django.core import exceptions
                self.reset_logger(self.args, True)

                try:
                    is_valid_email(email)
                except exceptions.ValidationError:
                    self.logger.error('Invalid e-mail `%s`', email)
                    sys.exit(self.SYS_ERROR.INVALID_INPUT)
                else:
                    self.is_interactive = False
コード例 #2
0
def get_started(request):
    if request.user.is_authenticated():
        package = request.user.get_profile().account.package
        plan = package.code
    else:
        plan = request.GET.get('plan', 'FREE')
        package = Package.objects.get(code=plan)
    if request.is_ajax() and request.method == 'POST':
        email = request.POST['email']
        try:
            is_valid_email(email)
        except:
            return HttpResponse('Invalid email address', status=400)

        try:
            account = create_account(request, email, package)
        except IntegrityError:
            return HttpResponse('Email address already used', status=400)

        return JsonResponse({
            'private_api_url': account.get_private_apiurl(),
            'public_api_url': account.get_public_apiurl(),
            'email': email
        })

    context = {
        'navigation_pos': 'get_started',
        'package': package,
        'plan': plan
    }
    return render('get_started.html', request, context_dict=context)
コード例 #3
0
    def handle(self, *args, **options):
        email = options.get('email', None)
        password = options.get('password', None)
        interactive = options.get('interactive')
        verbosity = int(options.get('verbosity', 1))

        # Do quick and dirty validation if --noinput
        if not interactive:
            if not password or not email:
                raise CommandError("You must use --password and --email with --noinput.")
            try:
                is_valid_email(email)
            except exceptions.ValidationError:
                raise CommandError("Invalid email address.")
            password = password.strip()
            if not len(password) < 6:
                raise CommandError("Password length must be > 5.")

        # Prompt for username/email/password. Enclose this whole thing in a
        # try/except to trap for a keyboard interrupt and exit gracefully.
        if interactive:
            try:

                # Get an email
                while 1:
                    if not email:
                        email = raw_input('E-mail address: ')
                        email = email.strip().lower()
                    try:
                        is_valid_email(email)
                    except exceptions.ValidationError:
                        sys.stderr.write("Error: That e-mail address is invalid.\n")
                        email = None
                    else:
                        break

                # Get a password
                while 1:
                    if not password:
                        password = getpass.getpass()
                        password2 = getpass.getpass('Password (again): ')
                        if password != password2:
                            sys.stderr.write("Error: Your passwords didn't match.\n")
                            password = None
                            continue
                    if len(password.strip()) < 6:
                        sys.stderr.write("Password length must be > 5.\n")
                        password = None
                        continue
                    break
            except KeyboardInterrupt:
                sys.stderr.write("\nOperation cancelled.\n")
                sys.exit(1)

        email = email.strip().lower()
        try:
            user = User.create_user(email, password)
            User.collection.update({'_id' : user._id}, {'$set' : {'is_superuser' : True}})
        except Exception, ex:
            sys.stderr.write("\nFailed to create user.\n%s\n" % unicode(ex))
コード例 #4
0
def get_started(request):
    if request.user.is_authenticated():
        package = request.user.get_profile().account.package
        plan = package.code
    else:
        plan = request.GET.get('plan', 'FREE')
        package = Package.objects.get(code=plan)
    if request.is_ajax() and request.method == 'POST':
        email = request.POST['email']
        try:
            is_valid_email(email)
        except:
            return HttpResponse('Invalid email address', status=400)
            
        try:
            account = create_account(request, email, package)
        except IntegrityError:
            return HttpResponse('Email address already used', status=400)
        
        return JsonResponse({'private_api_url':account.get_private_apiurl(), 'public_api_url':account.get_public_apiurl(), 'email': email})
    
    context = {
        'navigation_pos': 'get_started',
        'package': package,
        'plan': plan
    }
    return render('get_started.html', request, context_dict=context)
コード例 #5
0
    def before_execute(self, args):
        super(CreateUser, self).before_execute(args)
        self._prepare(args)

        username = getattr(args, 'username', None)
        email = getattr(args, 'email', None)

        if username or email:
            if not(username and email):
                self.logger.error('Both --username and --email are required if either is provided')
                sys.exit(self.SYS_ERROR.INVALID_INPUT)
            else:
                from django.contrib.auth.management.commands.createsuperuser import is_valid_email
                from django.core import exceptions
                self.reset_logger(self.args, True)

                try:
                    is_valid_email(email)
                except exceptions.ValidationError:
                    self.logger.error('Invalid e-mail `%s`', email)
                    sys.exit(self.SYS_ERROR.INVALID_INPUT)
                else:
                    self.is_interactive = False
コード例 #6
0
    def handle(self, *args, **options):
        email = options.get('email', None)
        password = options.get('password', None)
        interactive = options.get('interactive')
        verbosity = int(options.get('verbosity', 1))

        # Do quick and dirty validation if --noinput
        if not interactive:
            if not password or not email:
                raise CommandError(
                    "You must use --password and --email with --noinput.")
            try:
                is_valid_email(email)
            except exceptions.ValidationError:
                raise CommandError("Invalid email address.")
            password = password.strip()
            if not len(password) < 6:
                raise CommandError("Password length must be > 5.")

        # Prompt for username/email/password. Enclose this whole thing in a
        # try/except to trap for a keyboard interrupt and exit gracefully.
        if interactive:
            try:

                # Get an email
                while 1:
                    if not email:
                        email = raw_input('E-mail address: ')
                        email = email.strip().lower()
                    try:
                        is_valid_email(email)
                    except exceptions.ValidationError:
                        sys.stderr.write(
                            "Error: That e-mail address is invalid.\n")
                        email = None
                    else:
                        break

                # Get a password
                while 1:
                    if not password:
                        password = getpass.getpass()
                        password2 = getpass.getpass('Password (again): ')
                        if password != password2:
                            sys.stderr.write(
                                "Error: Your passwords didn't match.\n")
                            password = None
                            continue
                    if len(password.strip()) < 6:
                        sys.stderr.write("Password length must be > 5.\n")
                        password = None
                        continue
                    break
            except KeyboardInterrupt:
                sys.stderr.write("\nOperation cancelled.\n")
                sys.exit(1)

        email = email.strip().lower()
        try:
            user = User.create_user(email, password)
            User.collection.update({'_id': user._id},
                                   {'$set': {
                                       'is_superuser': True
                                   }})
        except Exception, ex:
            sys.stderr.write("\nFailed to create user.\n%s\n" % unicode(ex))
コード例 #7
0
ファイル: createsuperuser.py プロジェクト: wuxxin/ecs
    def handle(self, *args, **options):
        username = options.get('username', None)
        email = options.get('email', None)
        interactive = options.get('interactive')

        if username:
            raise DeprecationWarning('there is no such thing as a username')

        if not interactive:
            if not email:
                raise CommandError('You must use --email with --noinput')
            try:
                is_valid_email(email)
            except exceptions.ValidationError:
                raise CommandError('Invalid email address.')

        password = ''

        if interactive:
            try:
                while 1:
                    if not email:
                        email = input('Email: ')
                    try:
                        is_valid_email(email)
                    except exceptions.ValidationError:
                        sys.stderr.write(
                            'Error: That e-mail address is invalid.\n')
                        email = None
                    else:
                        try:
                            User.objects.get(username=hash_email(email))
                        except User.DoesNotExist:
                            break
                        else:
                            print(
                                'Error: That e-mail address is already taken.',
                                file=sys.stderr)
                            email = None

                while 1:
                    if not password:
                        password = getpass.getpass('Password:'******'Password: (again):')
                        if password != password2:
                            print('Error: Your passwords didn\'t match.',
                                  file=sys.stderr)
                            password = None
                            continue
                    if password.strip() == '':
                        print('Error: Blank passwords aren\'t allowed.',
                              file=sys.stderr)
                        password = None
                        continue
                    break

            except KeyboardInterrupt:
                print('Operation cancelled.', file=sys.stderr)
                sys.exit(1)

        u = create_user(email,
                        is_superuser=True,
                        is_staff=True,
                        is_active=True)
        u.set_password(password)
        u.save()
        print('Superuser created successfully.')