Exemple #1
0
def send_update_profile(request):
    if request.method == 'POST':
        form = UserProfileForm(request.POST)
        if form.is_valid():
            userProfile = UserProfile.objects.get(user=request.user)
            description = form.cleaned_data['description']
            rank = form.cleaned_data['rank']
            weapon = form.cleaned_data['weapon']
            friend_code = form.cleaned_data['friend_code']
            hunter_name = form.cleaned_data['hunter_name']
            nintendo_name = form.cleaned_data['nintendo_name']
            skype_name = form.cleaned_data['skype_name']
            teamspeak_name = form.cleaned_data['teamspeak_name']
            userProfile.description = description
            userProfile.rank = rank
            userProfile.weapon = weapon
            userProfile.friend_code = friend_code
            userProfile.hunter_name = hunter_name
            userProfile.nintendo_name = nintendo_name
            userProfile.skype_name = skype_name
            userProfile.teamspeak_name = teamspeak_name
            userProfile.save()
            return redirect('/roster/profile/' + str(userProfile.id))

        else:
            form = UserProfileForm()

    return redirect('/roster/send_update_profile/')
Exemple #2
0
def profile_form(request,username,use_openid=False):
    if request.user.username != username:
        return HttpResponse( "You cannot access another user's profile.", status=401)
    else:
        user = User.objects.get(username=username)
        try:
            user_profile = UserProfile.objects.get(user=user)
        except UserProfile.DoesNotExist:
            user_profile = UserProfile.objects.create(user=user)

    user_assoc = UserAssociation.objects.filter(user__id=user.id)
    
    if request.method == 'GET':
        uform = UserForm(instance=user)
        pform = UserProfileForm(instance=user_profile)
        return render_to_response('user_profile/user_profile_form.html', 
                {'profile': user_profile, 'assoc': user_assoc, 'uform': uform, 'pform': pform, 
                    'group_request_email': settings.GROUP_REQUEST_EMAIL, 'use_openid': use_openid, 'MEDIA_URL':settings.MEDIA_URL}) 

    elif request.method == 'POST':
        uform = UserForm(data=request.POST, instance=user)
        pform = UserProfileForm(data=request.POST, instance=user_profile)
        if uform.is_valid():
            user.save()
        if pform.is_valid():
            user_profile.save()

        #return HttpResponseRedirect(reverse('user_profile-form', args=[username]))
        return HttpResponseRedirect(reverse('map'))
    else:
        return HttpResponse( "Received unexpected " + request.method + " request.", status=400 )
Exemple #3
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()

            user.set_password(user.password)
            user.save()

            profile = profile_form.save()

            profile.user = user
            profile.save()

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

    context_dict = {
        'user_form': user_form,
        'profile_form': profile_form,
        'registered': registered
    }

    return render(request, "register.html", context_dict)
Exemple #4
0
def editUserView(request, ID):
    user_info = User.objects.get(id=ID)
    profile_info = UserProfile.objects.get(user=user_info)
    if request.method == 'POST':
        permission_list = [int(i) for i in request.POST.getlist('permission')]
        user_form = UserForm(request.POST, instance=user_info)
        profile_form = UserProfileForm(request.POST, instance=profile_info)
        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()
            for i in profile.permission.all():
                profile.permission.remove(i)
            for i in permission_list:
                profile.permission.add(Game.objects.get(id=i))
            return HttpResponseRedirect(reverse('userlisturl'))
    else:
        user_form = UserForm(instance=user_info)
        profile_form = UserProfileForm(instance=profile_info)
    context_dict = {
        'ID': ID,
        'user_form': user_form,
        'profile_form': profile_form,
    }
    return render(request, 'common/edituser.html', context_dict)
Exemple #5
0
def user_profile(request):

    if request.method == 'POST':
        basicform = UserBasicForm(request.POST, instance=request.user)
        extraform = UserProfileForm(request.POST,
                                    request.FILES,
                                    instance=request.user.profile)

        if extraform.is_valid() and basicform.is_valid():
            basicform.save()
            extraform.save()
            messages.success(request, "Changes saved")
            return HttpResponseRedirect('/')
    else:
        user = request.user
        profile = user.profile
        basicform = UserBasicForm(instance=user)
        extraform = UserProfileForm(instance=profile)

        args = {}
        args.update(csrf(request))
        args['basicform'] = basicform
        args['extraform'] = extraform

        return render(request, 'profile.html', args)
