cleanup code examples in README
This commit is contained in:
16
README.md
16
README.md
@@ -106,20 +106,22 @@ Depends on
|
||||
* if user doesn't have mfa then call your function to create the user session
|
||||
|
||||
```python
|
||||
from mfa.helpers import has_mfa
|
||||
|
||||
def login(request): # this function handles the login form POST
|
||||
user = auth.authenticate(username=username, password=password)
|
||||
if user is not None: # if the user object exist
|
||||
from mfa.helpers import has_mfa
|
||||
res = has_mfa(username=username, request=request) # has_mfa returns false or HttpResponseRedirect
|
||||
if res:
|
||||
return res
|
||||
return log_user_in(request, username=user.username)
|
||||
#log_user_in is a function that handles creatung user session, it should be in the setting file as MFA_CALLBACK
|
||||
# log_user_in is a function that handles creating user session, it should be in the setting file as MFA_CALLBACK
|
||||
```
|
||||
1. Add mfa to urls.py
|
||||
```python
|
||||
import mfa
|
||||
import mfa.TrustedDevice
|
||||
|
||||
urls_patterns = [
|
||||
'...',
|
||||
url(r'^mfa/', include('mfa.urls')),
|
||||
@@ -149,12 +151,14 @@ To be able to go passwordless for returning users, create a cookie named 'base_
|
||||
|
||||
Second, update the GET part of your login view
|
||||
```python
|
||||
from mfa.helpers import has_mfa
|
||||
|
||||
if "mfa" in settings.INSTALLED_APPS and getattr(settings, "MFA_QUICKLOGIN", False) and request.COOKIES.get('base_username'):
|
||||
username=request.COOKIES.get('base_username')
|
||||
from mfa.helpers import has_mfa
|
||||
res = has_mfa(username = username,request=request,)
|
||||
if res: return res
|
||||
## continue and return the form.
|
||||
res = has_mfa(username=username, request=request)
|
||||
if res:
|
||||
return res
|
||||
# continue and return the form.
|
||||
```
|
||||
# Checking MFA on Client Side
|
||||
|
||||
|
||||
Reference in New Issue
Block a user