Ejemplo n.º 1
0
def register(request):
    registered = False
    if request.method == "POST":
        user_form = UserForm(data=request.POST)
        profile_form = 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 = UserForm()
        profile_form = UserProfileInfoForm()

    return render(request,'basic_app/registration.html',
                            {'user_form':user_form,
                            'profile_form': profile_form,
                            'registered': registered
                            })
Ejemplo n.º 2
0
def register(request):

    registered = False

    if request.method == 'POST':

        # Get info from "both" forms
        # It appears as one form to the user on the .html page
        user_form = UserForm(data=request.POST)
        profile_form = UserProfileInfoForm(data=request.POST)

        # Check to see both forms are valid
        if user_form.is_valid() and profile_form.is_valid():

            # Save User Form to Database
            user = user_form.save()

            # Hash the password
            user.set_password(user.password)

            # Update with Hashed password
            user.save()

            # Now we deal with the extra info!

            # Can't commit yet because we still need to manipulate
            profile = profile_form.save(commit=False)

            # Set One to One relationship between
            # UserForm and UserProfileInfoForm
            profile.user = user

            # Check if they provided a profile picture
            if 'profile_pic' in request.FILES:
                print('found it')
                # If yes, then grab it from the POST form reply
                profile.profile_pic = request.FILES['profile_pic']

            # Now save model
            profile.save()

            # Registration Successful!
            registered = True

        else:
            # One of the forms was invalid if this else gets called.
            print(user_form.errors,profile_form.errors)

    else:
        # Was not an HTTP post so we just render the forms as blank.
        user_form = UserForm()
        profile_form = UserProfileInfoForm()

    # This is the render and context dictionary to feed
    # back to the registration.html file page.
    return render(request,'basic_app/registration.html',
                          {'user_form':user_form,
                           'profile_form':profile_form,
                           'registered':registered})
Ejemplo n.º 3
0
def register(request):

    registered = False

    if request.method == "POST":
        user_form = UserForm(data=request.POST)
        profile_form = 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 = UserForm()
        profile_form = UserProfileInfoForm

    return render(
        request, 'basic_app/registration.html', {
            'user_form': user_form,
            'profile_form': profile_form,
            'registered': registered
        })
def register(request):

    registered = False

    if request.method == 'POST':
        user_form = UserForm(data=request.POST)
        profile_form = 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  # This involves a bit of a juggling act between three different files, pay attention here.

            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 = UserForm()
        profile_form = UserProfileInfoForm()

    return render(
        request, 'basic_app/registration.html', {
            'user_form': user_form,
            'profile_form': profile_form,
            'registered': registered
        })
Ejemplo n.º 5
0
def register(request):
    registered=False

    if request.method=="POST":
        user_form = UserForm(data=request.POST)
        profile_form = 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=UserForm()
        profile_form = UserProfileInfoForm()

    return render(request,"basic_app/registration.html",
                        {
                        "user_form":user_form,
                        "profile_form": profile_form,
                        "registered":registered,
                        })


    return render(request,"basic_app/index.html")
Ejemplo n.º 6
0
def register(request):

    registered = False

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

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

            user = user_form.save()  # save directly into database
            user.set_password(user.password)  #Hashing the password
            user.save()

            profile = profile_form.save(commit=False)
            profile.user = user  #One to one relationship

            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 = UserForm()
        profile_form = UserProfileInfoForm()

    return render(
        request, 'basic_app/registration.html', {
            'user_form': user_form,
            'profile_form': profile_form,
            'registered': registered
        })
Ejemplo n.º 7
0
def register(request):
    registered = False

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

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

            user = user_form.save()
            user.set_password(user.password)  # hashing before saving
            user.save()

            profile = profile_form.save(commit=False)
            profile.user = user  # OneToOne Relationship

            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)
    # Not a POST
    else:
        user_form = UserForm()
        profile_form = UserProfileInfoForm()

    return render(request,
                  'basic_app/registration.html',
                  context={
                      'registered': registered,
                      'user_form': user_form,
                      'profile_form': profile_form,
                  })
Ejemplo n.º 8
0
def register(request):

    registered = False  #This tells us if someone is registered or not

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

        if user_form.is_valid() and profile_form.is_valid():
            user = user_form.save()
            user.set_password(
                user.password)  #this would essentially set the hashing pwd
            user.save()

            profile = profile_form.save(commit=False)
            profile.user = user  #This sets the OneToOne relationship

            if 'profile_pic' in request.FILES:
                profile.profile_pic = request.FILES[
                    'profile_pic']  # NB: even if this is a csv, we're supposed to be linking them up wi request.FILES as shown

            profile.save()

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

    return render(
        request, 'basic_app/registration.html', {
            'user_form': user_form,
            'profile_form': profile_form,
            'registered': registered
        })