Exemple #6
0
def add_user(request):
    registered = False
    if request.method == 'POST':
        profile_form = UserProfileForm(data=request.POST)
        device_form = UserDeviceForm(data=request.POST)
        if profile_form.is_valid():
            userprofile = profile_form.save()
            userprofile.last_played = datetime.datetime.now()
            if 'song' in request.FILES:
                userprofile.song = request.FILES['song']
            userprofile.save()
            if device_form.is_valid():
                deviceform = device_form.save()
                deviceform.user_profile = userprofile
                deviceform.save()
            registered = True
    else:
        profile_form = UserProfileForm()
        device_form = UserDeviceForm()

    return render(
        request, 'add_user.html', {
            'profile_form': profile_form,
            'device_form': device_form,
            'registered': registered
        })
def my_profile(request):
    context = get_context(request)
    if not request.user.is_authenticated():
        return redirect('login')
    else:
        user_profile = UserProfile.objects.get(user=request.user)
        if request.method == "POST":
            user_form = UserForm(request.POST, instance=request.user)
            user_profile_form = UserProfileForm(request.POST,
                                                instance=user_profile)
            if user_form.is_valid() and user_profile_form.is_valid():
                user_form.save()
                user_profile_form.save()

            return redirect_after_profile_save(request, 'data')
        else:
            user_form = UserForm(instance=request.user)
            user_profile_form = UserProfileForm(instance=user_profile)
            user_form.helper.form_tag = False
            user_profile_form.helper.form_tag = False
            context['user_form'] = user_form
            context['user_profile_form'] = user_profile_form
            context['user_profile_page_form'] = UserProfilePageForm(
                instance=user_profile)
            context['user_cover_letter_form'] = UserCoverLetterForm(
                instance=user_profile)
            context['user_info_page_form'] = UserInfoPageForm(
                instance=user_profile.user_info)
            context['is_editing_profile'] = True
            context['title'] = u'Mój profil'

            return render(request, 'profile.html', context)
Exemple #8
0
def addUserView(request):
    if request.method == 'POST':
        permission_list = [int(i) for i in request.POST.getlist('permission')]
        print permission_list
        user_form = UserForm(request.POST)
        profile_form = UserProfileForm(request.POST)
        if user_form.is_valid() and profile_form.is_valid():
            #  import pdb; pdb.set_trace()
            user = user_form.save()
            user.set_password(user.password)
            user.save()
            profile = profile_form.save(commit=False)
            profile.user = user
            profile.save()
            for i in permission_list:
                profile.permission.add(Game.objects.get(id=i))
            return HttpResponseRedirect(reverse('userlisturl'))
    else:
        user_form = UserForm()
        profile_form = UserProfileForm()
    context_dict = {
        'user_form': user_form,
        'profile_form': profile_form,
    }
    return render(request, 'common/adduser.html', context_dict)
Exemple #9
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()
			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(request, 'register.html', { 'user_form': user_form,
											'profile_form':profile_form,
											'registered':registered }
											)
Exemple #10
0
def edit_profile(request):
    args = {}
    args.update(csrf(request))
    if request.method == 'POST':
        form = UserProfileForm(request.POST,
                               request.FILES,
                               instance=request.user.profile)
        follow = userFollowActivity.objects.get(user=request.user)
        generes = Generes.objects.get(user=request.user)

        first_name = request.user.first_name
        last_name = request.user.last_name
        if form.is_valid():
            form.save()
            return HttpResponseRedirect('/accounts/loggedin/')
    else:
        form = UserProfileForm(instance=request.user.profile)
        generes = Generes.objects.get(user=request.user)
        follow = userFollowActivity.objects.get(user=request.user)
        first_name = request.user.first_name
        last_name = request.user.last_name

    args = {}
    args.update(csrf(request))
    args['form'] = form

    return render_to_response('editprofilepage.html', {
        'form': form,
        'follow': follow,
        'first_name': first_name,
        'last_name': last_name,
        'generes': generes
    },
                              context_instance=RequestContext(request))
