redirectrender(request,'panel.html')
mi código de views.py:
elif 'logInButton' in request.POST:
if login_email and login_password:
try:
user = Usuario.objects.get(email=login_email)
#compare hashed: bcrypt.hashpw(input, self.password) == self.password:
except Exception as e:
messages.error(request, 'Error in user or password')
return redirect('home')
if str(bcrypt.hashpw(login_password.encode('utf-8'), user.password[2:len(user.password)-1].encode('utf-8'))) == user.password:
if not user.activated:
messages.warning(request, 'You must to activate your user!')
return redirect('home')
user.last_login = strftime("%Y-%m-%d %H:%M:%S", gmtime())
fingerprint = request.META.get('HTTP_USER_AGENT')+request.META.get('COMPUTERNAME')+request.META.get('OS')
ip = str(request.META.get('REMOTE_ADDR'))
old_ip_and_old_fingerprint = (sha3.sha3_224(str(fingerprint).encode('utf-8')).hexdigest() == user.fingerprint) and (ip in user.ip)
if (not old_ip_and_old_fingerprint) and user.two_factors_auth:
# doble_auth_send()
messages.debug('doble_auth')
return redirect('home')
elif not old_ip_and_old_fingerprint:
notify_new_conection(ip,user.name,ip,request.META.get('HTTP_USER_AGENT'),request.META.get('COMPUTERNAME'),request.META.get('OS'),user.email) #notificamos la posible intrusion
user.ip = user.ip+ip+'|'
user.fingerprint = sha3.sha3_224(str(fingerprint).encode('utf-8')).hexdigest()
user.last_login = strftime("%Y-%m-%d %H:%M:%S", gmtime())
return render(request, 'dashboard.html')
else:
if not ip in user.ip:
user.ip = user.ip+ip+'|'
if not sha3.sha3_224(str(fingerprint).encode('utf-8')).hexdigest() == user.fingerprint:
user.fingerprint = sha3.sha3_224(str(fingerprint).encode('utf-8')).hexdigest()
user.last_login = strftime("%Y-%m-%d %H:%M:%S", gmtime())
return render(request, 'dashboard.html')
else:
messages.error(request, 'Error in user or password')
return redirect('home')
else:
messages.warning(request, 'Make sure all fields are entered and valid')
return redirect('home')