Ejemplo n.º 1
0
def view_profile(request, pk=""):
    title = "Profiles"
    latest_data = fetch_latest()

    if not pk:
        try:
            profile = request.user.get_profile()
        except:
            return HttpResponseRedirect(reverse('profile-home'))
    else:
        try:
            # FIXME: UserProfile pk doesn't necessarily match that of the User's.
            # Solution: Grab User(pk=pk), then UserProfile from that
            profile = UserProfile.objects.get(pk=pk)
        except:
            return HttpResponseRedirect(reverse('profile-home'))

    if request.method == 'POST':
        f = UserProfileForm(request.POST, request.FILES, instance=profile)
        if f.is_valid():
            f.save()
    else:
        f = UserProfileForm(instance=profile)
    
    # TODO: set title based on User's name
    return render_to_response('profile.djt', locals(), context_instance=RequestContext(request))
Ejemplo n.º 2
0
def create_profile(request):
    profile_step = 1    
    
    title = "Create profile"
    latest_data = fetch_latest()
    
    featured_profiles = fetch_featured() 

    if request.user.is_authenticated():
        return HttpResponseRedirect(reverse('profile-home'))
    
    if request.method == 'POST':
        form = UserCreationEmailForm(request.POST)
        if form.is_valid():
            email = form.cleaned_data['email']
            password = form.cleaned_data['password1']
            dicts = form.__dict__
            new_user = form.save()
            
            # authenticate user after creating the profile
            user = authenticate(username=email, password=password)
            if user is not None:
                if user.is_active:
                    login(request, user)
                    return HttpResponseRedirect(reverse('profile-home'))
                else:
                    return HttpResponseRedirect(reverse('disabled-profile'))
            else:
                request.session['login_error'] = "Username/password combination is wrong. Please try again."
                return HttpResponseRedirect(reverse('login-profile'))
                
    else:
        form = UserCreationEmailForm()
    return render_to_response("create_profile.djt", locals(), context_instance=RequestContext(request))
Ejemplo n.º 3
0
def contato(request):
    latest_data = fetch_latest()
    featured_profiles = fetch_featured() 
    
    profile_step = 3
    
    if request.method == "POST":
        form = ContactForm(request.POST)
        
        if form.is_valid():
            message = {'successMessage':u"Obrigado pelo recado. Caso preciso, entraremos em contato assim que possível"}
            data = form.cleaned_data
            email_body = " Nome: %s \n\n Email:\n %s \n\n\n Mensagem: \n\n %s " %( data['name'], data['email'], data['message'] )
#            email = EmailMessage(
#                'contato de %s' % data['name'],
#                email_body,
#                to=['*****@*****.**'],
#            )
#            email.send()
            send_mail("Contato de %s" % data['name'], email_body, EMAIL_HOST_USER, ('*****@*****.**',))
        
        else:
            message = {
                'errorMessage':'Error!',
                'execute': "$('form').innerHTML='<table>%s</table>'; " % form.as_table().replace('\n','')
            }
            
        return HttpResponse(
            simplejson.dumps(message),
            mimetype='text/plain'
            )
    if request.method == "GET":
        
        form = ContactForm()
        return render_to_response('contato.djt', locals(), context_instance=RequestContext(request))
Ejemplo n.º 4
0
def profile_home(request, pk=""):
    title = "Your profile"
    latest_data = fetch_latest()
    
    if request.user.is_authenticated():
        user = User.objects.get(id=request.user.id)
        profile = UserProfile.objects.get(user=user)
            
        return render_to_response("profile_home.djt", locals(), context_instance=RequestContext(request))
    
    else:
        return HttpResponseRedirect(reverse('create-profile'))
Ejemplo n.º 5
0
def login_profile(request):
    if request.user.is_authenticated():
        return HttpResponseRedirect(reverse('profile-home'))
    try: 
        errors = request.session['login_error']
        del request.session['login_error']        
    except:
        pass
    
    if request.method == 'GET':
        title = "Login"
        latest_data = fetch_latest()
        form = LoginForm()

        featured_profiles = fetch_featured()
        
        return render_to_response("login.djt", locals(), context_instance=RequestContext(request)) 
    
    if request.method == 'POST':
        errors = []
        form = LoginForm(request.POST)
        if form.is_valid():
            user = authenticate(username=request.POST['email'], password=request.POST['password'])
            
            if user is not None:
                if user.is_active:
                    login(request, user)
                    
                    return HttpResponseRedirect(request.META.get('HTTP_REFERER', None) or '/')
                
                else:
                    errors.append(u'Esta conta não está ativa.')
            
            else:
                errors.append(u'Usuário ou senha inválidos.')
        
        else:
            errors.append(u'Não foi possível fazer o login. Tente novamente.')
        
        return render_to_response('login_error.djt', locals(), context_instance=RequestContext(request))
Ejemplo n.º 6
0
def disabled_profile(request):
    title = "Disabled profile"
    latest_data = fetch_latest()    
    return render_to_response('disabled_profile.djt', locals(), context_instance=RequestContext(request))