def testUsersCreation(self):
     u = User.add("user1", "passwd", '*****@*****.**')
     U = User.objects.filter(username="******").get()
     self.assertEqual(u, U)
     u2 = User.add("user2", 'passwd', '*****@*****.**')
     U = User.objects.filter(username="******").get()
     self.assertEqual(u2, U)
 def testUpdateUserLastName(self):
     User.add("user1", "passwd", '*****@*****.**', 'User1', 'One')
     u = User.getByUsername("user1")
     self.assertEqual(u.lastname, 'One')
     u.updateUserLastname('Two')
     u = User.getByUsername("user1")
     self.assertEqual(u.lastname, 'Two')
	def testUpdateUserLastName(self):
		User.add("user1","passwd",'*****@*****.**','User1','One')
		u = User.getByUsername("user1")
		self.assertEqual(u.lastname, 'One')
		u.updateUserLastname('Two')
		u = User.getByUsername("user1")
		self.assertEqual(u.lastname, 'Two')
	def testUpdateUserEmail(self):
		User.add("user1","passwd",'*****@*****.**','User1','One')
		u = User.getByUsername("user1")
		self.assertEqual(u.email, '*****@*****.**')
		u.updateUserEmail('*****@*****.**')
		u = User.getByUsername("user1")
		self.assertEqual(u.email, '*****@*****.**')
	def testUsersCreation(self):
		u = User.add("user1","passwd",'*****@*****.**')
		U = User.objects.filter(username = "******").get()
		self.assertEqual(u, U)
		u2 = User.add("user2", 'passwd','*****@*****.**')
		U = User.objects.filter(username = "******").get()
		self.assertEqual(u2, U)
 def testUpdateUserEmail(self):
     User.add("user1", "passwd", '*****@*****.**', 'User1', 'One')
     u = User.getByUsername("user1")
     self.assertEqual(u.email, '*****@*****.**')
     u.updateUserEmail('*****@*****.**')
     u = User.getByUsername("user1")
     self.assertEqual(u.email, '*****@*****.**')
	def testCompleteFields(self):
		User.add("user1","passwd",'*****@*****.**','User1','One')
		User.add("user2","passwd2",'*****@*****.**','User2', 'Two')
		u = User.getByUsername("user1")
		self.assertEqual(u.firstname, 'User1')
		self.assertEqual(u.lastname, 'One')
		u2 = User.getByUsername("user2")
		self.assertEqual(u2.firstname, 'User2')
		self.assertEqual(u2.lastname, 'Two')
 def testCompleteFields(self):
     User.add("user1", "passwd", '*****@*****.**', 'User1', 'One')
     User.add("user2", "passwd2", '*****@*****.**', 'User2', 'Two')
     u = User.getByUsername("user1")
     self.assertEqual(u.firstname, 'User1')
     self.assertEqual(u.lastname, 'One')
     u2 = User.getByUsername("user2")
     self.assertEqual(u2.firstname, 'User2')
     self.assertEqual(u2.lastname, 'Two')
	def testUserValidation(self):
		User.add("user1","passwd",'*****@*****.**')
		User.add("user2","passwd2",'*****@*****.**')		
		result = User.isValidLogin("user1","passwd")
		self.assertEqual(result, True)
		result = User.isValidLogin("user1","passwd2")
		self.assertEqual(result, False)
		result = User.isValidLogin("user2","passwd")
		self.assertEqual(result, False)
		result = User.isValidLogin("user2","passwd2")
		self.assertEqual(result, True)
		result = User.isValidLogin("user","passwd5")
		self.assertEqual(result, False)
 def testUserValidation(self):
     User.add("user1", "passwd", '*****@*****.**')
     User.add("user2", "passwd2", '*****@*****.**')
     result = User.isValidLogin("user1", "passwd")
     self.assertEqual(result, True)
     result = User.isValidLogin("user1", "passwd2")
     self.assertEqual(result, False)
     result = User.isValidLogin("user2", "passwd")
     self.assertEqual(result, False)
     result = User.isValidLogin("user2", "passwd2")
     self.assertEqual(result, True)
     result = User.isValidLogin("user", "passwd5")
     self.assertEqual(result, False)
def SignUpView(request):
    if request.method == 'GET':
        # GET METHOD: Aca envio el formulario de creacion de usuario
        return render_to_response('signup.html',{},RequestContext(request))
    elif request.method == 'POST':
        # POST METHOD: Aca valido la informacion de creacion de usuario
        information = {}
        valid = True
        
        # Obtengo la informacon ingresada
        information['username'] = request.POST.get('username', '')
        password = request.POST.get('password', '')
        vpassword = request.POST.get('vpassword', '')
        information['email'] = request.POST.get('email', '')
        information['name'] = request.POST.get('name', '')
        information['lastname'] = request.POST.get('lastname', '')
        information['country'] = request.POST.get('country', '')
        leave_open = request.POST.get('remember',None)
        
        # Valido los datos.
        if not User.isValidUsername(information['username']):
            # Marco el error de username invaludo
            valid = False
            information['username_error'] = 'El nombre de usuario no es valido'
        elif not User.isValidPassword(password):
            # Marco el error de password invaludo
            valid = False
            information['password'] = ''
            information['password_error'] = 'La clave no es valida'
        elif password != vpassword:
            # Marco el error de passwords distintas
            valid = False
            information['vpassword'] = ''
            information['password_error'] = 'Las claves no coinciden'
        elif not User.isValidEmail(information['email']):
            # Marco el error de password invaludo
            valid = False
            information['email_error'] = 'El email ingresado no es valido'
        else:
            user = User.add(information['username'],password,information['email'],information['name'], information['lastname']);
            if  user == None:
                # Marco el error de usuario ya existente
                valid = False
                information['username_error'] = 'El usuario ya existe. Ingrese otro'
        
        
        if valid == False:
            # Hubo un error al crear el usuario. Vuelvo a enviar el formulario de creacion con los errores respectivos
            return render_to_response('signup.html',information ,RequestContext(request))
        else:
            # Se creo un usuario, redirijo pero seteo la cookie para identificar
            response = redirect('/')
            response.set_signed_cookie('user_id', information['username'])
            return response
    else:
        raise PermissionDenied
