Exemple #1
0
def edit_profile(request):
    try:
        Profile.objects.get(user=request.user)
    except:
        raise Http404("Profile does not exist. Contact Admin")

    js_script = """<script>var simplemde = new SimpleMDE({ element: $("#id_profile_page_markdown")[0], forceSync:true }); </script>"""
    context = {'js_script': js_script}
    if request.method == 'POST':
        submitted_user_form = UserForm(request.POST, instance=request.user)
        submitted_profile_form = EditProfileForm(request.POST,
                                                 request.FILES,
                                                 instance=request.user.profile)
        if submitted_profile_form.is_valid() and submitted_user_form.is_valid(
        ):
            submitted_user_form.save()
            submitted_profile_form.save()
            return redirect(reverse('dashboard'))
        else:
            context['user_form'] = submitted_user_form
            context['profile_form'] = submitted_profile_form
            return render(request, 'website/editprofile.html', context)

    user_form = UserForm(instance=request.user)
    profile_form = EditProfileForm(instance=request.user.profile)
    context['user_form'] = user_form
    context['profile_form'] = profile_form
    return render(request, 'website/editprofile.html', context)
Exemple #2
0
def account_edit(request):
    #import ipdb; ipdb.set_trace()
    form = UserForm(instance=request.user)
    if request.method == 'POST':
        form = UserForm(request.POST, instance=request.user)
        #import ipdb; ipdb.set_trace()
        if form.is_valid():
            form.save()
    return render(request, "website/account_edit.html",{
    'user': request.user,
    'form': form
    })
def register(request):
	context = RequestContext(request)
	registered = False
	if request.method == 'POST':
		user_form = UserForm(data=request.POST)
		profile_form = UserProfileForm(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 'picture' in request.FILES:
				profile.picture = request.FILES['picture']

			profile.save()

			registered = True

		else:
			print user_form.errors, profile_form.errors

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

	return render_to_response('HTML/register.html', {'user_form': user_form, 'profile_form': profile_form, 'registered': registered}, context)
Exemple #4
0
def register(request):
    '''Handles the creation of a new user for authentication

    Method arguments:
      request -- The full HTTP request object
    '''

    registered = False


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

        if user_form.is_valid() and profile_form.is_valid():
            print("valid")

            form_data = request.POST
            state = form_data["state"]
            user = user_form.save()
            user.set_password(user.password)
            user.save()
            profile = Profile.objects.create(state=state, user=user)
            profile.save()

            registered = True

        return login_user(request)

    elif request.method == 'GET':
        user_form = UserForm()
        profile_form = ProfileForm()
        template_name = 'register.html'
        context = {'user_form': user_form, 'next': request.GET.get('next', '/'), 'profile_form': profile_form}
        return render(request, template_name, context)
def register(request):
    '''Handles the creation of a new user for authentication

    Method arguments:
      request -- The full HTTP request object
    '''

    # 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

    # Create a new user by invoking the `create_user` helper method
    # on Django's built-in User model
    if request.method == 'POST':
        user_form = UserForm(data=request.POST)

        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

        return login_user(request)

    elif request.method == 'GET':
        user_form = UserForm()
        template_name = 'register.html'
        return render(request, template_name, {'user_form': user_form})
Exemple #6
0
def register(request):
    """
    purpose: allow a user to register an account
    author: Helana Nosrat, Kayla Brewer
    args: pulls information from two forms(user_form and profile_form) and sends that information to the database 
        as a POST to the user and userprofile models
    """

    registered = False

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

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

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

            user_profile.save()
            registered = True

        return login_user(request)

    elif request.method == 'GET':
        user_form = UserForm()
        profile_form = UserProfileForm()
        template_name = 'register.html'
        return render(request, template_name,
                      {'user_form': user_form, 'profile_form': profile_form, 'registered': registered})
def register(request):
    context = RequestContext(request)
    registered = False
    if request.method == 'POST':
        user_form = UserForm(data=request.POST)
        profile_form = UserProfileForm(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 'picture' in request.FILES:
                profile.picture = request.FILES['picture']

            profile.save()

            registered = True

        else:
            print user_form.errors, profile_form.errors

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

    return render_to_response(
        'HTML/register.html', {
            'user_form': user_form,
            'profile_form': profile_form,
            'registered': registered
        }, context)
Exemple #8
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:
                print('found it')
                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, 'website/registration.html', {
            'user_form': user_form,
            'profile_form': profile_form,
            'registered': registered
        })
Exemple #9
0
def register(request):

    if not request.user.is_authenticated():

        # 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)
            profile_form = UserProfileForm(data=request.POST)

            # If the two forms are valid...
            if user_form.is_valid() and profile_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()

                # Now sort out the UserProfile instance.
                # Since we need to set the user attribute ourselves, we set commit=False.
                # This delays saving the model until we're ready to avoid integrity problems.
                profile = profile_form.save(commit=False)
                profile.user = user
                # Now we save the UserProfile model instance.
                profile.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 :" + str(user_form.errors) +
                      "Profile Form Errors" + str(profile_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()
            profile_form = UserProfileForm()

        # Render the template depending on the context.
        return render(
            request, 'website/index.html', {
                'user_reg_form': user_form,
                'user_profile_form': profile_form,
                'registered': registered
            })
    else:
        return redirect('/dashboard/')
Exemple #10
0
def register(request):

    if not request.user.is_authenticated():

            # 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)
                profile_form = UserProfileForm(data=request.POST)

                # If the two forms are valid...
                if user_form.is_valid() and profile_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()

                    # Now sort out the UserProfile instance.
                    # Since we need to set the user attribute ourselves, we set commit=False.
                    # This delays saving the model until we're ready to avoid integrity problems.
                    profile = profile_form.save(commit=False)
                    profile.user = user
                    # Now we save the UserProfile model instance.
                    profile.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 :" + str(user_form.errors) + "Profile Form Errors" + str(profile_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()
                profile_form = UserProfileForm()

            # Render the template depending on the context.
            return render(request, 'website/index.html', {'user_reg_form': user_form, 'user_profile_form': profile_form,
                                                          'registered': registered})
    else:
            return redirect('/dashboard/')
Exemple #11
0
def sign_up(request):
    # A boolean value for telling the template
    # whether the registration was successful.
    registered = False

    if request.method == "POST":
        user_form = UserForm(request.POST, request.FILES)
        profile_form = UserProfileForm(request.POST, request.FILES)

        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 picture if available
            if "picture" in request.FILES:
                profile.picture = request.FILES["picture"]

            profile.save()

            # Update our variable to indicate that the template
            # registration was successful.
            registered = True
        else:
            render(
                request,
                "SkyView/signUp.html",
                context={
                    "user_form": user_form,
                    "profile_form": profile_form,
                    "registered": registered,
                },
            )
    else:
        user_form = UserForm()
        profile_form = UserProfileForm()

    return render(
        request,
        "SkyView/signUp.html",
        context={
            "user_form": user_form,
            "profile_form": profile_form,
            "registered": registered,
        },
    )
Exemple #12
0
def register(request):
    """
    Handles the creation of a new user for authentication

    ---Arguments---
    None

    ---GET---
    Renders register.html

        ---Context---
        'user_form': the form from user_form.py

    ---POST---
    runs the login_user function

    Author: Steve Browlee
    """

    # 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

    # Create a new user by invoking the `create_user` helper method
    # on Django's built-in User model
    if request.method == 'POST':
        user_form = UserForm(data=request.POST)

        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

        return login_user(request)

    elif request.method == 'GET':
        user_form = UserForm()
        template_name = 'register.html'
        return render(request, template_name, {'user_form': user_form})
def register(request):
    '''Handles the creation of a new user for authentication

    Method arguments:
      request -- The full HTTP request object
    '''

    # 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

    # Create a new user by invoking the `create_user` helper method
    # on Django's built-in User model
    if request.method == 'POST':
        user_form = UserForm(data=request.POST)
        customer_form = CustomerForm(data=request.POST)

        if user_form.is_valid() and customer_form.is_valid():
            # Save the user's form data to the database.
            user = user_form.save()
            customer = customer_form.save(commit=False)
            customer.user = user
            customer.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
            payment = PaymentType.objects.create(name="southwest",
                                                 accountNumber="12355346",
                                                 customer=customer)
            user_id = user.id
            Order.objects.create(isCompleted=0,
                                 customer=customer,
                                 paymentType=payment)

        return login_user(request)

    elif request.method == 'GET':
        user_form = UserForm()
        customer_form = CustomerForm()
        template_name = 'register.html'
        return render(request, template_name, {
            'user_form': user_form,
            'customer_form': customer_form
        })
Exemple #14
0
def register(request):
    if request.method == "POST":
        form = UserForm(request.POST)

        if form.is_valid():
            user = form.save()
            messages.success(request, "Your Account Was Created Successfully")
            login(request, user)
            return redirect("website:homepage")

        else:
            form = UserForm()
    form = UserForm
    return render(request=request,
                  template_name="website/register.html",
                  context={"form": form})
Exemple #15
0
def register(request):
    if request.user.is_anonymous():
        user_form = UserForm(request.POST or None)
        reporter_form = ReporterForm(request.POST or None)
        if request.method == "POST":
            if user_form.is_valid() and reporter_form.is_valid():
                user = user_form.save()
                user.save()

                reporter = reporter_form.save(commit=False)
                reporter.user = user
                reporter.save()
                return HttpResponseRedirect('/login')
        return render(request, 'registration/register.html', {'userForm': user_form, 'reporterForm': reporter_form})
    else:
        return HttpResponseRedirect('/')
Exemple #16
0
def register(request):
    """
    purpose: Handles the creation of a new user for authentication

    author: steve brownlee

    args: request -- The full HTTP request object

    returns: render of a registration from or invocation of django's login() method
    """

    # 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

    # Create a new user by invoking the `create_user` helper method
    # on Django's built-in User model
    if request.method == 'POST':
        user_form = UserForm(data=request.POST)
        profile_form = ProfileForm(data=request.POST)

        if user_form.is_valid() and profile_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()   

            user.profile.phone_number = profile_form.cleaned_data['phone_number'] 
            user.profile.address = profile_form.cleaned_data['address'] 
            user.save()            

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

        return login_user(request)

    elif request.method == 'GET':
        user_form = UserForm()
        profile_form = ProfileForm()
        template_name = 'register.html'
        return render(request, template_name, {
            'user_form': user_form,
            'profile_form': profile_form})
Exemple #17
0
def register(request):
    registered = False
    if request.method == 'POST':
        user_form = UserForm(data=request.POST)

        if user_form.is_valid():
            user = user_form.save()
            user.set_password(user.password)
            user.save()
            registered = True

        return login_user(request)

    elif request.method == 'GET':
        user_form = UserForm()
        template_name = 'register.html'
        return render(request, template_name, {'user_form': user_form})
Exemple #18
0
def register(request):
    '''Handles the creation of a new user for authentication

    Method arguments:
      request -- The full HTTP request object
    '''

    # 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

    # Create a new user as well as a new customer at the same time
    if request.method == 'POST':
        user_form = UserForm(data=request.POST)
        customer_form = CustomerForm(data=request.POST)
        confirm_password = request.POST['confirm_password']
        newPassword = request.POST.get('password')
        if user_form.is_valid() and customer_form.is_valid():
            if newPassword == confirm_password:
                user = user_form.save()
                customer = customer_form.save()
                customer.user = user
                user.set_password(user.password)
                user.save()
                customer.save()
                return login_user(request)
            else:

                # print("user form", newPassword)
                # print("confirm", confirm_password)
                print("passwords don't match")
                template_name = 'error.html'
                return render(request, template_name)
        else:
            print("not valid user form")

    elif request.method == 'GET':
        user_form = UserForm()
        customer_form = CustomerForm()
        template_name = 'register.html'
        return render(request, template_name, {
            'user_form': user_form,
            'customer_form': customer_form
        })
Exemple #19
0
def register(request):
    registered = False
    if request.method == 'POST':
        user_form = UserForm(data=request.POST)
        if user_form.is_valid():
            user = user_form.save()
            user.set_password(user.password)
            user.save()
            registered = True
        else:
            pass
    else:
        user_form = UserForm()

    return render(
        request,
        'register.html',
        {'user_form': user_form,
         'registered': registered})
Exemple #20
0
def register(request):
    #registered = False

    if request.method == 'POST':
        user_form = UserForm(data=request.POST)
        profile_form = UserProfileForm(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.is_active = False
            user.save()

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

            current_site = get_current_site(request)
            subject = 'activate your account'
            message = render_to_string(
                'registration/account_activation_email.html', {
                    'user': user,
                    'domain': current_site.domain,
                    'uid': urlsafe_base64_encode(force_bytes(user.pk)),
                    'token': account_activation_token.make_token(user),
                })
            user.email_user(subject, message)
            return redirect('account_activation_sent')
        #   registered = True
        #  user_form = UserForm()
        # profile_form = UserProfileForm()
        else:
            print user_form.errors, profile_form.errors

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

    return render(request, 'registration/registration_form.html', {
        'user_form': user_form,
        'profile_form': profile_form
    })
def register(request):
    '''Handles the creation of a new user for authentication
    Method arguments:
      request -- The full HTTP request object
    '''

    # 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

    # Create a new user by invoking the `create_user` helper method
    # on Django's built-in User model
    if request.method == 'POST':
        user_form = UserForm(data=request.POST)
        profile_form = ProfileForm(data=request.POST)

        if user_form.is_valid():
            # Save the user's form data to the database.
            user = user_form.save()
            profile = profile_form.save(commit=False)
            profile.user = user
            profile.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

        return login_user(request)

    elif request.method == 'GET': # If we go to /register, this will load. 
        profile_form = ProfileForm()
        user_form = UserForm() # UserForm is from Django, 
        return render(request, 'register.html', {'user_form': user_form, 'profile_form': profile_form})  # renders form
        # {'user_form': user_form} <-- this contains the form objects