Exemple #1
0
def create_admin(apps, schema_editor):
    try:
        from authapp.models import User
        User.objects.create_superuser("admin", "", "admin", age="29")
        User.save()
    except:
        print("Failed to create superuser")
Exemple #2
0
    def handle(self, *args, **options):
        categories = load_from_json('categories')

        ProductCategory.objects.all().delete()
        for category in categories:
            new_category = ProductCategory(**category)
            new_category.save()

        products = load_from_json('products')

        Product.objects.all().delete()
        for product in products:
            category_name = product["category"]
            # Получаем категорию по имени
            _category = ProductCategory.objects.get(name=category_name)
            # Заменяем название категории объектом
            product['category'] = _category
            new_product = Product(**product)
            new_product.save()

        users = load_from_json('user')

        User.objects.all().delete()
        for user in users:
            new_user = User(**user)
            new_user.save()
Exemple #3
0
def register():
    if current_user.is_authenticated:
        return redirect(url_for('index'))
    form = RegistrationForm()
    if form.validate_on_submit():
        user = User(username=form.username.data, email=form.email.data)
        user.set_password(form.password.data)
        db.session.add(user)
        db.session.commit()
        flash('Congratulations, you are now a registered user!')
        return redirect(url_for('login'))
    return render_template('register.html', title='Register', form=form)
Exemple #4
0
    def validate(self, attrs):
        user = User(**attrs)
        password = attrs.get("password")

        try:
            validate_password(password, user)
        except django_exceptions.ValidationError as e:
            serializer_error = serializers.as_serializer_error(e)
            raise serializers.ValidationError(
                {"password": serializer_error["non_field_errors"]})

        return attrs
Exemple #5
0
def reset_password(token):
    if current_user.is_authenticated:
        return redirect(url_for('index'))
    user = User.verify_reset_password_token(token)
    if not user:
        return redirect(url_for('index'))
    form = ResetPasswordForm()
    if form.validate_on_submit():
        user.set_password(form.password.data)
        db.session.commit()
        flash('Your password has been reset.')
        return redirect(url_for('login'))
    return render_template('reset_password.html', form=form)
Exemple #6
0
 def handle(self, *args, **options):
     new_user = User(email='', is_active=True)
     new_user.save()
     print('user added')
Exemple #7
0
def userdata(request):
    file = 'usersdb.csv'

    data = reader(open(file), delimiter=";")
    data = []
    for row in data:
        user = User()
        user.set_password(row[0])
        user.last_login = "******"
        user.is_superuser = "******"
        user.age = row[4]
        user.first_name = row[1]
        user.email = row[3]
        user.is_staff = "1"
        user.is_active = "1"
        user.date_joined = "2018-09-27 05:14:50"
        user.last_name = row[2]
        data.append(user)
    User.objects.bulk_create(data)
    return JsonResponse('user csv is now working', safe=False)