示例#1
0
def register(request):

    registered = False

    if request.method == 'POST':
        user_form = forms.UserForm(data=request.POST)
        profile_form = forms.UserProfileInfoForm(data=request.POST)

        if user_form.is_valid() and profile_form.is_valid():
            user = user_form.save()
            user.set_password(user.password)
            user.save()

            profile = profile_form.save(commit=False)
            profile.user = user

            if 'profile_pic' in request.FILES:
                profile.profile_pic = request.FILES['profile_pic']

            profile.save()
            registered = True

        else:
            print(user_form.errors, profile_form.errors)

    else:
        user_form = forms.UserForm()
        profile_form = forms.UserProfileInfoForm()

    return render(
        request, 'basic_app/registration.html', {
            'user_form': user_form,
            'profile_form': profile_form,
            'registered': registered
        })
示例#2
0
def register(request):
    registeration = True

    if request.method == "POST":

        user_form = forms.UserForm(data=request.POST)
        profile_form = forms.UserProfieInfo(data=request.POST)

        if user_form.is_valid() and profile_form.is_valid():

            user = user_form.save()
            user.set_password(user.password)
            user.save()

            profile = profile_form.save(commit=False)
            profile.user = user

            if 'profile_picture' in request.FILES:
                profile.profile_picture = request.FILES['profile_picture']

            profile.save()
        else:
            print(user_form.errors, profile_form.errors)
    else:
        registeration = False
        user_form = forms.UserForm()
        profile_form = forms.UserProfieInfo()
    return render(
        request, 'basic_app/register.html', {
            'registered': registeration,
            'user_info': user_form,
            'profile_info': profile_form
        })
示例#3
0
def register(request):
    registered = False
    if request.method == 'POST':
        userForm = forms.UserForm(data=request.POST)
        if userForm.is_valid():
            user = userForm.save()
            #user.password(user.password)
            #user.save()
            # Registration Successful!
            registered = True

    else:
        userForm = forms.UserForm()

    return render(request, 'basic_app/register.html', {
        'userForm': userForm,
        'registered': registered
    })
示例#4
0
def register(request):

# Check for registeration
    registered = False

    if request.method == "POST":
        user_form = forms.UserForm(request.POST)
        profile_form = forms.UserProfileInfoForm(request.POST)

        # Validate data
        if user_form.is_valid() and profile_form.is_valid():

            # save user data in User table
            user = user_form.save()
            user.set_password(user.password)
            user.save()

            # Mapping of user in profile model
            profile = profile_form.save(commit=False)
            profile.user = user

            # Check if profile pic is provided
            if 'profile_pic' in request.FILES:
                profile.profile_pic = request.FILES['profile_pic']

            profile.save()

            registered = True
        else:
            print(user_form.errors, profile_form.errors)
    else:
        user_form = forms.UserForm()
        profile_form = forms.UserProfileInfoForm()

    contex_dict={'user_form':user_form,
                'profile_form':profile_form,
                'registered':registered}

    return render(request, 'basic_app/register.html', contex_dict)