Exemple #11
0
def register(request):
    # Like before, get the request's context.
    context = RequestContext(request)

    if request.user.is_authenticated:
        #return HttpResponseRedirect('/profile')

        #else:

        # 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':
            user_form = UserForm(data=request.POST)
            profile_form = UserProfileForm(data=request.POST)
            validation_form = ValidationForm(data=request.POST)

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

                user.set_password(user.password)
                user.save()

                profile = profile_form.save(commit=False)
                profile.user = user
                profile.user_since = datetime.datetime.today()

                if 'picture' in request.FILES:
                    profile.picture = request.FILES['picture']

                user_id = user.id
                if user_id % 2 is 0:
                    profile.condition = 1
                elif user_id % 2 is not 0:
                    profile.condition = 2

                profile.save()
                registered = True
                new_user = authenticate(username=request.POST['username'],
                                        password=request.POST['password'])
                login(request, new_user)

            else:
                print user_form.errors, profile_form.errors, validation_form.errors

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

        return render_to_response(
            'badsearch/register.html', {
                'user_form': user_form,
                'profile_form': profile_form,
                'validation_form': validation_form,
                'registered': registered
            }, context)
Exemple #12
0
def user_profile(request):
    if request.session['email']:
        if request.method == 'POST':
            a = Join.objects.get(email=request.session['email'])
            try:
                b = UserProfile.objects.get(user=a)
            except:
                b = UserProfile(user=a)
                b.save()
                b = UserProfile.objects.get(user=a)
            form = UserProfileForm(request.POST, instance=b)
            if form.is_valid():
                f = form.save(commit=False)
                f.user = a
                f.save()
                return HttpResponseRedirect('/fb/login/')
            else:
                return render(request, 'fb/profile.html', {'form': form})
        else:
            a = Join.objects.get(email=request.session['email'])
            try:
                b = UserProfile.objects.get(user=a)
            except:
                b = UserProfile(user=a)
                b.save()
                b = UserProfile.objects.get(user=a)
            form = UserProfileForm(instance=b)
            return render(request, 'fb/profile.html', {'form': form})
    else:
        return HttpResponseRedirect('/fb/login/')
Exemple #13
0
def profile_edit(request):

    if request.method == "POST":
        user_form = UserEditForm(request.POST,
                                 request.FILES,
                                 instance=request.user)
        profile_form = UserProfileForm(request.POST,
                                       request.FILES,
                                       instance=request.user.user)

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

        return redirect('profile')
    else:
        if not request.user:
            return redirect('login')
        else:
            user_form = UserEditForm(instance=request.user)
            profile_form = UserProfileForm(instance=request.user.user)
            return render(request, 'campusthrift/profile_edit.html', {
                'user_form': user_form,
                'profile_form': profile_form
            })
Exemple #14
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(request.POST,request.FILES)
       # p = UserProfileForm(data=request.FILES)
        # If the two forms are valid...
        if user_form.is_valid() and profile_form.is_valid():# and p.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:
               # p.picture = request.FILES['picture']
               # p.save()
               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_to_response(
            'registration.html',
            {'user_form': user_form, 'profile_form': profile_form, 'registered': registered},
            context)
Exemple #15
0
def user_profile_edit(request):

    instance1 = get_object_or_404(User, id=request.user.id)
    instance2 = get_object_or_404(UserProfile, id=request.user.profile.id)
    args = {}

    args.update(csrf(request))
    if request.method == "POST":
        form1 = RegistrationForm(request.POST, instance=instance1)
        form2 = UserProfileForm(request.POST,
                                request.FILES,
                                instance=instance2)
        args["err"] = form1.errors
        args["err2"] = form2.errors
        if form1.is_valid() * form2.is_valid():
            user = form1.save()
            userprofile = form2.save(commit=False)
            userprofile.user = user
            userprofile.save()
            return HttpResponseRedirect('/dashboard')

    args["form"] = RegistrationForm(instance=instance1)
    args["form2"] = UserProfileForm(instance=instance2)
    args["form_title"] = "Edit Profile Info"
    return render(request, 'register.html', args, RequestContext(request))
Exemple #16
0
def login(request):
    if request.user.is_authenticated():  # if there is a user logged in already
        user_name = UserProfile(name=request.user.username)

        if request.POST:
            form = UserProfileForm(request.POST, instance=user_name)
            if form.is_valid():
                form.save()
                return HttpResponseRedirect('/')
        else:
            form = UserProfileForm(instance=user_name)

        args = {}
        args.update(csrf(request))

        args['form'] = UserProfileForm()
        print args
        context = {"full_name": request.user.username, "args": args}
        return HttpResponseRedirect("", context)
    else:
        c = {}

        c.update(csrf(request))

        context = {"c": c}
        return render(request, "login.html", context)
def user_profile(request):
    if request.method == 'POST':
        form = UserProfileForm(request.POST, instance=request.user.profile)
        if form.is_valid():
            form.save()
            return HttpResponseRedirect('/diary/%s' % request.user.profile.id)
    else:
        user = request.user
        profile = user.profile
        form = UserProfileForm(instance=profile)

    args = {}
    args.update(csrf(request))

    args['form'] = form
    args['username'] = request.user.username
    args['user_profile_id'] = request.user.profile.id
    return render_to_response('profile.html', args)


# def list_api(request):
#     item_list = UserProfile.objects.all()
#     output_list = []
#
#     for item in item_list:
#         output_item = {}
#         output_item["system_id"] = item.id
#         output_item["first_name"] = item.first_name
#         output_list.append(output_item)
#
#     return HttpResponse(
#         json.dumps(output_list),
#         content_type="application/json"
#     )
Exemple #18
0
def register(request, type):
    if type not in ['subject', 'tester']:
        raise Exception('register: invalid type.')
    if request.method == 'POST':
        rform = RegistrationForm(request.POST)
        pform = UserProfileForm(request.POST)
        if rform.is_valid() and pform.is_valid():
            user = rform.save()
            if type == 'subject':
                group = Group.objects.get(name='Subjects')
            elif type == 'tester':
                group = Group.objects.get(name='Testers')
            user.groups.add(group)
            profile = pform.save(commit=False)
            profile.user = user
            profile.save()
            if type == 'tester':
                create_log_entry(profile, 'joined', [])
            return HttpResponseRedirect(reverse('home'))
    else:
        rform = RegistrationForm()
        pform = UserProfileForm()
    return render_to_response('testtool/registration/register.html', {
        'rform': rform,
        'pform': pform
    },
                              context_instance=RequestContext(request))
Exemple #19
0
def edit_profile(request):

    user = User.objects.get(username=request.user)

    if request.method == "POST":
        form = UserProfileForm(request.POST, request.FILES)
        if form.is_valid():

            model_instance = form.save(commit=False)
            user_profile = UserProfile.objects.filter(user=user)[0]
            model_instance.id = user_profile.id
            model_instance.user_id = user_profile.user_id
            if request.FILES:
                model_instance.picture = request.FILES['picture']
            else:
                model_instance.picture = user_profile.picture

            if request.POST['description']:
                model_instance.description = request.POST['description']
            else:
                model_instance.description = user_profile.description

            model_instance.save()

            message = 'Your edit was successful!'

            context = {'message': message, 'model_instance': model_instance}
            return render(request, "thanks.html", context)
    else:
        form = UserProfileForm()

    context = {'form': form}

    return render(request, "edit_profile.html", context)
def register(request):
    if request.session.test_cookie_worked():
        print(">>>>>TEST COOKIE WORKED!")
        request.session.delete_test_cookie()
    # Request the context.
    context = RequestContext(request)
    context_dict = {}
    # Boolean telling us whether registration was successful or not.
    # Initially False; presume it was a failure until proven otherwise!
    registered = False

    # If HTTP POST, we wish to process form data and create an account.
    if request.method == 'POST':
        # Grab raw form data - making use of both FormModels.
        user_form = UserForm(data=request.POST)
        profile_form = UserProfileForm(data=request.POST)

        # Two valid forms?
        if user_form.is_valid() and profile_form.is_valid():
            # Save the user's form data. That one is easy.
            user = user_form.save()

            # Now a user account exists, we hash the password with the set_password() method.
            # Then we can update the account with .save().
            user.set_password(user.password)
            user.save()

            # Now we can sort out the UserProfile instance.
            # We'll be setting values for the instance ourselves, so commit=False prevents Django from saving the instance automatically.
            profile = profile_form.save(commit=False)
            profile.user = user

            # Profile picture supplied? If so, we put it in the new UserProfile.
            if 'picture' in request.FILES:
                profile.picture = request.FILES['picture']

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

            # We can say registration was successful.
            registered = True

        # Invalid form(s) - just print errors to the terminal.
        else:
            print user_form.errors, profile_form.errors

    # Not a HTTP POST, so we render the two ModelForms to allow a user to input their data.
    else:
        user_form = UserForm()
        profile_form = UserProfileForm()

    context_dict['user_form'] = user_form
    context_dict['profile_form'] = profile_form
    context_dict['registered'] = registered

    # Render and return!
    return render_to_response('rango/register.html', context_dict, context)
