コード例 #1
0
def register(request):
    registered = False

    if request.method == 'POST':
        user_form = UserForm(data=request.POST)
        user_info_form = UserInfoForm(data=request.POST)

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

            user_info = user_info_form.save(commit=False)
            user_info.user = user

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

            user_info.save()
            registered = True

    else:
        user_form = UserForm()
        user_info_form = UserInfoForm()
    dict = {
        'user_form': user_form,
        'user_info_form': user_info_form,
        'registered': registered
    }
    return render(request, 'Login_app/register.html', context=dict)
コード例 #2
0
ファイル: views.py プロジェクト: Hasan-Saju/Django
def register(request):
    registered = False

    if request.method == 'POST':
        user_form = UserForm(data=request.POST)
        user_info_form = UserInfoForm(data=request.POST)

        if user_form.is_valid() and user_info_form.is_valid():
            user = user_form.save()
            user.set_password(user.password)  # password encryption
            user.save()

            user_info = user_info_form.save(commit=False)
            user_info.user = user  # user table connects userinfo

            # check if pp exists or not
            if 'profile_pic' in request.FILES:  # this is for img,pdf,static files
                user_info.profile_pic = request.FILES['profile_pic']

            user_info.save()
            registered = True
    else:
        user_form = UserForm()
        user_info_form = UserInfoForm()

    dict = {'user_form': user_form,
            'user_info_form': user_info_form, 'registered': registered}
    return render(request, 'Login_app/register.htm', context=dict)
コード例 #3
0
ファイル: views.py プロジェクト: mdehsanul/django-deployment
def register(request):
    registered = False

    if request.method == 'POST':
        user_form = UserForm(data=request.POST)
        user_info_form = UserInfoForm(data=request.POST)

        if user_form.is_valid() and user_info_form.is_valid():
            # model 1
            user = user_form.save()
            # converting plain password text into encripted password text by hashing
            user.set_password(user.password)
            # update and save encripted password
            user.save()

            # model 2
            # holding image file valid or not for upload by 'commit=False'
            user_info = user_info_form.save(commit=False)
            # creating one to one relation with admin --> user model    with user_info
            user_info.user = user
            # checking image file valid or not
            if 'profile_pic' in request.FILES:
                user_info.profile_pic = request.FILES['profile_pic']
            user_info.save()

            registered = True
    else:
        user_form = UserForm()
        user_info_form = UserInfoForm()
    dict = {
        'user_form': user_form,
        'user_info_form': user_info_form,
        'registered': registered
    }
    return render(request, 'Login_app/register.html', context=dict)
コード例 #4
0
def register(request):
    registered = False

    if request.method == 'POST':
        user_form = UserForm(data=request.POST)
        user_info_form = UserInfoForm(data=request.POST)

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

            user_info = user_info_form.save(commit=False)
            # making one-to-one relationship between two tables
            user_info.user = user

            # for any kind of file inputs do this
            if 'profile_pic' in request.FILES:
                user_info.profile_pic = request.FILES['profile_pic']

            user_info.save()
            registered = True

    else:
        user_form = UserForm()
        user_info_form = UserInfoForm()
    dict = {
        'user_form': user_form,
        'user_info_form': user_info_form,
        'registered': registered
    }
    return render(request, 'Login_app/register.html', context=dict)
コード例 #5
0
def register(request):
    registered = False

    if request.method == 'POST':
        user_form = UserForm(data=request.POST)
        user_info_form = UserInfoForm(data=request.POST)

        if user_form.is_valid() and user_info_form.is_valid():
            user = user_form.save()
            user.set_password(user.password)  #password encryption
            user.save()

            user_info = user_info_form.save(commit=False)
            user_info.user = user  #user_info and user table connected each other for this line

            if 'profile_pic' in request.FILES:
                user_info.profile_pic = request.FILES[
                    'profile_pic']  #this line use for upload profile pic and save picture in profile pic

            user_info.save()
            registered = True
    else:
        user_form = UserForm()
        user_info_form = UserInfoForm()

    dict = {
        'user_form': user_form,
        'user_info_form': user_info_form,
        'registered': registered
    }
    return render(request, 'Login_app/register.html', context=dict)
コード例 #6
0
def register(request):

    registered = False
    if request.method == "POST":
        user_form = UserForm(data=request.POST)
        user_info_form = UserInfoForm(data=request.POST)

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

            user = user_form.save()  #create a object of last added data
            user.set_password(
                user.password)  #last added objects password enctyped by this
            user.save()

            user_info = user_info_form.save(
                commit=False)  #creat object but not save
            user_info.user = user  #one to one connection wih two model

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

            user_info.save()
            registered = True
    else:
        user_form = UserForm()
        user_info_form = UserInfoForm()

    diction = {
        'title': 'Register | Authentication',
        'user_form': user_form,
        'user_info_form': user_info_form,
        'registered': registered
    }
    return render(request, 'Login_app/register.html', context=diction)