Ejemplo n.º 9
0
def register(request):

    registered = False

    if request.method == 'POST':

        # Get info from "both" forms
        # It appears as one form to the user on the .html page
        user_form = UserForm(data=request.POST)
        profile_form = UserProfileInfoForm(data=request.POST)

        # Check to see both forms are valid
        if user_form.is_valid() and profile_form.is_valid():

            # Save User Form to Database
            user = user_form.save()

            # Hash the password
            user.set_password(user.password)

            # Update with Hashed password
            user.save()

            # Now we deal with the extra info!

            # Can't commit yet because we still need to manipulate
            profile = profile_form.save(commit=False)

            # Set One to One relationship between
            # UserForm and UserProfileInfoForm
            profile.user = user

            # Check if they provided a profile picture
            if 'profile_pic' in request.FILES:
                print('found it')
                # If yes, then grab it from the POST form reply
                profile.profile_pic = request.FILES['profile_pic']

            # Now save model
            profile.save()

            # Registration Successful!
            registered = True

        else:
            # One of the forms was invalid if this else gets called.
            print(user_form.errors, profile_form.errors)

    else:
        # Was not an HTTP post so we just render the forms as blank.
        user_form = UserForm()
        profile_form = UserProfileInfoForm()

    # This is the render and context dictionary to feed
    # back to the registration.html file page.
    return render(
        request, 'basic_app/registration.html', {
            'user_form': user_form,
            'profile_form': profile_form,
            'registered': registered
        })
Ejemplo n.º 10
0
def register(request):

    registered = False  # veut dire que l'user n'est pas registered

    if request.method == 'POST':

        # Get info from "both" forms
        # It appears as one form to the user on the .html page
        user_form = UserForm(
            data=request.POST)  #va prendre les infos de user form

        profile_form = UserProfileInfoForm(data=request.POST)  #pareil

        # Check to see both forms are valid
        if user_form.is_valid() and profile_form.is_valid():
            # si vrai alors on les prend de user form
            # Save User Form to Database
            user = user_form.save()

            # Hash the password
            user.set_password(user.password)

            # Update with Hashed password
            user.save()

            # Now we deal with the extra info!

            # Can't commit yet because we still need to manipulate
            profile = profile_form.save(
                commit=False)  #pour ne pas avoir d'erreur
            # car on va encore manipuler avant de mettre ds la database

            # Set One to One relationship between
            # UserForm and UserProfileInfoForm
            profile.user = user

            # Check if they provided a profile picture
            if 'profile_pic' in request.FILES:  # FILES car fichier
                print('found it')
                # If yes, then grab it from the POST form reply
                profile.profile_pic = request.FILES[
                    'profile_pic']  # files = dictionnarie

            # Now save model
            profile.save()

            # Registration Successful!
            registered = True  # l'user s'est enregistre

        else:
            # One of the forms was invalid if this else gets called.
            print(user_form.errors, profile_form.errors)

    else:
        # si il y a pas de request
        # Was not an HTTP post so we just render the forms as blank.
        user_form = UserForm()
        profile_form = UserProfileInfoForm()

    # This is the render and context dictionary to feed
    # back to the registration.html file page. context dictionnarie
    return render(
        request, 'basic_app/registration.html', {
            'user_form': user_form,
            'profile_form': profile_form,
            'registered': registered
        })
Ejemplo n.º 11
0
def register(request):

    # Flag to check if the user is registered
    registered = False

    if request.method == 'POST':

        # instantiate Form objects with the retrieved data
        user_form = UserForm(data=request.POST)
        profile_form = UserProfileInfoForm(data=request.POST)

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

            # save the user form in plain text
            user = user_form.save()

            # hash the password
            user.set_password(user.password)

            # then save those changes on the password (re-save)
            user.save()

            # Do same for profile_form, but DO NOT commit to DB yet
            profile = profile_form.save(commit=False)

            # The OneToOne relationship defined in models.py is
            # reflected here. We are linking both forms togehter
            # in this line of code, keeping profile_form as master
            profile.user = user

            # if a profile picture was provided
            if 'profile_pic' in request.FILES:

                # grab the value of the profile_pic
                profile.profile_pic = request.FILES['profile_pic']

            # save the changes
            profile.save()

            # registration successful, flag it.
            registered = True

        # there was an error in the registration, print it.
        else:

            print(user_form.errors, profile_form.errors)

    # Request was NOT POST (Get or other one)
    else:

        # so show the forms to be completed
        user_form = UserForm()
        profile_form = UserProfileInfoForm()

    # at any case, return the view with its context view
    return render(
        request, 'basic_app/registration.html', {
            'user_form': user_form,
            'profile_form': profile_form,
            'registered': registered
        })
