Exemple #1
0
def signUpView(request):
    # Checking If the User is already Logged In
    if (request.user.is_authenticated):
        checkAndRedirect(request.user)
    if (request.method == 'POST'):
        form = forms.SignUpForm(request.POST)
        if (form.is_valid()):
            # print()
            instance = form.save(commit=False)
            # Only after instance is saved We can access id
            instance.save()

            # Creating Profile Instance for the new user
            profileInstance = models.Profile(user=instance)
            profileInstance.save()

            # Creating Customer Instance for the new user
            customerInstance = Customer(user=instance)
            customerInstance.save()

            user = authenticate(request,
                                username=form.cleaned_data['username'],
                                password=form.cleaned_data['password1'])
            if (user):
                login(request, user)
                return HttpResponseRedirect(reverse('customer:landing'))
    else:
        form = forms.SignUpForm()

    context = {
        'form': form,
        'cartc': 0,
    }
    return render(request, 'accounts/signup.html', context)
Exemple #2
0
def signup_index(request):
    logger.info('signup')
    if request.method == 'POST':
        forms = {'SignUpForm':FORMS.SignUpForm(request.POST)}
    else:
        forms = {'SignUpForm':FORMS.SignUpForm()}
    c = {}
    main_url = CONFIG.TOP_URL
    action_dict = CONFIG.ACTION_DICT
    url_dict = {'main_url':main_url,
                }
    c.update({'html_title':CONFIG.HOME_HTML_TITLE})
    c.update(url_dict)
    c.update(forms)
    c.update(action_dict)
    return render(request, 'common/signup.html', c)
Exemple #3
0
def signup_user(request):
    logger.info('signup_user')
    c = {}

    form = FORMS.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)
    else:
        return signup_index(request)

    return HOME_VIEWS.Home(request)