Exemple #21
0
def user_profile(request):
    ensure_profile(request.user)

    if request.method == 'POST':
        form = UserProfileForm(request.POST, instance=request.user.userprofile)
        if form.is_valid():
            form.save()
            return redirect(request.user.get_absolute_url())
    else:
        form = UserProfileForm(instance=request.user.userprofile)
    return render(request, "users/user_profile.html", {"form": form})
Exemple #22
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 post, process 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

            profile.save()
            registered = True

        # invalid form
        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, "register.html", {
            'user_form': user_form,
            'profile_form': profile_form,
            'registered': registered
        })
Exemple #23
0
def register(request):
    # Register users in the system
    context = RequestContext(request)
    email_in_db = False
    registered = False
    username_taken = False
    if request.method == 'POST':
        user_data = request.POST
        user_data['username'] = user_data['username'].strip()
        user_form = UserForm(user_data)
        profile_form = UserProfileForm(user_data)
        # If the two forms are valid...
        if user_form.is_valid() and profile_form.is_valid():
            user = user_form.save(commit=False)
            # c heck if email is in the database
            email_to_be_checked = user.email
            # if no user has this email, the query will result in an error, then
            # the except statement will be executed, resulting in a successful registration
            try:
                test_user = User.objects.get(email=email_to_be_checked)
                email_in_db = True
            except User.DoesNotExist:
                # save user and user_profile, and sign in the user with the non-hashed password
                non_hashed_password = user.password
                user.set_password(non_hashed_password)
                user.save()
                profile = profile_form.save(commit=False)
                profile.user = user
                profile.save()
                registered = True
                # In the end, log the user into the system
                user2 = authenticate(username=user.username,
                                     password=non_hashed_password)
                login(request, user2)
        else:
            # convert the errors into a json format
            user_form_errors = json.loads(user_form.errors.as_json())
            # check if the user_form error was raised because someone tried to register with a username that is already in the dbs
            if user_form_errors.has_key("username") and \
                            user_form_errors['username'][0]['message'] == "User with this Username already exists.":
                username_taken = True
    else:
        user_form = UserForm()
        profile_form = UserProfileForm()
    return render_to_response(
        'ArtVillage/register.html', {
            'user_form': user_form,
            'registered': registered,
            'email_in_db': email_in_db,
            'username_taken': username_taken,
            'profile_form': profile_form
        }, context)
Exemple #24
0
def userprofile(request):
    (profile, created) = UserProfile.objects.get_or_create(user=request.user)
    form = mailform = None

    if request.method == 'POST':
        if request.POST['submit'] == 'Save':
            form = UserProfileForm(request.user,
                                   request.POST,
                                   instance=profile)
            if form.is_valid():
                form.save()
                messages.add_message(request, messages.INFO,
                                     "User profile saved.")
                return HttpResponseRedirect('.')
        elif request.POST['submit'] == 'Add email':
            mailform = MailForm(request.POST)
            if mailform.is_valid():
                m = UserExtraEmail(user=request.user,
                                   email=mailform.cleaned_data['email'],
                                   confirmed=False,
                                   token=generate_random_token(),
                                   tokensent=datetime.now())
                m.save()
                send_template_mail(
                    settings.NOTIFICATION_FROM, request.user.username, m.email,
                    'Your email address for commitfest.postgresql.org',
                    'extra_email_mail.txt', {
                        'token': m.token,
                        'user': m.user
                    })
                messages.info(
                    request,
                    "A confirmation token has been sent to %s" % m.email)
                return HttpResponseRedirect('.')
        else:
            messages.error(request,
                           "Invalid submit button pressed! Nothing saved.")
            return HttpResponseRedirect('.')

    if not form:
        form = UserProfileForm(request.user, instance=profile)
    if not mailform:
        mailform = MailForm()

    extramails = UserExtraEmail.objects.filter(user=request.user)

    return render_to_response('userprofileform.html', {
        'form': form,
        'extramails': extramails,
        'mailform': mailform,
    },
                              context_instance=RequestContext(request))
Exemple #25
0
def userprofile(request):
    if request.method == "POST":
        form = UserProfileForm(request.POST)

        if form.is_valid():
            form.instance.user = request.user
            form.save()
            return HttpResponseRedirect('signup_success')
    else:
        args = {}
        args.update(csrf(request))
        args['form'] = UserProfileForm()
    return render_to_response('userprofile.html', args)
Exemple #26
0
def register_profile(request):
    form = UserProfileForm()
    if request.method == 'POST':
        form = UserProfileForm(request.POST, request.FILES)
        if form.is_valid():
            user_profile = form.save(commit=False)
            # user_profile.user = request.user
            user_profile.save()
            return redirect('index')
        else:
            print(form.errors)
    context_dict = {'form': form}
    return render(request, 'game/profile_registration.html', context_dict)
Exemple #27
0
def user_profile(request):
    usuario = request.user
    if request.method == 'POST':

        form = UserProfileForm(request.POST, instance=usuario)

        if form.is_valid():
            form.save()
            return HttpResponseRedirect(reverse('home'))
    else:
        form = UserProfileForm(instance=usuario)

    return render(request, 'mi_perfil.html', locals())
Exemple #28
0
def edit_profile(request):
    args = {}
    args.update(csrf(request))
    #test navbar func
    self = navbar(request.user.id)

    #self = request.user
    if request.method == 'POST':
        form = UserProfileForm(request.POST,
                               request.FILES,
                               instance=request.user.profile)
        #follow = userFollowActivity.objects.get(user=request.user)
        follow = bandFollow.objects.values_list(
            'band_id', flat=True).filter(user_id=request.user.id)
        generes = Generes.objects.get(user=request.user)

        #       generes =u','.join(self.cleaned_data['generes'])
        first_name = request.user.first_name
        last_name = request.user.last_name
        if form.is_valid():
            form.save()
            return HttpResponseRedirect('/accounts/loggedin/')
    else:
        form = UserProfileForm(instance=request.user.profile)
        try:
            generes = Generes.objects.get(user=request.user)
        except Generes.DoesNotExist:
            generes = None
        try:
            #follow = userFollowActivity.objects.get(user=request.user)
            follow = bandFollow.objects.values_list(
                'band_id', flat=True).filter(user_id=request.user.id)
        except bandFollow.DoesNotExist:
            follow = None
        first_name = request.user.first_name
        last_name = request.user.last_name

    args = {}
    args.update(csrf(request))
    args['form'] = form

    return render_to_response('editprofilepage.html', {
        'from_user': self,
        'self': self,
        'form': form,
        'follow': follow,
        'first_name': first_name,
        'last_name': last_name,
        'generes': generes
    },
                              context_instance=RequestContext(request))
Exemple #29
0
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()

            # check that the users domain
            # matches one kept in out DB
            # this python hack gets around the fact that uni domains are often substring
            # of student emails. (since we want lectures to be able to register with having
            # different fields or duplicate universities
            domains = [
                d for d in University.objects.all()
                if d.email_domain in user.email.split("@")[1]
            ]
            if len(domains) < 1:
                return HttpResponse("Your email domain is invalid.")

            user.set_password(user.password)
            user.save()

            profile = profile_form.save(commit=False)
            profile.user = user
            profile.confirmation_code = ''.join(
                random.choice(string.ascii_uppercase + string.digits)
                for _ in range(100))

            profile.save()

            #send the verification email
            send_registration_confirmation(request, profile)

            registered = True
            user = authenticate(username=request.POST['username'],
                                password=request.POST['password'])
            login(request, user)

        else:
            print user_form.errors, profile_form.errors

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

    return render_to_response('register.html', locals(), context)
Exemple #30
0
def register(request):
    """
    View for register new User
    """
    # Boolean value: True-> registration succeeded, initially set to False
    registered = False

    #If it's a HTTP POST, process the form data:
    if request.method == "POST":
        # Making use of both UserForm and UserProfileForm to grab information
        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 user's form data to database
            user = user_form.save()

            # Now hash the password and update the user object
            user.set_password(user.password)
            user.save()

            # Now sort out the UserProfile instance, Set commit=False so
            # user attributes like picture, website, etc. can be set
            profile = profile_form.save(commit=False)
            profile.user = user

            # Did user enter a profile picture?
            # If so, get from the input form and put it in the UserProfile Model
            if "picture" in request.FILES:
                profile.picture = request.FILES["picture"]
            # Now UserProfile model instance can be saved
            profile.save()
            registered = True  # used to determine that template registration was successful.
        # Uh oh, invalid form or forms?  Print out problems to the terminal, also shown to user
        else:
            print user_form.errors, profile_form.errors
    else:
        # Not a HTTP POST, so form rendered with two fresh blank ModelForm instances
        user_form = UserForm()
        profile_form = UserProfileForm()

    # render the template depending on the context
    context_dict = {
        "user_form": user_form,
        "profile_form": profile_form,
        "registered": registered
    }
    return _process_request(request, context_dict, "rango/register.html")