Ejemplo n.º 12
0
def register(request):

    registered = False

    if request.method == 'POST':

        # Get info from "both" forms
        # It appears as one form to the user on the .html page
        user_form = UserForm(data=request.POST)
        profile_form = UserProfileInfoForm(data=request.POST)

        # Check to see both forms are valid
        if user_form.is_valid() and profile_form.is_valid():
            user = user_form.save(commit=False)
            profile = profile_form.save(commit=False)

            if User.objects.filter(email=user.email).exists(
            ) or UserProfileInfo.objects.filter(
                    mob_no=profile.mob_no) or UserProfileInfo.objects.filter(
                        college_reg_id=profile.college_reg_id):
                print("Exixt")
            else:
                # Save User Form to Database
                user = user_form.save()

                # Hash the password
                user.set_password(user.password)
                codeg = 1110 + user.id
                user.username = '******' + str(codeg)

                # Update with Hashed password
                user.save()

                # Now we deal with the extra info!

                # Can't commit yet because we still need to manipulate

                # Set One to One relationship between
                # UserForm and UserProfileInfoForm
                profile.user = user

                log = Log()
                log.mob_no_log = profile.mob_no
                log.email_log = user.email
                log.refuser = user.username
                log.save()

                # Check if they provided a profile picture
                #if 'profile_pic' in request.FILES:
                #print('found it')
                # If yes, then grab it from the POST form reply
                #profile.profile_pic = request.FILES['profile_pic']

                # Now save model
                profile.save()

                # Registration Successful!
                registered = True
                subject = "Registration Sucessful Pravesha'19"
                message = render_to_string(
                    "basic_app/message_body.html", {
                        'regid': user.username,
                        'fname': user.first_name,
                        'lname': user.last_name
                    })
                from_email = settings.EMAIL_HOST_USER
                to_list = [user.email]
                send_mail(subject,
                          message,
                          from_email,
                          to_list,
                          fail_silently=True)

        else:
            # One of the forms was invalid if this else gets called.
            print(user_form.errors, profile_form.errors)

    else:
        # Was not an HTTP post so we just render the forms as blank.
        user_form = UserForm()
        profile_form = UserProfileInfoForm()

    # This is the render and context dictionary to feed
    # back to the registration.html file page.
    if registered == True:

        return render(
            request, 'basic_app/registration.html', {
                'user_form': user_form,
                'profile_form': profile_form,
                'registered': registered,
                'username': user.username
            })
    else:
        return render(
            request, 'basic_app/registration.html', {
                'user_form': user_form,
                'profile_form': profile_form,
                'registered': registered,
            })
Ejemplo n.º 13
0
def register(request):
    registered = False

    if request.method == 'POST':

        user_form = UserForm(data=request.POST)
        profile_form = UserProfileInfoForm(data=request.POST)

        print('data: ', request.POST)

        if user_form.is_valid() \
                and profile_form.is_valid() \
                and user_form.cleaned_data['password'] == user_form.cleaned_data['confirm_password']:

            print('files: ', request.FILES)

            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:
                print('Found file: ', request.FILES['profile_pic'])
                profile.profile_pic = request.FILES['profile_pic']

            profile.save()

            registered = True

            return render(
                request, 'basic_app/registration.html', {
                    'user_form': user_form,
                    'profile_form': profile_form,
                    'registered': registered
                })

        elif user_form.cleaned_data['password'] != user_form.cleaned_data[
                'confirm_password']:
            user_form.add_error('confirm_password',
                                'The passwords do not match')
            return render(
                request, 'basic_app/registration.html', {
                    'user_form': user_form,
                    'profile_form': profile_form,
                    'registered': registered
                })
        elif len(user_form.cleaned_data['password']) < 5:
            user_form.add_error('password',
                                'The password length must be at least 6')
            return render(
                request, 'basic_app/registration.html', {
                    'user_form': user_form,
                    'profile_form': profile_form,
                    'registered': registered
                })
        else:

            print('user_form.errors: ', user_form.errors)
            print('profile_form.errors: ', profile_form.errors)
            return render(
                request, 'basic_app/registration.html', {
                    'user_form': user_form,
                    'profile_form': profile_form,
                    'registered': registered
                })
    else:
        user_form = UserForm()
        profile_form = UserProfileInfoForm()
        return render(
            request, 'basic_app/registration.html', {
                'user_form': user_form,
                'profile_form': profile_form,
                'registered': registered
            })
