Advertisement
Guest User

Untitled

a guest
May 12th, 2017
148
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.46 KB | None | 0 0
  1. #! -*- coding: utf-8 -*-
  2.  
  3.  
  4.  
  5. from django.template import loader
  6.      
  7. from django.shortcuts import render_to_response
  8.  
  9. from django.template import RequestContext, Context
  10.  
  11. from django.db import connection
  12.  
  13. from forms import FormRegistro, FormUsuario
  14.  
  15. from django.contrib.auth.decorators import login_required
  16.  
  17. from usuario.models import UsuarioProfile
  18.  
  19. from django.http import HttpResponseForbidden, Http404, HttpResponse, HttpResponseRedirect
  20.  
  21. from django.contrib.auth import authenticate
  22.  
  23. def cross(request):
  24.     html = """
  25.     <?xml version=\"1.0\"?>\
  26.     <cross-domain-policy>\
  27.       <allow-access-from domain=\"*\" />\
  28.     </cross-domain-policy>
  29.     """
  30.     return HttpResponse(html)
  31.  
  32.  
  33. def registrar(request):
  34.  
  35.     if request.method == 'POST':
  36.         form = FormUsuario ( request.POST )
  37.         valido = form.is_valid()
  38.        
  39.         if valido:
  40.             novo_usuario = form.save()
  41.             return HttpResponseRedirect('/index')
  42.            
  43.     else:
  44.         form = FormUsuario()
  45.        
  46.     return render_to_response(
  47.         'registrar.html',
  48.         locals(),
  49.         context_instance=RequestContext(request),
  50.         )
  51.  
  52.  
  53. def verificaUsuarioSenha(request):
  54.     #if '.swf'  in request.META.get('HTTP_REFERER',''):
  55.     #if '.swf'  not in request.META.get('HTTP_REFERER', ''):
  56.     #    return HttpResponseForbidden("status=nok")
  57.     username  =  request.POST.get('username','')
  58.     password =  request.POST.get('password','')
  59.     print request.POST
  60.     print "_" * 40
  61.     print request.GET
  62.     print "_" * 40
  63.     print "Debug"
  64.     print "Method: %s" % request.method
  65.     print "user:%s \npass:%s " % ( username ,password )
  66.     print "Referer:%s" % request.META.get('HTTP_REFERER', None)
  67.     print "_" * 40
  68.  
  69.     status = 'nok'    
  70.     if request.method == 'POST':
  71.         user = authenticate(
  72.                         username = username,
  73.                         password =  password
  74.                         )
  75.         if user is not None:
  76.             if user.is_active:
  77.                 status = 'ok'
  78.             else:
  79.                 pass #status = 'nok'
  80.         else:
  81.             pass #status = 'nok'
  82.            
  83.     return HttpResponse("status=%s"%status)
  84.  
  85.        
  86.  
  87. @login_required
  88. def index(request):
  89.     nome = request.user.first_name
  90.     id = request.user.id
  91.    
  92.     template = 'usuario/index.html'
  93.     return render_to_response(template, {'nomeUsuario' : nome, 'idUsuario' : id}, context_instance=RequestContext(request))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement