Ejemplo n.º 1
0
def register(request):
    registered = False
    if not (request.user.is_authenticated):

        if request.method == "POST":
            user_form = UserForm(data=request.POST)
            head_form = HeadForm(data=request.POST)

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

                head = head_form.save(commit=False)
                head.user = user
                head.save()
                registered = True
                return redirect('login')

            else:
                print(user_form.errors and head_form.errors)

        else:
            user_form = UserForm()
            head_form = HeadForm()

        return render(
            request, 'app1/red.html', {
                'user_form': user_form,
                'head_form': head_form,
                'registered': registered
            })

    else:
        return redirect('index')
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()

    print(registered)
    return render(request,'registration.html',
    {'user_form':user_form,'profile_form':profile_form,'registered':registered})
Ejemplo n.º 3
0
def register_teacher(request):
    registered = False
    if request.method == "POST":
        user_form = UserForm(data=request.POST)
        profile_form = UserProfileTeacherInfoForm(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

            profile.save()
            registered = True
        else:
            print(user_form.errors)

    else:
        user_form = UserForm()
        profile_form = UserProfileTeacherInfoForm()

    return render(
        request, 'app1/teacher.html', {
            'user_form': user_form,
            'profile_form': profile_form,
            'registered': registered
        })
Ejemplo n.º 4
0
def register(request):
    registered = False
    if request.method == "POST":
        user_form = UserForm(data=request.POST)
        profile_form = UserProfileForm(data=request.POST)
        print profile_form
        if user_form.is_valid() and profile_form.is_valid():

            user = user_form.save(commit=False)
            user.set_password(user.password)
            user.is_active = True
            user.save()
            profile = profile_form.save(commit=False)
            profile.user = user
            profile.lastLoginDate = datetime.now()
            profile.ipaddress = get_client_ip(request)
            profile.save()
            registered = True
        else:
            print user_form.errors, profile_form.errors
            messages.info(request,
                          str(user_form.errors) + str(profile_form.errors))
    else:
        user_form = UserForm()
        profile_form = UserProfileForm()
    return render(request,'site/register.html',{'title':'Sign Up','current_page':'register',\
     'user_form':user_form,'profile_form':profile_form,'registered':registered})
Ejemplo n.º 5
0
def empreg(request):
    registered = False
    if not (request.user.is_authenticated):
        if request.method == "POST":
            user_form = UserForm(data=request.POST)
            emp_form = EmployeeForm(data=request.POST)

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

                emp = emp_form.save(commit=False)
                emp.user = user
                emp.save()
                registered = True
                return redirect('login')

            else:
                print(user_form.errors and emp_form.errors)

        else:
            user_form = UserForm()
            emp_form = EmployeeForm()

        return render(request, 'app1/emp.html', {
            'user_form': user_form,
            'emp_form': emp_form,
            'registered': registered
        })
    else:
        return redirect('index')
Ejemplo n.º 6
0
def formview(request):
    regis = False
    if request.method == 'POST':
        form1 = UserForm(request.POST)
        form2 = UserProfileForm(request.POST)
        if form1.is_valid() and form2.is_valid():
            print("Name: " + form1.cleaned_data['username'])
            print("Email: " + form1.cleaned_data['email'])
            print("Password:"******"Website:" + form2.cleaned_data['website'])
            form1.save(commit=True)
            profile = form2.save(commit=False)
            if 'profile_pic' in request.FILES:
                profile.profile_pic = request.FILES['profile_pic']
                profile.save()
                regis = True
        else:
            print(form1.errors, form2.errors)

    else:
        form1 = UserForm()
        form2 = UserProfileForm()
    return render(request, 'app1/forms.html', {
        'form1': form1,
        'form2': form2,
        'registered': regis
    })
Ejemplo n.º 7
0
def register(request):	
	registered = False
	if request.method == "POST":
		user_form = UserForm(data=request.POST)
		profile_form = UserProfileForm(data=request.POST)
		print profile_form
		if user_form.is_valid() and profile_form.is_valid():
			
			user = user_form.save(commit=False)
			user.set_password(user.password)
			user.is_active=True
			user.save()
			profile = profile_form.save(commit=False)
			profile.user = user
			profile.lastLoginDate = datetime.now()
			profile.ipaddress=get_client_ip(request)
			profile.save()
			registered = True
		else:
			print user_form.errors, profile_form.errors
			messages.info(request,str(user_form.errors)+str(profile_form.errors))
	else:
		user_form = UserForm()
		profile_form = UserProfileForm()
	return render(request,'site/register.html',{'title':'Sign Up','current_page':'register',\
		'user_form':user_form,'profile_form':profile_form,'registered':registered})
Ejemplo n.º 8
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 = UserProfileForm(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 = UserProfileForm()

    # This is the render and context dictionary to feed
    # back to the registration.html file page.
    return render(
        request, 'app1/registration.html', {
            'user_form': user_form,
            'profile_form': profile_form,
            'registered': registered
        })
Ejemplo n.º 9
0
def update_user(request, user_id_pk):
    instance = Person.objects.get(pk=user_id_pk)
    form = UserForm(instance=instance)
    if request.method == 'POST':
        form = UserForm(request.POST, instance=instance)
        if form.is_valid():
            form.save()
            return redirect('/view')
    context = {'form': form}
    return render(request, 'app1/edit.html', context)
Ejemplo n.º 10
0
def saveUser(request):
    # if not request.session.has_key('username'):
    # return HttpResponseRedirect('login')
    print("new")
    form = UserForm()
    if request.method == 'POST':
        print("called")
        form = UserForm(request.POST, request.FILES)
        print("ok")
        if form.is_valid():
            form.save()
            return redirect('usertable')
        else:
            return HttpResponse("*****ERROR IN VALIDATION******")
    return render(request, 'useradd.html', {"form": form})
Ejemplo n.º 11
0
def manage(request):
    usr_id = int(request.GET["id"])
    form = UserForm()
    if usr_id > 0:
        ob = User.objects.get(id=usr_id)
        form = UserForm(instance=ob)

    if request.method == 'POST':
        form = UserForm(request.POST, request.FILES)
        if usr_id > 0:
            form = UserForm(request.POST, request.FILES, instance=ob)
        if form.is_valid():
            form.save()
            return redirect('usertable')

    return render(request, 'useradd.html', {"form": form, "id": usr_id})
Ejemplo n.º 12
0
def register(request):
    registered = False
    error_s = ""
    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(commit=False)
            user.set_password(user.password)
            user.username = user.email
            user.save()
            profile = profile_form.save(commit=False)
            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()
            registered = True

        else:
            print(user_form.errors, profile_form.errors)
            error_s1 = str(user_form.errors)
            error_s2 = str(profile_form.errors)
            user_form = UserForm()
            return render(
                request, 'app1/registration.html', {
                    'error_s1': error_s1,
                    'error_s2': error_s2,
                    'user_form': user_form,
                    'profile_form': profile_form
                })

    else:
        user_form = UserForm()
        profile_form = UserProfileInfoForm()
    return render(
        request, 'app1/registration.html', {
            'user_form': user_form,
            'profile_form': profile_form,
            'registered': registered
        })
Ejemplo n.º 13
0
def register(request):
    # Like before, get the request's context.
    context = RequestContext(request)

    # A boolean value for telling the template whether the registration was successful.
    # Set to False initially. Code changes value to True when registration succeeds.
    registered = False

    # If it's a HTTP POST, we're interested in processing form data.
    if request.method == 'POST':
        # Attempt to grab information from the raw form information.
        # Note that we make use of both UserForm and UserProfileForm.
        user_form = UserForm(data=request.POST)

        # If the two forms are valid...
        if user_form.is_valid():
            # Save the user's form data to the database.
            user = user_form.save()

            # Now we hash the password with the set_password method.
            # Once hashed, we can update the user object.
            user.set_password(user.password)
            user.save()

            # Update our variable to tell the template registration was successful.
            registered = True

        # Invalid form or forms - mistakes or something else?
        # Print problems to the terminal.
        # They'll also be shown to the user.
        else:
            #print user_form.errors

    # Not a HTTP POST, so we render our form using two ModelForm instances.
    # These forms will be blank, ready for user input.
    else:
     user_form = UserForm()

    # Render the template depending on the context.
    return render_to_response(
            'app1/register.html',
            {'user_form': user_form, 'registered': registered},
            context)
Ejemplo n.º 14
0
def register(request):
    registered = False

    if request.method == 'POST':
        user_form = UserForm(data=request.POST)
        if user_form.is_valid():
            user_form.save()
            registered = True

        else:
            print(user_form.errors)

    else:
        user_form = UserForm()

    return render(request, 'app1/registration.html', {
        'user_form': user_form,
        'registered': registered
    })
def user_signup(request):
    """
    A function used to allow user to sign up.
    :author Nourhan Fawzy:
    :param request:
    :return render_to_response:
    """

    registered = False

    if request.method == 'POST':
        user_form = UserForm(data=request.POST)
        library_form = LibraryForm(data=request.POST)

        if user_form.is_valid() and library_form.is_valid():
            # Save the user's form data to the database.
            user = user_form.save()
            user.set_password(user.password)
            user.save()
            user_library = library_form.save(commit=False)
            user_library.created_by = user
            user_library.save()
            registered = True
        else:
            print user_form.errors, library_form.errors

    else:
        user_form = UserForm()
        library_form = LibraryForm()
        return render_to_response(
            'sign_up.html',
            {'user_form': user_form, 'library_form': library_form,
            'registered': registered},
            context_instance=RequestContext(request))

    return render_to_response(
                'home.html', {'user': user, 'user_library': user_library,
                'registered': registered},
                context_instance=RequestContext(request))
Ejemplo n.º 16
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()

            # commit=False -> not yet submited to db
            profile = profile_form.save(commit=False)
            # get the user
            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,
                  'app1/register.html',
                  context={
                      'user_form': user_form,
                      'profile_form': profile_form,
                      'registered': registered
                  })
Ejemplo n.º 17
0
def create_user(request):
    if request.method == 'POST':
        form = UserForm(request.POST)
        if form.is_valid():
            first_name = form.cleaned_data['first_name']
            last_name = form.cleaned_data['last_name']
            dob = form.cleaned_data['dob']
            gender = form.cleaned_data['gender']

            Person.objects.create(first_name=first_name,
                                  last_name=last_name,
                                  dob=dob,
                                  gender=gender)
            context = {
                'name': first_name,
                'dob': dob,
                'gender': gender,
            }
    else:
        form = UserForm()
        context = {
            'form': form,
        }
    return render(request, 'app1/add.html', context)
Ejemplo n.º 18
0
def register(request):
    if request.method == 'GET':
        return render(request, 'register.html')
    elif request.method == 'POST':
        user_form = UserForm(request.POST)
        user_profile_form = UserProfileForm(request.POST)
        if user_form.is_valid() and user_profile_form.is_valid():
            user_model = User(username=request.POST['username'],
                              email=request.POST['email'],
                              password=request.POST['password'],
                              first_name=request.POST['first_name'],
                              last_name=request.POST['last_name'])
            user_model.set_password(user_model.password)
            user_model.save()
            user_profile_model = UserProfile(
                mobile_number=request.POST['mobile_number'],
                social=request.POST['social'],
                user=user_model)

            user_profile_model.save()

            return HttpResponseRedirect('/login/')
        else:
            return HttpResponse(form.errors)