def _register(request):
    if request.user.is_authenticated():
        return redirect('Shop');

    if request.method == 'POST':
        form = RegisterForm(request.POST)
        if form.is_valid():

            _username = request.POST['username']
            _password = request.POST['password']
            _email = request.POST['email'] 

            if User.objects.filter(email= _email).exists():
                return render(request, 'login.html', {'error': ['Account with this address already exists.',], 'register': form})   

            if User.objects.filter(username = _username).exists():
                return render(request, 'login.html', {'error': ['Account with that name already exists.',], 'register': form}) 

            user = User.objects.create_user(_username,_email,_password)
            user.is_active = False
            user.save()  
            return render(request, 'login.html', {'message': ['Account created correctly, please login.',], 'register': RegisterForm()})      
        else:
            return render(request, 'login.html', {'error': ['Complete all fields correctly.',], 'register': form})    

    return redirect('Login')
Beispiel #2
0
def registerform(request):
    form = RegisterForm()
    if form.is_valid():
        print("hey form is correct")
        susername = form.cleaned_data.get("username")
        susername = form.cleaned_data.get("email")
        spassword = form.cleaned_data.get("password")
        spassword2 = form.cleaned_data.get("password2")
        # user= authenticate(request,username='******',password='******')
        # if user is not None:
        #     login(request,user)
    context = {'register': form}
    return render(request, "shop/register.html", context)
Beispiel #3
0
def register():
    form = RegisterForm()
    if form.validate_on_submit():
        hashed_password = generate_password_hash(form.password.data)
        user = User(username=form.username.data,
                    email=form.email.data,
                    password=hashed_password)
        db.session.add(user)
        db.session.commit()
        flash(f'Account created for {form.username.data}! You can now log in.',
              'success')
        return redirect(url_for('login'))
    return render_template('register.html', title='Register', form=form)
def _register(request):
    if request.user.is_authenticated():
        return redirect('Shop')

    if request.method == 'POST':
        form = RegisterForm(request.POST)
        if form.is_valid():

            _username = request.POST['username']
            _password = request.POST['password']
            _email = request.POST['email']

            if User.objects.filter(email=_email).exists():
                return render(
                    request, 'login.html', {
                        'error': [
                            'Account with this address already exists.',
                        ],
                        'register': form
                    })

            if User.objects.filter(username=_username).exists():
                return render(
                    request, 'login.html', {
                        'error': [
                            'Account with that name already exists.',
                        ],
                        'register': form
                    })

            user = User.objects.create_user(_username, _email, _password)
            user.is_active = False
            user.save()
            return render(
                request, 'login.html', {
                    'message': [
                        'Account created correctly, please login.',
                    ],
                    'register': RegisterForm()
                })
        else:
            return render(request, 'login.html', {
                'error': [
                    'Complete all fields correctly.',
                ],
                'register': form
            })

    return redirect('Login')
def _login(request):
    if request.user.is_authenticated():
        return redirect('Shop')

    if request.method == 'GET':
        if 'redirect' in request.GET:
            return render(request, 'login.html',
                          {'redirect': request.GET['redirect']})
        else:
            return render(request, 'login.html',
                          {'register': RegisterForm(request.POST)})
    else:
        if 'username' not in request.POST:
            error = 'Not specified username.'
            return render(request, 'login.html', {'error': error})

        if 'password' not in request.POST:
            error = 'Not specified password.'
            return render(request, 'login.html', {'error': error})

        username = request.POST['username']
        password = request.POST['password']

        user = authenticate(username=username, password=password)

        if user is not None:
            login(request, user)

            UserAccount.objects.get_or_create(User=user)

            if user.is_active:
                if 'redirect' in request.POST:
                    if request.POST['redirect'] is not None:
                        return redirect(request.POST['redirect'])

                return redirect('Shop')
            else:
                return redirect('Active')
        else:
            error = 'Bad username or password.'
            return render(request, 'login.html', {
                'error': error,
                'register': RegisterForm(request.POST)
            })
Beispiel #6
0
def register(request):
    if request.method == 'POST':
        form = RegisterForm(request.POST)
        if form.is_valid():
            form.is_active = True
            form.is_superuser = True
            user = form.save()
            login(request, user, backend='django.contrib.auth.backends.ModelBackend')
            return redirect('/')
    else:
        form = RegisterForm()
    return render(request, 'login.html',
                  {'form': form, 'submit_text': 'Зарегистрироваться', 'auth_header': 'Регистрация'})
Beispiel #7
0
def register():
    form = RegisterForm()
    if request.method == 'POST':
        user = User(name=form.name.data,
                    username=form.username.data,
                    email=form.email.data,
                    password=form.password.data)
        db.session.add(user)
        db.session.commit()
        flash('You are now registered and can log in', 'success')
        return redirect(url_for('sign_in'))
    return render_template('register.html', form=form)
Beispiel #8
0
def register(request):
    from shop.forms import RegisterForm
    from shop.models import Client

    if request.POST:
        form = RegisterForm(request.POST)
        print form.errors
        
        if form.is_valid():
            user = User.objects.create_user(request.POST['login'], request.POST['email'], request.POST['passwd'])
            user.is_staff = False
            user.is_active = True
            user.is_superuser = False
            user.first_name = request.POST['first_name']
            user.last_name = request.POST['last_name']
            user.save()
            
            client = Client(user=user, fullname='niepotrzebne ale dla testow ok :)')
            client.save()

            return HttpResponseRedirect('/login')
    else:
        form = RegisterForm()
    return render_to_response('auth/register.html', {'form': form})