Skip to content

Commit 714439d

Browse files
committed
Doc: Fix errors in code and grammar
1 parent e0bfe58 commit 714439d

File tree

1 file changed

+33
-9
lines changed

1 file changed

+33
-9
lines changed

two_factor_authentication/twilio_verify_2fa.md

Lines changed: 33 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -49,18 +49,19 @@ Note that these keys are private and should not be committed to version control.
4949

5050
## Create a simple flask application with basic form validation
5151

52-
I will not go into the details of how to create a simple flask application. If you are new to Flask, you can [learn how here](https://github.com/GitauHarrison/notes/blob/master/start_flask_server.md). A complete flask starter project is available on [GitHub](https://github.com/GitauHarrison/starting-a-flask-server). You will need to install and work with a database, `flask-wtf` and `flask-login` to complete the project.
52+
I will not go into the details of how to create a simple flask application. If you are new to Flask, I recommend that you begin [here](https://github.com/GitauHarrison/notes/blob/master/start_flask_server.md). A complete flask starter project is available on [GitHub](https://github.com/GitauHarrison/starting-a-flask-server). You will also need to learn how to create and work with web forms, a database, and user sessions to complete this project.
53+
54+
55+
## Integrate Twilio Verify with your flask application
56+
57+
When a user first creates an account, they will have the option to enable two-factor authentication on their profile page. When they click the "Enable 2FA" link, they will be requested to provide their phone number which will be used to get a verification code. Subsequent logins will require them to enter the verification code before they can access their accounts.
5358

5459
Once you have your project up and running, you will need to install `twilio` in your virtual environment.
5560

5661
```python
5762
(venv) $ pip3 install "twilio>=6.17.0"
5863
```
5964

60-
## Integrate Twilio Verify with your flask application
61-
62-
When a user first creates an account, they will have the option to enable two-factor authentication on their profile page. When they click the "Enable 2FA" link, they will be requested to provide their phone number which will be used to get a verification code. Subsequent logins will require them to enter the verification code before they can access their accounts.
63-
6465
### Integration table of contents
6566

6667
1. [Testing](#testing)
@@ -199,7 +200,15 @@ class PhoneForm(FlaskForm):
199200

200201
```
201202

202-
Notice that I am using the `phonenumbers` library to validate the phone number. This library is used to validate phone numbers in the helper `validate_phone` method. Typically, its usage is as follows:
203+
Notice that I am using the `phonenumbers` library to validate the phone number. This library is used to validate phone numbers in the helper `validate_phone` method. Before you can use it, you have to install it in your virtual environment.
204+
205+
206+
```python
207+
(venv) $ pip3 install phonenumbers
208+
```
209+
210+
211+
Typically, its usage is as follows:
203212

204213
```python
205214
>>> import phonenumbers
@@ -243,6 +252,8 @@ def enable_2fa():
243252
return render_template('enable_2fa.html', form=form)
244253
```
245254

255+
The `request_verification_token` function is used to generate a one-time token. A call to this function is defined below. For now, let us focus on creating this template.
256+
246257
##### Improved phone number form
247258

248259
Since users of the application may be from different nationalities, it would help improve their experience if they could enter their respective phone numbers in the international format.
@@ -502,17 +513,17 @@ def check_verification_token(phone, token):
502513
"""
503514
verify = _get_twilio_verify_client()
504515
try:
505-
result = verify.verifications_check(to=phone, code=token)
516+
result = verify.verification_checks.create(to=phone, code=token)
506517
return result.status == 'approved'
507518
except TwilioException as e:
508519
return False
509520
```
510521

511522
#### Disable 2FA
512523

513-
With the state of 2FA updated, we can now implement the `disable_2fa` view function. This will allow a user to disable 2FA by removing his phone from the database.
524+
With the state of 2FA updated, we can now implement the `disable_2fa` view function. This will allow a user to disable 2FA by removing his phone number from the database.
514525

515-
`app/routes.py`: Cancel 2FA
526+
`app/routes.py`: Disable 2FA
516527

517528
```python
518529
from app.forms import DisableForm
@@ -529,6 +540,19 @@ def diable_2fa():
529540
return render_template('disable_2fa.html', form=form)
530541
```
531542

543+
We will need to define the `DisableForm` class in the `forms.py` module.
544+
545+
546+
`app/forms.py`: Disable form
547+
548+
```python
549+
# ...
550+
551+
552+
class DisableForm(FlaskForm):
553+
submit = SubmitField('Disable')
554+
```
555+
532556
Just like the `enable_2fa` view function, this route will redirect the user to another page that has a form.
533557

534558
`app/templates/disable_2fa.html`: Disable 2FA

0 commit comments

Comments
 (0)