def SignUpAPI(request):
    if request.method == 'GET':
        # GET METHOD: Aca envio el formulario de creacion de usuario
        return render_to_response('signup.html',{},RequestContext(request)) 
    elif request.method == 'POST':
        # POST METHOD: Aca valido la informacion de creacion de usuario
        information = {}
        
        # Obtengo la informacon ingresada
        information['username'] = request.POST.get('username', '')
        password = request.POST.get('password', '')
        vpassword = request.POST.get('vpassword', '')
        information['email'] = request.POST.get('email', '')
        information['name'] = request.POST.get('name', '')
        information['lastname'] = request.POST.get('lastname', '')
        information['country'] = request.POST.get('country', '')
        information['error_code'] = 0 # NO ERROR!
        leave_open = request.POST.get('remember',None)
        
        # Valido los datos.
        if not User.isValidUsername(information['username']):
            information['error_code'] = 1 # ERROR NOMBRE DE USUARIO INVALIDO
            information['error_description'] = 'El nombre de usuario no es valido'
        elif not User.isValidPassword(password):
            # Marco el error de password invaludo
            information['error_code'] = 2 # ERROR CLAVE INVALIDA
            information['error_description'] = 'La clave no es valida'
        elif password != vpassword:
            # Marco el error de passwords distintas
            information['error_code'] = 3 # ERROR CLAVES NO SON IDENTICAS
            information['error_description'] = 'Las claves no coinciden'
        elif not User.isValidEmail(information['email']):
            # Marco el error de password invaludo
            information['error_code'] = 4 # ERROR EMAIL INVALIDO
            information['error_description'] = 'El email ingresado no es valido'
        else:
            user = User.add(information['username'],password,information['email'],information['name'], information['lastname']);
            if  user == None:
                # Marco el error de usuario ya existente
                information['error_code'] = 5 # ERROR USUARIO YA EXISTE
                information['error_description'] = 'El usuario ya existe. Ingrese otro'
        
        
        if information['error_code'] != 0:
            # Hubo un error al crear el usuario. Envio el diccionario en formato json
            return api.render_to_json(information);
        else:
            # Se creo un usuario, redirijo pero seteo la cookie para identificar
            response = redirect('/')
            response.set_signed_cookie('user_id', information['username'])
            return response
    else:
        raise PermissionDenied
	def testUpdateUserPassword(self):
		u = User.add("user1","passwd",'*****@*****.**')
		self.assertTrue(User.isValidLogin("user1","passwd"))
		u.updateUserPassword("newpasswd")
		self.assertFalse(User.isValidLogin("user1","passwd"))
		self.assertTrue(User.isValidLogin("user1","newpasswd"))
	def testUserGetByUsername(self):
		self.assertEqual(User.getByUsername("user1"), None)
		u = User.add("user1","passwd",'*****@*****.**')
		self.assertEqual(User.getByUsername("user1"), u)
		self.assertEqual(User.getByUsername("user2"), None)
	def testTwoEqualUsersCreation(self):
		u = User.add("user1","passwd",'*****@*****.**')
		u2 = User.add("user1","passwd",'*****@*****.**')
		self.assertIsNone(u2)
		u2 = User.add("user1","passwd", "*****@*****.**")
		self.assertIsNone(u2)
 def testUpdateUserPassword(self):
     u = User.add("user1", "passwd", '*****@*****.**')
     self.assertTrue(User.isValidLogin("user1", "passwd"))
     u.updateUserPassword("newpasswd")
     self.assertFalse(User.isValidLogin("user1", "passwd"))
     self.assertTrue(User.isValidLogin("user1", "newpasswd"))
 def testUserGetByUsername(self):
     self.assertEqual(User.getByUsername("user1"), None)
     u = User.add("user1", "passwd", '*****@*****.**')
     self.assertEqual(User.getByUsername("user1"), u)
     self.assertEqual(User.getByUsername("user2"), None)
 def testTwoEqualUsersCreation(self):
     u = User.add("user1", "passwd", '*****@*****.**')
     u2 = User.add("user1", "passwd", '*****@*****.**')
     self.assertIsNone(u2)
     u2 = User.add("user1", "passwd", "*****@*****.**")
     self.assertIsNone(u2)