create account

Authentication system in the forum application #7: Reset password and Send email reset password by duski.harahap

View this thread on: hive.blogpeakd.comecency.com
· @duski.harahap ·
$17.13
Authentication system in the forum application #7: Reset password and Send email reset password
#### Repository
https://github.com/python

#### What Will I Learn?
- Reset password
- Send email reset password

#### Requirements
- Basic Python
- Install Python 3
- Install Django


#### Resources
- Python - https://www.python.org/
- Django- https://www.djangoproject.com/
- Bootstrap 4 - https://getbootstrap.com/docs/4.0/getting-started/introduction/
- http://ana-balica.github.io/2015/01/29/pagination-in-django/

#### Difficulty
Basic

### Tutorial Content

Hey everyone, this is a continuation of the Django application tutorial series, this tutorial series specifically discusses authentication in the Django forum application, so for those of you who are just following this tutorial, I suggest you follow the tutorial series in the curriculum section. In the previous tutorial, we have made user activation features with e-mail and also a number of other features, now in this section, we will create a new feature, namely resetting user passwords.

### Make the interface to Reset password


We will start our new feature by creating an interface to enter the password reset feature, so the idea is that I will make a button at the interface of the Django application. For more details, we can see the following template:

**registration/login.html**

```
{% extends "base.html" %}

{% block title %} Sign in{% endblock %}

{% block content %}
<h2>Sign in</h2>
<form method="post">
	{% csrf_token %}
	{{ form.as_p }}
	<button type="submit" name="button">Login</button>
	<a href="{% url 'password_reset' %}">Forgot password</a> // Set URL for forgot password
</form>

{% endblock%}
```



- As usual, we need ***tokens*** on every form we make because we need tokens to verify that the data we post is safe. We can use ***csrf token*** to make our form safe, by writing like this ```{% csrf_token%}```, later our template will render a new input with type = "hidden", for more details we can see in the picture below:

