Python3 Support

This commit is contained in:
Mohamed ElKalioby
2019-01-23 10:42:50 +03:00
parent b199c86993
commit 6efd643022
11 changed files with 27 additions and 23 deletions

View File

@@ -87,6 +87,6 @@ Depends on
If you will use Email Token method, then you have to provide template named `mfa_email_token_template.html` that will content the format of the email with parameter named `user` and `otp`.
1. To match the look and feel of your project, MFA includes `base.html` but it needs blocks named `head` & `content` to added its content to it.
1. Somewhere in your app, add a link to 'mfa_home'
```<l><a href="{% url 'mfa_home' %}">Security</a> </l>```
```<li><a href="{% url 'mfa_home' %}">Security</a> </li>```
For Example, See https://github.com/mkalioby/AutoDeploy/commit/5f1d94b1804e0aa33c79e9e8530ce849d9eb78cc in AutDeploy Project

8
mfa/Common.py Normal file
View File

@@ -0,0 +1,8 @@
from django.conf import settings
from django.core.mail import EmailMessage
def send(to,subject,body):
From = "%s <%s>" % (settings.EMAIL_FROM, settings.EMAIL_HOST_USER)
email = EmailMessage(subject,body,From,to)
email.content_subtype = "html"
return email.send(False)

View File

@@ -5,19 +5,13 @@ from random import randint
from .models import *
from django.template.context import RequestContext
from .views import login
from .Common import send
def sendEmail(request,username,secret):
from django.contrib.auth import get_user_model
User = get_user_model()
user=User.objects.get(username=username)
print secret
res=render_to_response("mfa_email_token_template.html",{"request":request,"user":user,'otp':secret})
from django.conf import settings
from django.core.mail import EmailMessage
From = "%s <%s>" % (settings.EMAIL_FROM, settings.EMAIL_HOST_USER)
email = EmailMessage("OTP",res.content,From,[user.email] )
email.content_subtype = "html"
return email.send(False)
return send([user.email],"OTP", res.content)
def start(request):
context = csrf(request)

View File

@@ -105,8 +105,8 @@ def start(request):
def send_email(request):
body=render(request,"TrustedDevices/email.html",{}).content
from Registry_app.Common import send
if send(request.user.email,"Add Trusted Device Link",body,delay=False):
from .Common import send
if send([request.user.email],"Add Trusted Device Link",body):
res="Sent Successfully"
else:
res="Error occured, please try again later."

View File

@@ -41,14 +41,14 @@ def validate(request,username):
import datetime, random
data = simplejson.loads(request.POST["response"])
print "Checking Errors"
res= check_errors(request,data)
if res!=True:
return res
print "Checking Challenge"
challenge = request.session.pop('_u2f_challenge_')
device, c, t = complete_authentication(challenge, data, [settings.U2F_APPID])
print device
key=User_Keys.objects.get(username=username,properties__shas="$.device.publicKey=%s"%device["publicKey"])
key.last_used=timezone.now()
key.save()

View File

@@ -1 +1 @@
import urls
from . import urls

View File

@@ -1,8 +1,6 @@
import pyotp
from .models import *
import TrustedDevice
import U2F, FIDO2
import totp
from . import TrustedDevice, U2F, FIDO2, totp
import simplejson
from django.shortcuts import HttpResponse
from mfa.views import verify,goto

View File

@@ -2,8 +2,7 @@ from django.db import models
from jsonfield import JSONField
from jose import jwt
from django.conf import settings
from jsonLookup import hasLookup,shasLookup
JSONField.register_lookup(hasLookup)
from jsonLookup import shasLookup
JSONField.register_lookup(shasLookup)
class User_Keys(models.Model):

View File

@@ -5,7 +5,7 @@ from django.core.urlresolvers import reverse
from django.template.context_processors import csrf
from django.template.context import RequestContext
from django.conf import settings
import TrustedDevice
from . import TrustedDevice
from user_agents import parse
def index(request):
keys=[]
@@ -24,7 +24,7 @@ def verify(request,username):
#request.session["base_password"] = password
keys=User_Keys.objects.filter(username=username,enabled=1)
methods=list(set([k.key_type for k in keys]))
print methods
if "Trusted Device" in methods and not request.session.get("checked_trusted_device",False):
if TrustedDevice.verify(request):
return login(request)

2
setup.cfg Normal file
View File

@@ -0,0 +1,2 @@
[bdist_wheel]
universal = 1

View File

@@ -4,8 +4,11 @@ from setuptools import find_packages, setup
setup(
name='django-mfa2',
version='0.9.0',
version='0.9.2',
description='Allows user to add 2FA to their accounts',
long_description=open("README.md").read(),
long_description_content_type="text/markdown",
author='Mohamed El-Kalioby',
author_email = 'mkalioby@mkalioby.com',
url = 'https://github.com/mkalioby/django-mfa2/',