Beispiel #1
0
def registerUser(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

            profile.save()

            registered = True

        else:
            print user_form.errors, profile_form.errors

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

    return render_to_response(
            'portal/registration.html',
            {'user_form': user_form, 'profile_form': profile_form, 'registered': registered},
            context)
Beispiel #2
0
def register(request):

    regStatus = False

    if request.method == 'POST':
        #grab info from raw information
        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()

            #hash the password for security using the djangohash default method
            user.set_password(user.password)
            user.save()

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

            if 'profile_pic' in request.FILES:
                profile_pic = request.FILES['profile_pic']
            profile.save()

            regStatus = 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': regStatus})
Beispiel #3
0
def my_data(request):
    user = User.objects.get(pk=request.user.pk)
    user_form = UserForm(instance=user)

    try:
        user_profile = UserProfile.objects.get(user=user)
    except:
        user_profile = UserProfile()
        user_profile.user = user
        user_profile.save()

    profile_form = UserProfileForm(instance=user_profile)

    if request.method == 'POST':
        user_form = UserForm(request.POST)
        profile_form = UserProfileForm(request.POST)
        if user_form.is_valid() and profile_form.is_valid():
            user.first_name = user_form.cleaned_data['first_name']
            user.last_name = user_form.cleaned_data['last_name']
            user.save()

            user_profile.cpf = profile_form.cleaned_data['cpf']
            user_profile.address = profile_form.cleaned_data['address']
            user_profile.number = profile_form.cleaned_data['number']
            user_profile.address2 = profile_form.cleaned_data['address2']
            user_profile.city = profile_form.cleaned_data['city']
            user_profile.district = profile_form.cleaned_data['district']
            user_profile.state = profile_form.cleaned_data['state']
            user_profile.country = profile_form.cleaned_data['country']
            user_profile.zipcode = profile_form.cleaned_data['zipcode']
            user_profile.phone = profile_form.cleaned_data['phone']
            user_profile.remote_receiver_id = profile_form.cleaned_data[
                'remote_receiver_id']
            user_profile.save()

    context = {
        'user_form': user_form,
        'profile_form': profile_form,
        'user': user
    }

    return render(request, 'portal/my_data.html', context)
Beispiel #4
0
def register(request):
    ans_code = "abc"
    regStatus = False
    from django.contrib.auth.models import User

    if request.method == 'POST':
        #grab info from raw information
        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()

        #hash the password for security using the djangohash default method
        username = request.POST.get('username')
        first_name = request.POST.get('first_name')
        last_name = request.POST.get('last_name')
        email = request.POST.get('email')
        password = request.POST.get('password')
        secret_code = request.POST.get('secret_code')
        staffval = False
        if secret_code == ans_code:
            staffval = True

            #user.set_password('user.password')
        user = User(username=username,
                    first_name=first_name,
                    last_name=last_name,
                    email=email,
                    password=password)

        user.save()
        user.set_password(password)
        if staffval == True:
            user.is_staff = True

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

        #if 'profile_pic' in request.FILES:
        #   profile_pic = request.FILES['profile_pic']
        #profile.save()

        regStatus = True

    return render(request, 'home.html', {})