![Screenshot_2.png](https://ipfs.busy.org/ipfs/QmdNMJxSatg3WtPqnR1zJD3891g8n3gByjCxzHBoiJxTz2)

- In the template above we can see the login page that we have used in our previous tutorial, in this template we will add a new interface which is a link to the *password reset* page.

- we will render the URL to reset the password in the following way ```<a href="{% url 'password_reset' %}">Forgot password</a>```, **Django** has provided a ***URL*** to reset the password, we can render it like this ```{% url 'password_reset' %}```, If we see, the template will be rendered as follows:

![Screenshot_1.png](https://ipfs.busy.org/ipfs/QmPqXD4zDbzVcLr43fSnjJGdDttBKk3fTLhsX9K7vgVCCp)

We can see in the picture above we have successfully rendered the URL to reset the password, now with that URL we ***don't need*** to make routing to reset the password, because Django has provided it.


### Create a template reset password

We have created a password reset interface on the sign in the template, now we will create a template to reset the password. **Django** has also provided a default template for resetting passwords if you don't want to create a new template you can use the template provided by Django. In this template, we will send a confirmation email to the user's email.

- **Default template from Django**

I will show how to use default templates and templates that we create ourselves, we will see the difference if we use the default template we do not need to declare a class view to render templates. For more details, we can see in the picture below:

![ezgif.com-video-to-gif.gif](https://cdn.steemitimages.com/DQmV7d7DioXUsjQeKHWtHzfMmBvJhojC3aVNveA2BXagE8C/ezgif.com-video-to-gif.gif)

We can see in the picture above that the link has rendered the template automatically. now we will create our own template.
<br>
- **Create a password reset template**

In this section, I will create a password reset template, at the top we use the template provided by Django, now we will try to create our own template. We will make the template in the **template/registration** folder. In this folder, I will create a **password_reset_form.html** template. We can see an example like the following picture

![Screenshot_3.png](https://ipfs.busy.org/ipfs/QmavANreSNpX4Xd2bLg9UraRxELiXnu4EAnh61nj5P3Bui)


**password_reset_form.html**

```
{% extends "base.html" %}

{% block title %} Reset Password{% endblock %}

{% block content %}
<h2>Reset your password</h2>
<form method="post">
	{% csrf_token %}
	{{ form.as_p }}
	<button type="submit" name="button">Send email</button>
</form>

{% endblock%}
```



In this template we still use ```{% csrf_token%}``` and form ```{{ form.as_p }}```,  the thing to note is the name of our template file. ***We can't use template names as we like.*** If we use our own template the name of the password reset template must be like this **password_reset_form.html**. For more details, we can see in the picture below:

![ezgif.com-video-to-gif (1).gif](https://cdn.steemitimages.com/DQmfKvcynuHkRo7czjSaxCJ8xJ97JkWt3X14rsYcccyiUrK/ezgif.com-video-to-gif%20(1).gif)

It can be seen that we changed the file name to **wrongFileName.html**, so Django will automatically render the default template that it *has provided.*
<br>
- **Create a send email confirmation page**

Now we have finished the password reset page, now we will create a confirmation page when the password is reset successfully and the email is sent to the user's email. to make the confirmation page, we also cannot name the file carelessly. we must make the password reset email confirmation page as follows **password_reset_done.html**. We will also make the **template/registration** folder. For more details, we can see the example below:

**password_reset_done.html**

```
{% extends "base.html" %}

{% block title %} Confirmation change password{% endblock %}

{% block content %}
<div class="alert alert-success">
  <strong>Success!</strong> Please check your email..!
</div>
{% endblock%}
```

The configuration page is quite simple, we will only render alerts from bootstrap like the following:

```
<div class="alert alert-success">
  <strong>Success!</strong> Please check your email..!
</div>
```

So later when the user succeeds in sending his confirmation e-mail address if successful he will get a confirmation page like the following. If it's finished, we can see the confirmation page like this:

![ezgif.com-video-to-gif (2).gif](https://cdn.steemitimages.com/DQmVqqTUome4jybN1RzAhvX2vk6qFwLSBMtL5enDFgSYcQ1/ezgif.com-video-to-gif%20(2).gif)
<br>
- **Send an email password**

We have created a template and confirmation page, now we will send a confirmation email to the user to reset the password, this email will be sent by the system to the user email that will be reset. Here I will send a password reset link to user **millea@admin.com**. We will send the password reset link later on that email. For more details, we can see in the picture below:

![ezgif.com-video-to-gif (3).gif](https://cdn.steemitimages.com/DQmYSndhC98Khzs5rGF8wRfhZmZLJ4vpupLoNaja4wh2FJX/ezgif.com-video-to-gif%20(3).gif)

The link that we sent is http://127.0.0.1:8000/accounts/reset/Mw/566-0f6c2c53444cc2b4150b/. Well, we can see in the picture above we have successfully sent a confirmation email to the user's email. this means the system that we are running well. http://127.0.0.1:8000/accounts/reset/Mw/566-0f6c2c53444cc2b4150b/


### Curriculum

- **Forum app**

[django#1](https://steemit.com/utopian-io/@duski.harahap/create-a-forum-application-using-django-1-init-projects-and-dependencies-and-database-schema-1551711163679), [django#2](https://steemit.com/utopian-io/@duski.harahap/create-a-forum-application-using-django-2-template-system-and-class-based-view-implementation-1552057536737), [django#3](https://steemit.com/utopian-io/@duski.harahap/create-a-forum-application-using-django-3-base-template-login-and-register-system-1552311993977), [django#4](https://steemit.com/utopian-io/@duski.harahap/create-a-forum-application-using-django-4-admin-dashboard-ang-setting-redirect), [django#5](https://steemit.com/utopian-io/@duski.harahap/create-a-forum-application-using-django-5-slug-concept-and-generated-slug-and-use-forms-generic-view), [django#6](https://steemit.com/utopian-io/@duski.harahap/create-a-forum-application-using-django-6-crud-system-and-url-protection-redirect-system), [django#7](https://steemit.com/utopian-io/@duski.harahap/create-a-forum-application-using-django-7-unique-slug-and-manage-modules-in-admin-dashboard-1553268749861), [django#8](https://steemit.com/utopian-io/@duski.harahap/create-a-forum-application-using-django-8-display-forum-data-and-create-and-implement-list-view-1553525769014),  [django#8](https://steemit.com/utopian-io/@duski.harahap/create-a-forum-application-using-django-8-display-forum-data-and-create-and-implement-list-view-1553525769014),  [django#9](https://steemit.com/utopian-io/@duski.harahap/create-a-forum-application-using-django-9-single-page-for-forums-passing-params-in-routing-and-make-time-humanize-1553788983186),  [django#10](https://steemit.com/utopian-io/@duski.harahap/create-a-forum-application-using-django-10-detail-page-for-forums-use-slug-as-the-parameter-url-and-implement-getcontextdata),  [django#11](https://steemit.com/utopian-io/@duski.harahap/create-a-forum-application-using-django-11-url-behavior-and-update-view-and-edit-menu-1554268753908)


#### Proof of work done

https://github.com/milleaduski/forums-django
πŸ‘  , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , and 82 others
properties (23)
authorduski.harahap
permlinkauthentication-system-in-the-forum-application-7-reset-password-and-send-email-reset-password-1557411149585
categoryutopian-io
json_metadata{"app":"steeditor/0.1.2","format":"markdown","image":["https://ipfs.busy.org/ipfs/QmdVUYkvGL8kk761vxJc4bk94VeG9aDqzLYudwsUNXsC5e","https://ipfs.busy.org/ipfs/QmdNMJxSatg3WtPqnR1zJD3891g8n3gByjCxzHBoiJxTz2","https://ipfs.busy.org/ipfs/QmPqXD4zDbzVcLr43fSnjJGdDttBKk3fTLhsX9K7vgVCCp","https://cdn.steemitimages.com/DQmV7d7DioXUsjQeKHWtHzfMmBvJhojC3aVNveA2BXagE8C/ezgif.com-video-to-gif.gif","https://ipfs.busy.org/ipfs/QmavANreSNpX4Xd2bLg9UraRxELiXnu4EAnh61nj5P3Bui","https://cdn.steemitimages.com/DQmfKvcynuHkRo7czjSaxCJ8xJ97JkWt3X14rsYcccyiUrK/ezgif.com-video-to-gif%20(1","https://cdn.steemitimages.com/DQmVqqTUome4jybN1RzAhvX2vk6qFwLSBMtL5enDFgSYcQ1/ezgif.com-video-to-gif%20(2","https://cdn.steemitimages.com/DQmYSndhC98Khzs5rGF8wRfhZmZLJ4vpupLoNaja4wh2FJX/ezgif.com-video-to-gif%20(3"],"tags":["utopian-io","tutorials","python","web","django"],"users":["admin","duski"],"links":["https://github.com/python","https://www.python.org/","https://www.djangoproject.com/","https://getbootstrap.com/docs/4.0/getting-started/introduction/","http://ana-balica.github.io/2015/01/29/pagination-in-django/","https://cdn.steemitimages.com/DQmfKvcynuHkRo7czjSaxCJ8xJ97JkWt3X14rsYcccyiUrK/ezgif.com-video-to-gif%20","https://cdn.steemitimages.com/DQmVqqTUome4jybN1RzAhvX2vk6qFwLSBMtL5enDFgSYcQ1/ezgif.com-video-to-gif%20","https://cdn.steemitimages.com/DQmYSndhC98Khzs5rGF8wRfhZmZLJ4vpupLoNaja4wh2FJX/ezgif.com-video-to-gif%20","https://steemit.com/utopian-io/@duski.harahap/create-a-forum-application-using-django-1-init-projects-and-dependencies-and-database-schema-1551711163679","https://steemit.com/utopian-io/@duski.harahap/create-a-forum-application-using-django-2-template-system-and-class-based-view-implementation-1552057536737","https://steemit.com/utopian-io/@duski.harahap/create-a-forum-application-using-django-3-base-template-login-and-register-system-1552311993977","https://steemit.com/utopian-io/@duski.harahap/create-a-forum-application-using-django-4-admin-dashboard-ang-setting-redirect","https://steemit.com/utopian-io/@duski.harahap/create-a-forum-application-using-django-5-slug-concept-and-generated-slug-and-use-forms-generic-view","https://steemit.com/utopian-io/@duski.harahap/create-a-forum-application-using-django-6-crud-system-and-url-protection-redirect-system","https://steemit.com/utopian-io/@duski.harahap/create-a-forum-application-using-django-7-unique-slug-and-manage-modules-in-admin-dashboard-1553268749861","https://steemit.com/utopian-io/@duski.harahap/create-a-forum-application-using-django-8-display-forum-data-and-create-and-implement-list-view-1553525769014","https://steemit.com/utopian-io/@duski.harahap/create-a-forum-application-using-django-9-single-page-for-forums-passing-params-in-routing-and-make-time-humanize-1553788983186","https://steemit.com/utopian-io/@duski.harahap/create-a-forum-application-using-django-10-detail-page-for-forums-use-slug-as-the-parameter-url-and-implement-getcontextdata","https://steemit.com/utopian-io/@duski.harahap/create-a-forum-application-using-django-11-url-behavior-and-update-view-and-edit-menu-1554268753908","https://github.com/milleaduski/forums-django"]}
created2019-05-09 14:12:42
last_update2019-05-09 14:12:42
depth0
children4
last_payout2019-05-16 14:12:42
cashout_time1969-12-31 23:59:59
total_payout_value12.906 HBD
curator_payout_value4.227 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length9,455
author_reputation60,094,717,098,672
root_title"Authentication system in the forum application #7: Reset password and Send email reset password"
beneficiaries
0.
accountutopian.pay
weight500
max_accepted_payout100,000.000 HBD
percent_hbd10,000
post_id84,536,123
net_rshares35,423,926,643,823
author_curate_reward""
vote details (146)
@portugalcoin ·
$11.74
Thank you for your contribution @duski.harahap.
After reviewing your contribution, we suggest you following points:

- Using the first person in the tutorials makes it difficult to understand the tutorials. We suggest using the third person in your text.

- Using GIFs to show results is definitely better than standard still images.

- The functionality you explain in your tutorial is very basic. In the next tutorial bring something more innovative.

Thank you for your work in developing this tutorial.
Looking forward to your upcoming tutorials.

Your contribution has been evaluated according to [Utopian policies and guidelines](https://join.utopian.io/guidelines), as well as a predefined set of questions pertaining to the category.

To view those questions and the relevant answers related to your post, [click here](https://review.utopian.io/result/8/3-1-1-1-2-3-2-3-).

---- 
Need help? Chat with us on [Discord](https://discord.gg/uTyJkNm).

[[utopian-moderator]](https://join.utopian.io/)
πŸ‘  , , , , , , , , , , , , , , , , ,
properties (23)
authorportugalcoin
permlinkre-duskiharahap-authentication-system-in-the-forum-application-7-reset-password-and-send-email-reset-password-1557411149585-20190509t201548615z
categoryutopian-io
json_metadata{"tags":["utopian-io"],"users":["duski.harahap"],"links":["https://join.utopian.io/guidelines","https://review.utopian.io/result/8/3-1-1-1-2-3-2-3-","https://discord.gg/uTyJkNm","https://join.utopian.io/"],"app":"steemit/0.1"}
created2019-05-09 20:15:48
last_update2019-05-09 20:15:48
depth1
children1
last_payout2019-05-16 20:15:48
cashout_time1969-12-31 23:59:59
total_payout_value8.922 HBD
curator_payout_value2.817 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length1,002
author_reputation602,508,960,813,215
root_title"Authentication system in the forum application #7: Reset password and Send email reset password"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id84,555,466
net_rshares22,852,314,204,082
author_curate_reward""
vote details (18)
@utopian-io ·
Thank you for your review, @portugalcoin! Keep up the good work!
properties (22)
authorutopian-io
permlinkre-re-duskiharahap-authentication-system-in-the-forum-application-7-reset-password-and-send-email-reset-password-1557411149585-20190509t201548615z-20190512t002611z
categoryutopian-io
json_metadata"{"app": "beem/0.20.17"}"
created2019-05-12 00:26:12
last_update2019-05-12 00:26:12
depth2
children0
last_payout2019-05-19 00:26:12
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length64
author_reputation152,955,367,999,756
root_title"Authentication system in the forum application #7: Reset password and Send email reset password"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id84,691,055
net_rshares0
@steem-ua ·
#### Hi @duski.harahap!

Your post was upvoted by @steem-ua, new Steem dApp, using UserAuthority for algorithmic post curation!
Your post is eligible for our upvote, thanks to our collaboration with @utopian-io!
**Feel free to join our [@steem-ua Discord server](https://discord.gg/KpBNYGz)**
properties (22)
authorsteem-ua
permlinkre-authentication-system-in-the-forum-application-7-reset-password-and-send-email-reset-password-1557411149585-20190509t204955z
categoryutopian-io
json_metadata"{"app": "beem/0.20.19"}"
created2019-05-09 20:49:57
last_update2019-05-09 20:49:57
depth1
children0
last_payout2019-05-16 20:49:57
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length292
author_reputation23,214,230,978,060
root_title"Authentication system in the forum application #7: Reset password and Send email reset password"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id84,557,489
net_rshares0
@utopian-io ·
Hey, @duski.harahap!

**Thanks for contributing on Utopian**.
We’re already looking forward to your next contribution!

**Get higher incentives and support Utopian.io!**
 Simply set @utopian.pay as a 5% (or higher) payout beneficiary on your contribution post (via [SteemPlus](https://chrome.google.com/webstore/detail/steemplus/mjbkjgcplmaneajhcbegoffkedeankaj?hl=en) or [Steeditor](https://steeditor.app)).

**Want to chat? Join us on Discord https://discord.gg/h52nFrV.**

<a href='https://steemconnect.com/sign/account-witness-vote?witness=utopian-io&approve=1'>Vote for Utopian Witness!</a>
properties (22)
authorutopian-io
permlinkre-authentication-system-in-the-forum-application-7-reset-password-and-send-email-reset-password-1557411149585-20190510t112225z
categoryutopian-io
json_metadata"{"app": "beem/0.20.17"}"
created2019-05-10 11:22:27
last_update2019-05-10 11:22:27
depth1
children0
last_payout2019-05-17 11:22:27
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length595
author_reputation152,955,367,999,756
root_title"Authentication system in the forum application #7: Reset password and Send email reset password"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id84,601,544
net_rshares0