Exemplo n.º 1
0
 def test_register_user_with_valid_data_is_valid(self):
     form_data = {
         'first_name': 'Mohammed',
         'last_name': 'Khalil',
         'username': '******',
         'email': '*****@*****.**',
         'password1': '123456z!',
         'password2': '123456z!'
     }
     form = SignUpForm(form_data)
     self.assertTrue(form.is_valid())
Exemplo n.º 2
0
 def test_register_user_with_missing_data_fails(self):
     form_data = {
         'first_name': 'Mohammed',
         'username': '******',
         'email': '*****@*****.**',
         'password1': '123456z!',
         'password2': '123456z'
     }
     # Remove each key-value from dictionary, assert form not valid
     for field in form_data.keys():
         data = dict(form_data)
         del (data[field])
         form = SignUpForm(data)
         self.assertFalse(form.is_valid())
Exemplo n.º 3
0
def signup(request):
    form = SignUpForm(request.POST)
    if form.is_valid():
        user = form.save()
        user.refresh_from_db()
        user.customer.first_name = form.cleaned_data.get('first_name')
        user.customer.last_name = form.cleaned_data.get('last_name')
        user.customer.address = form.cleaned_data.get('address')
        user.save()
        username = form.cleaned_data.get('username')
        password = form.cleaned_data.get('password1')
        user = authenticate(username=username, password=password)
        login(request, user)
        return redirect('/')
    return render(request, 'signup.html', {'form': form})
Exemplo n.º 4
0
    def test_register_user_with_username_already_in_db_fails(self):

        # Create a user with username mkha
        mkha = User(username='******', email='*****@*****.**')
        mkha.save()

        # attempt to create another user with same username
        form_data = {
            'first_name': 'Mohammed',
            'last_name': 'Khalil',
            'username': '******',
            'email': '*****@*****.**',
            'password1': '123456z!',
            'password2': '123456z'
        }
        form = SignUpForm(form_data)
        self.assertFalse(form.is_valid())
Exemplo n.º 5
0
def signup(request):
    is_user = False
    form = SignUpForm()
    if request.method == 'POST':
        form = SignUpForm(request.POST)
        if form.is_valid():
            try:
                email = form.cleaned_data.get('email')
                raw_password = form.cleaned_data.get('password1')
                User.objects.create(
                    username=email.split('@')[0],
                    email=email,
                    password=make_password(raw_password)).save()

                user = authenticate(email=email, password=raw_password)
                print(user)
                login(request, user)
                return redirect('login')
            except IntegrityError:
                is_user = True
    else:
        form = SignUpForm()
    return render(
        request,
        'signup.html',
        {
            'form': form,
            'menus': get_menu(),
            'is_user': is_user,
        },
    )
Exemplo n.º 6
0
def signup(request):
    if request.method == 'POST':
        form = SignUpForm(request.POST)
        if form.is_valid():
            form.save()
            username = form.cleaned_data.get('username')
            raw_password = form.cleaned_data.get('password1')
            user = authenticate(username=username, password=raw_password)
            login(request, user)
            return redirect('shop')
    else:
        form = SignUpForm()
    return render(request, 'signup.html', {'form': form})
Exemplo n.º 7
0
def reg(request):
    if request.method == 'POST':
        form = SignUpForm(request.POST)
        if form.is_valid():
            form.save()
            username = form.cleaned_data.get('email')
            raw_password = form.cleaned_data.get('password1')
            user = authenticate(username=username, password=raw_password)
            login(request, user)
            # return reverse_lazy('about')
            return redirect('about')
    else:
        form = SignUpForm()
    return render(request, 'registration/reg.html', {'form': form})
Exemplo n.º 8
0
Arquivo: views.py Projeto: jod35/shop
def sign_up():
    form = SignUpForm()
    if request.method == 'POST':
        new_seller = Seller(
            username=request.form.get('username'),
            email=request.form.get('email'),
            password=bcrypt.generate_password_hash(
                request.form.get('password')),
            comm_type=request.form.get('comm_type'),
        )
        try:
            db.session.add(new_seller)
            db.session.commit()
            flash("Your account has been created! You can now login")
            return redirect(url_for('sign_up'))
        except:
            flash("Please Check your Credentials and try again!")
            return redirect(url_for('sign_up'))

    return render_template('signup.html', form=form)