Exemple #1
0
def user_register(request):
	registered = False
	page = ''
	try:
		page = Page.objects.get(ptype = 'register')
	except:
		raise Http404
	if request.method == 'POST':
		user_form = UserForm(data = request.POST)
		member_form = MemberForm(data = request.POST)
		if user_form.is_valid() and member_form.is_valid():
			user = user_form.save()

			user.set_password(user.password)
			user.save()
			member = member_form.save(commit = False)
			member.user = user
			member.save()
			u = authenticate(username = request.POST['username'], password = request.POST['password'])
			login(request,u)
			registered = True
			return HttpResponseRedirect('/')

		else:
			return render_to_response('register.html',{'user_form':user_form, 'member_form':member_form, 'registered':registered, 'page':page },context_instance=RequestContext(request))

	else :
		user_form = UserForm()
		member_form = MemberForm()

	return render_to_response('register.html',{'user_form':user_form, 'member_form':member_form, 'registered':registered,'page':page },context_instance=RequestContext(request))
Exemple #2
0
def profileedit(request):
    instance_a = get_object_or_404(MemberProfile, user=request.user)
    instance_b = get_object_or_404(User, pk=request.user.id)

    a = ProfileForm(request.POST or None, instance=instance_a)
    b = UserForm(request.POST or None, instance=instance_b)

    if a.is_valid() and b.is_valid():
        a.save() and b.save()
        return HttpResponseRedirect('/dashboard/account/')


    return render(request, 'member/profile-edit.html', {
        'form': a,
        'forms': b,
        })
Exemple #3
0
def profileedit(request):
    instance_a = get_object_or_404(MemberProfile, user=request.user)
    instance_b = get_object_or_404(User, pk=request.user.id)

    a = ProfileForm(request.POST or None, instance=instance_a)
    b = UserForm(request.POST or None, instance=instance_b)

    if a.is_valid() and b.is_valid():
        a.save() and b.save()
        return HttpResponseRedirect('/dashboard/account/')


    return render(request, 'dashboard/profile-edit.html', {
        'form': a,
        'forms': b,
        })
Exemple #4
0
    def post(self, request):
        if ('login' in request.POST):
            form = LoginForm(request.POST)
            if form.is_valid():
                user = form.login(request)
                if user:
                    login(request, user)
                    if is_caregiver(user):
                        caregiver = CareGiver.objects.get(user=user)
                        elders = Elder.get_cared_elder(caregiver)
                        if elders:
                            request.session['active_elder'] = elders[0].id
                        else:
                            request.session['active_elder'] = 0
                        return self.caregiver(request)
                    else:
                        return self.partner(request)
            else:
                return render(request, 'login.html',
                              {'error_login': form.errors})

        elif ('signup' in request.POST):
            userform = UserForm(request.POST)
            caregiverform = CareGiverForm(request.POST)
            # return reverse(request.POST['gender'])
            if userform.is_valid() and caregiverform.is_valid():
                user = userform.save(commit=False)
                user.set_password(userform.cleaned_data.get('password'))
                user.save()
                caregiver = caregiverform.save(commit=False)
                caregiver.user = user
                caregiver.save()
                g = Group.objects.get(name='CareGiver')
                g.user_set.add(user)
                return render(
                    request, 'login.html',
                    {'success': "Pendaftaran Berhasil, silahkan login"})
            else:
                userform.errors.update(caregiverform.errors)
                return render(request, 'login.html', {
                    'error_signup': userform.errors,
                    'values': request.POST
                })
        else:
            return render(request, 'login.html')
Exemple #5
0
def member_register(request):

    registered = False

    if request.method == "POST":
        user_form = UserForm(data=request.POST)
        profile_form = MemberForm(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 = MemberForm()

    return render(
        request, 'member/registration.html', {
            'user_form': user_form,
            'profile_form': profile_form,
            'registered': registered
        })
Exemple #6
0
def member_settings(request, redirect_from="profile"):

    user = request.user
    memberprofile = MemberProfile.objects.get(member=user)
    
    ''' If profile is not created yet go to startup page'''
    try:
        if user.memberprofile:
            pass
    except:
        return HttpResponseRedirect("/member/startup/")
        

    if request.method == 'POST':
        pform = MemberProfileForm(request.POST, instance=memberprofile)
        uform = UserForm(request.POST, instance=user)

        if uform.is_valid() and pform.is_valid():
            user = uform.save(commit=False)
            user.save()
            profile = pform.save()

            messages.success(request, "Member profile saved successfully")
    else:
        uform = UserForm(instance=user)
        pform = MemberProfileForm(instance=memberprofile)

    tw_numbers = MemberTwilioNumber.objects.filter(member=user)

    twform = FilterTwilioNumberSearchForm()
    twnumberedit_form = MemberTwilioNumberEditForm()
    member_contact_numers = MemberContactNumber.objects.all()


    return render_to_response("member/settings.html", 
            {'uform': uform, 'pform': pform, "tw_numbers": tw_numbers, 'twform': twform,
             'twnumberedit_form': twnumberedit_form, 'path': redirect_from, 'contact_numbers': member_contact_numers},
            context_instance=RequestContext(request))