Skip to content

Instantly share code, notes, and snippets.

@manuel14
Last active January 1, 2016 21:09
Show Gist options
  • Save manuel14/8202099 to your computer and use it in GitHub Desktop.
Save manuel14/8202099 to your computer and use it in GitHub Desktop.
(vista)
def comprobar(request):
usuario = request.POST["user"]
password = request.POST["pass"]
user = authenticate(username=usuario, password= password)
if user is not None:
return HttpResponse(simplejson.dumps(True), context_instance=RequestContext(request))
else:
return HttpResponse(simplejson.dumps(False), context_instance=RequestContext(request))
(javascript)
$(document).ready(function(){
$("#boton").click(function(event) {
usuario = $("#usuario").val()
password = $("#password").val()
$.post('validar', {user:usuario, pass:password}, function(respuesta){
if (JSON.parse(respuesta)){
alert("Registro exitoso")}
else{
alert("Usuario o constraseña no valida") }
} )
});
slider()
})
(Html)
<html>
<head>
</head>
<body>
<form id="formulario" method="post">
{% csrf_token %}
<label>Usuario</label>
<input type="text" id="usuario" >
<label>Contraseña</label>
<input type="password" id="password">
<input type="submit" value="enviar" id="boton">
</form>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment