def register(request):
    # Like before, get the request's context.
    context = RequestContext(request)
    serverUser=getpass.getuser()
    registered = False
    profile_form = UserProfileForm()
    if request.method == 'POST':
        #user_form = UserForm(data=request.POST)
        profile_form = UserProfileForm(data=request.POST)
        if  profile_form.is_valid():
            profile = profile_form.save(commit=False)
            profile.save()
            registered = True
            username=request.POST["username"]
            request.session["username"]=username
            file_name="/home/"+serverUser+"/Desktop/submit/"+username
            file_name="_".join(file_name.split(" "))
            fans=open(file_name,"w")
            for i in range(20):
                fans.write("Copy-paste your command here")
                fans.write("\n")
            return HttpResponseRedirect('/home/1/')

        else:
            print  profile_form.errors
            return render_to_response(
                'home/register.html',
                { 'profile_form': profile_form, 'registered': registered},
                context)

    else:
        return render_to_response(
                'home/register.html',
                { 'profile_form': profile_form, 'registered': registered},
                context)
Esempio n. 2
0
def register(request):
    # Like before, get the request's context.
    context = RequestContext(request)
    registered = False
    profile_form = UserProfileForm()
    if request.method == 'POST':
        #user_form = UserForm(data=request.POST)
        profile_form = UserProfileForm(data=request.POST)
        if  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
            username=request.POST["username"]
            request.session["username"]=username
            return HttpResponseRedirect('/home/')

        else:
            print  profile_form.errors
            return render_to_response(
                'home/register.html',
                { 'profile_form': profile_form, 'registered': registered},
                context)

    else:
        return render_to_response(
                'home/register.html',
                { 'profile_form': profile_form, 'registered': registered},
                context)
Esempio n. 3
0
def register(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)
        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

            # Did the user provide a profile picture?
            # If so, we need to get it from the input form and put it in the UserProfile model.
            if 'picture' in request.FILES:
                profile.picture = request.FILES['picture']

            # 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, 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,
            'home/registration/register.html',
            {'user_form': user_form, 'profile_form': profile_form, 'registered': registered} )	
Esempio n. 4
0
def ProfileSettings(request, pk):

    users1 = UserProfile.objects.filter(id=pk).first()
    myprofileForm = UserProfileForm(request.POST or None,
                                    request.FILES or None,
                                    instance=users1)
    total_Notis = Notification.objects.filter(user=users1,
                                              viewed=False).all().count

    if myprofileForm.is_valid():
        myprofileForm.save()
        return redirect('UserProfile')

    context = {"count_notis": total_Notis, 'form': myprofileForm, 'u1': users1}
    return render(request, 'ProfileSettings.html', context)
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()
            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, profile_form.errors)

    return HttpResponse("Registered")
Esempio n. 6
0
def register(request):
    # Like before, get the request's context.
    context = RequestContext(request)
    registered = False
    profile_form = UserProfileForm()
    if request.method == 'POST':
        #user_form = UserForm(data=request.POST)
        profile_form = UserProfileForm(data=request.POST)
        if 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
            username = request.POST["username"]
            request.session["username"] = username
            return HttpResponseRedirect('/home/')

        else:
            print profile_form.errors
            return render_to_response('home/register.html', {
                'profile_form': profile_form,
                'registered': registered
            }, context)

    else:
        return render_to_response('home/register.html', {
            'profile_form': profile_form,
            'registered': registered
        }, context)
Esempio n. 7
0
def registered(request):
    registered = False
    if request.method == "POST":
        print(request.POST)
        print(request.FILES)
        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
            profile.save()
            registered = True
            login(request, user)
            return redirect("/home/user-demand")

        else:
            # user_errors = user_form.errors
            # profile_errors = profile_form.errors
            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,
            "registered": registered,
        },
    )
Esempio n. 8
0
def profile(request):
    if request.method == "POST":
        userform = UserForm(request.POST, instance=request.user)
        user_profile = UserProfile.objects.get(user=request.user)
        userprofileform = UserProfileForm(request.POST, instance=user_profile)
        try:
            pilot = Pilot.objects.get(user=request.user)
            pilotform = PilotProfileForm(request.POST, instance=pilot)
            pilot_valid = pilotform.is_valid()
            if pilot_valid:
                pilotform.save()
        except ObjectDoesNotExist:
            pilotform = None
            pilot_valid = True
        user_valid = userform.is_valid()
        user_profile_valid = userprofileform.is_valid()
        if pilot_valid and user_valid and user_profile_valid:
            change = "Changes Submitted"
            print("PILOT SAVED!")
        else:
            print("PILOT INVALID")
        if user_valid:
            userform.save()
            print("User SAVED!")
        if user_profile_valid:
            userprofileform.save()
            user_profile = UserProfile.objects.get(user=request.user)
            request.session["django_timezone"] = user_profile.timezone
            print("User Profile Saved!")
        else:
            print("USER INVALID")

    else:
        try:
            pilot = Pilot.objects.get(user=request.user)
            pilotform = PilotProfileForm(instance=pilot)
        except ObjectDoesNotExist:
            pilotform = None
        userform = UserForm(instance=request.user)
        userprofile = UserProfile.objects.get(user=request.user)
        userprofileform = UserProfileForm(instance=userprofile)
        change = ""

    return render(
        request,
        "home/profile.html",
        {
            "userform": userform,
            "change": change,
            "pilotform": pilotform,
            "userprofileform": userprofileform,
        },
    )
def nuevo_usuario(request):
	if not request.user.is_authenticated():
		return redirect('/')

	if request.method == 'POST':
		formulario = UsuarioForm(request.POST)
		adicional = UserProfileForm(request.POST)
		if formulario.is_valid() and adicional.is_valid():
			f = formulario.save()
			adicional.user = f
			adicional.save()
			messages.add_message(request, messages.SUCCESS, 'Se registró un nuevo usuario')
			return redirect('/art7admin/usuarios/')
	else:
		formulario = UsuarioForm()
		adicional = UserProfileForm()
	return render(request,'registro-usuario.html', { 'formulario':formulario, 'adicional':adicional})
Esempio n. 10
0
def signup(request):
    if request.method == "POST":
        form = SignUpForm(request.POST)
        profileform = UserProfileForm(request.POST)
        if form.is_valid():
            form.save()
            if profileform.is_valid():
                profileform.save()
            username = form.cleaned_data.get("username")
            raw_password = form.cleaned_data.get("password1")
            user = authenticate(request,
                                username=username,
                                password=raw_password)
            auth_login(request, user)
            return redirect("profile")
    else:
        form = SignUpForm()
        profileform = UserProfileForm()
    return render(request, "home/signup.html", {
        "form": form,
        "profileform": profileform
    })
Esempio n. 11
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)
        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)

            # Did the user provide a group?
            # If so, we need to get it from the post and put it in the User model, empty otherwise.
            user.groups.add(request.POST.get('group', ''))

            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

            # Did the user provide a profile picture?
            # If so, we need to get it from the input form and put it in the UserProfile model.
            if 'picture' in request.FILES:
                profile.picture = request.FILES['picture']

            # Now we save the UserProfile model instance.
            profile.save()

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

            # Register this user to all candidate questions
            registerNewUserToAllCandidateQuestions(user)

        # 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, 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_to_response(
        'home/register.html', {
            'user_form': user_form,
            'profile_form': profile_form,
            'registered': registered
        }, context)