Beispiel #1
0
def register(request):
    context = RequestContext(request)
    registered = False

    if request.method == 'POST':
        # attempt to grab information from the raw form information
        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 redirect('/login/')
        else:
            print user_form.errors

    else:
        user_form = UserForm()

    # render the template depending on the context
    return render_to_response(
            'register.html',
            {'user_form': user_form, 'registered': registered},
            context)
Beispiel #2
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, 'mysite/registration.html', {
            'user_form': user_form,
            'profile_form': profile_form,
            'registered': registered
        })
Beispiel #3
0
def create_user(request):
    if request.method == "POST":
        #import pdb;pdb.set_trace()
        form = UserForm(request.POST)
        personal_form = ProfileForm(request.POST)
        if form.is_valid():
            #new_user = User.objects.create_user(**form.cleaned_data)
            #login(new_user)
            # redirect, or however you want to get to the main view
            return HttpResponseRedirect('user.html')
    else:
        form = UserForm()
        
    personal_form = PersonalForm()
    profile_form = ProfileForm()
    return render(request, 'user.html', {'form': form, 'form1':personal_form, 'form2':profile_form})
Beispiel #4
0
def register(request):
    if request.method == "POST":
        form = UserForm(request.POST)
        if form.is_valid():
            form.save()
            return redirect('login')
        else:
            messages.error(request, 'Ups da ist was vergessen gegangen :(')
            return render(request, 'registration/register.html', {
                'form': form,
            })
    else:
        form = UserForm()
        return render(request, 'registration/register.html', {
            'form': form,
        })
Beispiel #5
0
def register(request):
    context = RequestContext(request)

    # boolean to tell template whether the registration was successful
    registered = False

    if request.method == 'POST':
        # attempt to grab raw info
        user_form = UserForm(data=request.POST)
        profile_form = UserProfileForm(data=request.POST)

        # if 2 forms valid
        if user_form.is_valid() and profile_form.is_valid():
            # save user form to database
            user = user_form.save()

            # hash user with set password method
            user.set_password(user.password)
            user.save()

            # sort out UserProfile instance
            profile = profile_form.save(commit=False)
            profile.user = user

            # Did user provide profile picture?
            if 'picture' in request.FILES:
                profile.picture = request.FILES['picture']

            # save user profile
            profile.save()

            # update register boolean
            registered = True

        else:
            print(user_form.errors, profile_form.errors)

            # Not a HTTP POST, render form using 2 ModelForm instances
    else:
        user_form = UserForm()
        profile_form = UserProfileForm()

    # Render the template depending on the context
    return render_to_response(
        'polls/register.html',
        {'user_form': user_form, 'profile_form': profile_form, 'registered': registered},
        context)
Beispiel #6
0
def update_profile(request):
    """
    :param request:
    :return:
    """
    if request.method == 'POST':
        user_form = UserForm(request.POST, instance=request.user)
        profile_form = ProfileForm(request.POST, instance=request.user.profile)
        if user_form.is_valid() and profile_form.is_valid():
            user_form_data = user_form.cleaned_data
            profile_form_data = profile_form.cleaned_data
            profile_ = Profile.objects.get(user__username=request.user)
            user_ = User.objects.get(username=request.user)
            pre_form_change_email = user_.email
            pre_form_change_phone = profile_.phone_number
            user_form.save()
            profile_form.save()
            profile_ = Profile.objects.get(user=request.user)
            profile_.profile_filled = True
            if pre_form_change_email != user_form_data['email']:
                profile_.email_verification_status = 0
                # Here we have to set a bit in User model that shows we have to confirm user's email
            if pre_form_change_phone != profile_form_data['phone_number']:
                profile_.phone_verification_status = 0
            profile_.profile_filled = True
            profile_.save()
            return redirect('profile')
        else:
            return redirect('update_profile')
    else:
        profile_ = Profile.objects.get(user=request.user)
        user_form = UserForm(instance=request.user)
        profile_form = ProfileForm(instance=request.user.profile)
    return render(
        request, 'registration/profile.html', {
            'user_form': user_form,
            'profile_form': profile_form,
            'isEmailVerified': profile_.email_verification_status,
            'number_of_items': get_number_of_items_in_cart(request),
            'profile_filled': profile_.profile_filled,
        })
Beispiel #7
0
def profile(request):
    response_data = {}
    try:            
        profile = UserProfile.objects.get(user=request.user.id)
    except:
        profile = None
    try:
        find_img = request.user.id.__str__()+'/profile/'
        imagems = ImageUpload.objects.filter(upload__startswith=find_img)    
    except:
        imagems = None    
    try:            
        establisments = Establishment.objects.filter(user=request.user.id)
    except:
        establisments = None   
    if request.method == "POST":
        prof_form = UserProfileForm(request.POST, instance=profile)
        user_form = UserForm(request.POST, instance=request.user)
        if prof_form.is_valid() and user_form.is_valid():
            user = user_form.save(commit=False)
            user.username = user_form.cleaned_data['email']
            user.save()   
            profile = prof_form.save(commit=False)
            profile.user = request.user            
            profile.save()
            response_data['objectid'] = profile.id
            response_data['sucess'] = 'Perfil salvo com sucesso!'
            return HttpResponse(json.dumps(response_data), content_type='application/json')
        else:                
            response_data['erro'] = prof_form.errors.values()
            return HttpResponse(json.dumps(response_data), content_type='application/json')    
    else:
        user_form = UserForm(instance=request.user)
        prof_form = UserProfileForm(instance=profile) 
    return render(request, "profile.html", 
                  {'profile': profile, 'establisments': establisments, 'imagems': imagems, 
                   'user_form': user_form, 'prof_form': prof_form})