Ejemplo n.º 14
0
def register(request):

    registered = False

    if request.method == 'POST':

        # Get info from "both" forms
        # It appears as one form to the user on the .html page
        user_form = UserForm(data=request.POST)
        profile_form = UserProfileInfoForm(data=request.POST)

        # Check to see both forms are valid
        if user_form.is_valid() and profile_form.is_valid():

            # Save User Form to Database
            print('hello world')
            user = user_form.save(commit=False)
            user.is_active = False
            user.save()

            # # Hash the password
            # user.set_password(user.password)
            #
            # # Update with Hashed password
            # user.save()

            # Now we deal with the extra info!

            # Can't commit yet because we still need to manipulate
            profile = profile_form.save(commit=False)

            # Set One to One relationship between
            # UserForm and UserProfileInfoForm
            profile.user = user

            # Check if they provided a profile picture
            # if 'profile_pic' in request.FILES:
            #     print('found it')
            #     # If yes, then grab it from the POST form reply
            #     profile.profile_pic = request.FILES['profile_pic']

            # Now save model
            profile.save()

            # Registration Successful!
            registered = True
            current_site = get_current_site(request)
            message = render_to_string(
                'acc_active_email.html', {
                    'user': user,
                    'domain': current_site.domain,
                    'uid': urlsafe_base64_encode(force_bytes(user.pk)),
                    'token': account_activation_token.make_token(user),
                })
            mail_subject = 'Activate your blog account.'
            to_email = user_form.cleaned_data.get('email')
            email = EmailMessage(mail_subject, message, to=[to_email])
            email.send()
            return HttpResponse(
                'Please confirm your email address to complete the registration'
            )

        else:
            # One of the forms was invalid if this else gets called.
            print(user_form.errors, profile_form.errors)

    else:
        # Was not an HTTP post so we just render the forms as blank.
        user_form = UserForm()
        profile_form = UserProfileInfoForm()

    # This is the render and context dictionary to feed
    # back to the registration.html file page.
    return render(
        request, 'basic_app/registration.html', {
            'user_form': user_form,
            'profile_form': profile_form,
            'registered': registered
        })
Ejemplo n.º 15
0
def index(request):
    count="Failed"
    if request.method == 'POST':
        profile_form = UserProfileInfoForm(data=request.POST)
        print('first if')
    # Check to see both forms are valid
        if profile_form.is_valid():

        # Now we deal with the extra info!
            print('is valid?')
        # Can't commit yet because we still need to manipulate
            profile = profile_form.save(commit=False)

        # Set One to One relationship between
        # UserForm and UserProfileInfoForm
            profile.user = request.user


            pc = UserPictureCount.objects.get(user = request.user)
            count = str(pc.picture_count)


        # Check if they provided a profile picture
            if 'profile_pic' in request.FILES:
                print('found it')

                pc.picture_count -=1
                pc.save()


            # If yes, then grab import osit from the POST form reply
                profile.profile_pic = request.FILES['profile_pic']
                f = request.FILES['profile_pic']
                # for chunk in f.chunks():
                #     path = 'media/'+request.user.username+'/file.png'
                #     if not os.path.exists(path):
                #         os.makedirs(path)
                #     fw=open(path,'wb')
                #     fw.write(chunk)
                #     fw.close()


        # Now save model
                profile.save()
                if (pc.picture_count > 0):
                    return render(request,'basic_app/success.html')
                else:
                    profile_form = UserProfileInfoForm()
                    outofsnaps =""
                    count = '0'
                    outofsnaps ="REWIND<< are printing your photos!"
                    return render(request,'basic_app/index.html',{
    'profile_form':profile_form,
    "pic_count": count,
    "top_up":outofsnaps
    })


        else:
             print('invalid image')
             profile_form = UserProfileInfoForm()



    else:
    # Was not an HTTP post so we just render the forms as blank.
        profile_form = UserProfileInfoForm()
        outofsnaps =""
        if request.user.id:
            try:
                pc = UserPictureCount.objects.get(user_id = request.user.id)
                count = str(pc.picture_count)
                if pc.picture_count == 0:
                    outofsnaps ="REWIND<< are printing your photos!"

            except UserPictureCount.DoesNotExist:
                count = '0'
                outofsnaps ="Invalid user"






# This is the render and context dictionary to feed
# back to the registration.html file page.

    return render(request,'basic_app/index.html',{
    'profile_form':profile_form,
    "pic_count": count,
    "top_up":outofsnaps
    })