summaryrefslogtreecommitdiff
path: root/python-django-verify-email.spec
blob: f27232187a4468aaa9a7c94cee39d74683d6c61a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
%global _empty_manifest_terminate_build 0
Name:		python-Django-Verify-Email
Version:	2.0.3
Release:	1
Summary:	A Django app for email verification.
License:	MIT License
URL:		https://github.com/foo290/Django-Verify-Email/
Source0:	https://mirrors.nju.edu.cn/pypi/web/packages/c6/e8/71387759826bd87531c78c4e2de62c43f994dcf7291127cf05ff04ac7501/Django-Verify-Email-2.0.3.tar.gz
BuildArch:	noarch


%description
In your settings.py :
```
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_PORT = 587
EMAIL_USE_TLS = True
EMAIL_HOST_USER = os.environ.get('EMAIL_ID') 
EMAIL_HOST_PASSWORD = os.environ.get('EMAIL_PW')
DEFAULT_FROM_EMAIL = 'noreply<no_reply@domain.com>'
```
## Main steps... <hr>
### Step 1 :-
Add "verify_email" to your INSTALLED_APPS setting like this:
```
    INSTALLED_APPS = [
        "verify_email.apps.VerifyEmailConfig",
    ]
```
<p id="step2">
<h3>Step 2 :-</h3>
Include the "verify_email" URLconf in your project urls.py like this:
```
urlpatterns = [
	path('verification/', include('verify_email.urls')),	
]
```
</p>
<p id="step3">
<h3>Step 3 :-</h3>
Apply migrations...
```
python manage.py migrate
```
</p>
### Step 4 :-
For sending email from a signup form, in your views.py import:
```
from verify_email.email_handler import send_verification_email
```
Now in the function where you are validating the form:
```
def register_user(request):
    if form.is_valid():
        inactive_user = send_verification_email(request, form)
```
<b>Attention : </b>"send_verification_email()" takes two arguments, requests and form in order to set user's active status. 
The "inactive_user" that is returned by "send_verification_email()" contains a saved user object just like form.save() would do(with is_active status set as False), which you can further use to extract user information from cleaned_data dictionary, as shown below :
```
inactive_user.cleaned_data['email']
# Output: test-user123@gmail.com
```
The user is already being saved as inactive and you don't have to .save() it explicitly.
<b>If anything goes wrong in sending the verification link email, the user will not be saved, so that the user can try again.</b>
### At this point, you are good to go...
 Start the development server and signup with an email and you should be getting an email on the entered email with the default template for account activation. (You can provide your own HTML template. see <a href='#advance'>Advance Section</a>)
 <b>Note : </b>The app comes with default email templates which can be overriden. See <a href='#customemailtemplate'> Custom Email Templates</a>
# Verifying User's email : 
<h3 style='text-align:center'>Nothing...</h3><br>
That's right! , you don't have to implement any other code for validating users with their respective unique tokens and emails. 
<b>The app takes care of everything in the background.</b>
* When the user clicks on the verification link, it comes to :
    ```
    path('verification/', include('verify_email')),
    ```
    which you defined in your project's urls.py in <a href='#step2'>step 2</a> above.
* This pattern is further extended in this app's urls.py where it accepts encoded email and encoded hashed tokens from the verification link.
* It then checks for users by that email.
* If the user exists, it then checks for a token if it is valid for that user or not.
* If the token is valid, it activates the user's account by setting is_active attribute to True and last_login to timezone.now().
* If the token is already been redeemed or modified, you'll be redirected to a "verification failed" page.
#### This whole process from generating HMAC hashed token for each user to verify it for a unique user, is abstracted within the app 😃.
<p id="advance">
<h1>Advance</h1>
<p id="link-expiring">
<h2>Expiration of link and Resending emails :</h2>
If you want your link to expire after a certain amount of time, you can use signed links, <b>All you have to do is just set a variable in the settings.py file and BAMM! you got yourself a link that will expire after the specified time.</b><br>
It's that simple, just setting a variable. <br><br>
If you don't set this variable, the link will expire after being used at least once. 
<br>
The link, by default, does not expire until it has been used at least once, however, you can 
**change** this behavior by specifying the time as
"EXPIRE_AFTER" in settings.py. The variable can be set as :
* By default the time is considered in seconds, so if you set "EXPIRE_AFTER" as an integer, that will be considered in seconds.
* You can specify time unit for large times, max unit is days.
* **Its very simple** just suffix the "EXPIRE_AFTER" variable's value with a time unit from ["s", "m", "h", "d"]. (Keep in mind, the "m" here is minutes, not month)
**Example**
* If I have to make a link expire after **one-day**, then I'd do:
    * EXPIRE_AFTER = "1d"  # Will expire after one day from link generation
* If I have to make a link expire after **one-hour**, then I'd do:
    * EXPIRE_AFTER = "1h"  # Will expire after one hour from link generation
* If I have to make a link expire after **one-minute**, then I'd do:
    * EXPIRE_AFTER = "1m"  # Will expire after 1 minute from link generation
**Note:** By default, if you do not specify a unit, it'll be considered in seconds.
</p>
<p id="resending-email">
<h2>Re-Sending Email</h2> <hr>
</p>
A user can request a new verification link **For a specific no. of times** in case the previous one has expired. By default, a user can request
new link **two times** which, obviously can be modified by you.
Set a "MAX_RETRIES" variable in settings.py specifying the no. of times a user is allowed to request a new link.
After that no. is exceeded, the user will be automatically redirected to an error page showing that you have maxed out.
<p id="resending-email-using-link">
<h2>Re-Sending Email using previous link</h2> 
</p>
When the link expires, the user will be redirected to a page displaying that the link is expired and has a button to request a new email, now as long as the user hasn't exceeded max retries, the user can request a new email simply by clicking on that button.
<p id='resending-email-using-form'>
<h2>Resend Email using Email Form</h2> 
</p>
In case when previous email/link is lost or deleted by the client, they can request a new email by specifying their email.
The path for that is `https://yourdomain/verification/user/verify-email/request-new-link/`, at this path, there will be a form that will ask for the email of the registered user.
The pathname is `request-new-link-from-email` which you can use to create a button on your front end and redirect traffic to the request email page.
Something like:
```html
<a href="{% url 'request-new-link-from-email' %}">
```
This will redirect you to full path `/verification/user/verify-email/request-new-link/`
There are several checks done before sending an email again:
* if the email is registered and the user's account is not been activated
* the user hasn't exceeded max retry limit(set by you),
Then a new email will be sent to the given email.
The form template is supposed to be changed unless you are okay with the default template provided with the package.
To set your own custom template for form, set a variable name `REQUEST_NEW_EMAIL_TEMPLATE` in settings.py with the path of template you want to use. Example:
```py
REQUEST_NEW_EMAIL_TEMPLATE = 'mytemplates/mycustomtemplate.html'
```
and then your template will be displayed at the path.
**Making Form:** while making your custom template, keep in mind that the view will pass a variable named `form` to the provided template, this form will contain only 1 field `email`. Sample code that you can use while making your template is here:
```html
<form method='POST' >
            {% csrf_token %}
            <fieldset>
                {{form}}
            </fieldset>
            <div style="margin-top: 50px;">
                <button class="btn btn-outline-info" type="submit">Request New Email</button>
            </div>
</form>
```
You can apply your styles or whatever you want. (this code is used in the default template)
**NOTE:** This info is stored in the database so you have to apply migrations (<a href='#step3'>step 3</a>) to use this feature. 
</p>
<p id="customemailtemplate">
<h2>Custom Email Templates : </h2>
The app is packed with default HTML templates to handle the web pages but if you want to provide your own template you can do it by setting an attribute in settings.py :
```
HTML_MESSAGE_TEMPLATE = "path/to/html_template.html"
VERIFICATION_SUCCESS_TEMPLATE = "path/to/success.html"
VERIFICATION_FAILED_TEMPLATE = "path/to/failed.html"
REQUEST_NEW_EMAIL_TEMPLATE = "path/to/email.html"
LINK_EXPIRED_TEMPLATE = 'path/to/expired.html'
NEW_EMAIL_SENT_TEMPLATE  = 'path/to/new_email_sent.html'
```
```
SUBJECT = 'subject of email'
# default subject is: Email Verification Mail
```
</p>
## Inside Templates : <hr>
### Custom HTML Message Template :
Two variables are passed in context dict of "HTML_MESSAGE_TEMPLATE" :
* ```{{request}}``` : Which is the same request passed in to send_verification_email.
* ```{{link}}``` : Which contains verification link
<b>IMPORTANT : </b> if you are using custom html message template for email that has to be sent to user, <u>provide a <b>{{link}}</b> as a template tag to contain verification link.</u> 
<b>You Must Pass This In Your Template</b>. Otherwise, the sent mail will not contain the verification link.
For Ex :
```my_custom_email_message.html : ```
```
<div class="format-font" >
    <a href="{{link}}" class="my-button" >Verify</a>  # ----> The "link" variable is passed by the app's backend containing verification link.
</div>

%package -n python3-Django-Verify-Email
Summary:	A Django app for email verification.
Provides:	python-Django-Verify-Email
BuildRequires:	python3-devel
BuildRequires:	python3-setuptools
BuildRequires:	python3-pip
%description -n python3-Django-Verify-Email
In your settings.py :
```
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_PORT = 587
EMAIL_USE_TLS = True
EMAIL_HOST_USER = os.environ.get('EMAIL_ID') 
EMAIL_HOST_PASSWORD = os.environ.get('EMAIL_PW')
DEFAULT_FROM_EMAIL = 'noreply<no_reply@domain.com>'
```
## Main steps... <hr>
### Step 1 :-
Add "verify_email" to your INSTALLED_APPS setting like this:
```
    INSTALLED_APPS = [
        "verify_email.apps.VerifyEmailConfig",
    ]
```
<p id="step2">
<h3>Step 2 :-</h3>
Include the "verify_email" URLconf in your project urls.py like this:
```
urlpatterns = [
	path('verification/', include('verify_email.urls')),	
]
```
</p>
<p id="step3">
<h3>Step 3 :-</h3>
Apply migrations...
```
python manage.py migrate
```
</p>
### Step 4 :-
For sending email from a signup form, in your views.py import:
```
from verify_email.email_handler import send_verification_email
```
Now in the function where you are validating the form:
```
def register_user(request):
    if form.is_valid():
        inactive_user = send_verification_email(request, form)
```
<b>Attention : </b>"send_verification_email()" takes two arguments, requests and form in order to set user's active status. 
The "inactive_user" that is returned by "send_verification_email()" contains a saved user object just like form.save() would do(with is_active status set as False), which you can further use to extract user information from cleaned_data dictionary, as shown below :
```
inactive_user.cleaned_data['email']
# Output: test-user123@gmail.com
```
The user is already being saved as inactive and you don't have to .save() it explicitly.
<b>If anything goes wrong in sending the verification link email, the user will not be saved, so that the user can try again.</b>
### At this point, you are good to go...
 Start the development server and signup with an email and you should be getting an email on the entered email with the default template for account activation. (You can provide your own HTML template. see <a href='#advance'>Advance Section</a>)
 <b>Note : </b>The app comes with default email templates which can be overriden. See <a href='#customemailtemplate'> Custom Email Templates</a>
# Verifying User's email : 
<h3 style='text-align:center'>Nothing...</h3><br>
That's right! , you don't have to implement any other code for validating users with their respective unique tokens and emails. 
<b>The app takes care of everything in the background.</b>
* When the user clicks on the verification link, it comes to :
    ```
    path('verification/', include('verify_email')),
    ```
    which you defined in your project's urls.py in <a href='#step2'>step 2</a> above.
* This pattern is further extended in this app's urls.py where it accepts encoded email and encoded hashed tokens from the verification link.
* It then checks for users by that email.
* If the user exists, it then checks for a token if it is valid for that user or not.
* If the token is valid, it activates the user's account by setting is_active attribute to True and last_login to timezone.now().
* If the token is already been redeemed or modified, you'll be redirected to a "verification failed" page.
#### This whole process from generating HMAC hashed token for each user to verify it for a unique user, is abstracted within the app 😃.
<p id="advance">
<h1>Advance</h1>
<p id="link-expiring">
<h2>Expiration of link and Resending emails :</h2>
If you want your link to expire after a certain amount of time, you can use signed links, <b>All you have to do is just set a variable in the settings.py file and BAMM! you got yourself a link that will expire after the specified time.</b><br>
It's that simple, just setting a variable. <br><br>
If you don't set this variable, the link will expire after being used at least once. 
<br>
The link, by default, does not expire until it has been used at least once, however, you can 
**change** this behavior by specifying the time as
"EXPIRE_AFTER" in settings.py. The variable can be set as :
* By default the time is considered in seconds, so if you set "EXPIRE_AFTER" as an integer, that will be considered in seconds.
* You can specify time unit for large times, max unit is days.
* **Its very simple** just suffix the "EXPIRE_AFTER" variable's value with a time unit from ["s", "m", "h", "d"]. (Keep in mind, the "m" here is minutes, not month)
**Example**
* If I have to make a link expire after **one-day**, then I'd do:
    * EXPIRE_AFTER = "1d"  # Will expire after one day from link generation
* If I have to make a link expire after **one-hour**, then I'd do:
    * EXPIRE_AFTER = "1h"  # Will expire after one hour from link generation
* If I have to make a link expire after **one-minute**, then I'd do:
    * EXPIRE_AFTER = "1m"  # Will expire after 1 minute from link generation
**Note:** By default, if you do not specify a unit, it'll be considered in seconds.
</p>
<p id="resending-email">
<h2>Re-Sending Email</h2> <hr>
</p>
A user can request a new verification link **For a specific no. of times** in case the previous one has expired. By default, a user can request
new link **two times** which, obviously can be modified by you.
Set a "MAX_RETRIES" variable in settings.py specifying the no. of times a user is allowed to request a new link.
After that no. is exceeded, the user will be automatically redirected to an error page showing that you have maxed out.
<p id="resending-email-using-link">
<h2>Re-Sending Email using previous link</h2> 
</p>
When the link expires, the user will be redirected to a page displaying that the link is expired and has a button to request a new email, now as long as the user hasn't exceeded max retries, the user can request a new email simply by clicking on that button.
<p id='resending-email-using-form'>
<h2>Resend Email using Email Form</h2> 
</p>
In case when previous email/link is lost or deleted by the client, they can request a new email by specifying their email.
The path for that is `https://yourdomain/verification/user/verify-email/request-new-link/`, at this path, there will be a form that will ask for the email of the registered user.
The pathname is `request-new-link-from-email` which you can use to create a button on your front end and redirect traffic to the request email page.
Something like:
```html
<a href="{% url 'request-new-link-from-email' %}">
```
This will redirect you to full path `/verification/user/verify-email/request-new-link/`
There are several checks done before sending an email again:
* if the email is registered and the user's account is not been activated
* the user hasn't exceeded max retry limit(set by you),
Then a new email will be sent to the given email.
The form template is supposed to be changed unless you are okay with the default template provided with the package.
To set your own custom template for form, set a variable name `REQUEST_NEW_EMAIL_TEMPLATE` in settings.py with the path of template you want to use. Example:
```py
REQUEST_NEW_EMAIL_TEMPLATE = 'mytemplates/mycustomtemplate.html'
```
and then your template will be displayed at the path.
**Making Form:** while making your custom template, keep in mind that the view will pass a variable named `form` to the provided template, this form will contain only 1 field `email`. Sample code that you can use while making your template is here:
```html
<form method='POST' >
            {% csrf_token %}
            <fieldset>
                {{form}}
            </fieldset>
            <div style="margin-top: 50px;">
                <button class="btn btn-outline-info" type="submit">Request New Email</button>
            </div>
</form>
```
You can apply your styles or whatever you want. (this code is used in the default template)
**NOTE:** This info is stored in the database so you have to apply migrations (<a href='#step3'>step 3</a>) to use this feature. 
</p>
<p id="customemailtemplate">
<h2>Custom Email Templates : </h2>
The app is packed with default HTML templates to handle the web pages but if you want to provide your own template you can do it by setting an attribute in settings.py :
```
HTML_MESSAGE_TEMPLATE = "path/to/html_template.html"
VERIFICATION_SUCCESS_TEMPLATE = "path/to/success.html"
VERIFICATION_FAILED_TEMPLATE = "path/to/failed.html"
REQUEST_NEW_EMAIL_TEMPLATE = "path/to/email.html"
LINK_EXPIRED_TEMPLATE = 'path/to/expired.html'
NEW_EMAIL_SENT_TEMPLATE  = 'path/to/new_email_sent.html'
```
```
SUBJECT = 'subject of email'
# default subject is: Email Verification Mail
```
</p>
## Inside Templates : <hr>
### Custom HTML Message Template :
Two variables are passed in context dict of "HTML_MESSAGE_TEMPLATE" :
* ```{{request}}``` : Which is the same request passed in to send_verification_email.
* ```{{link}}``` : Which contains verification link
<b>IMPORTANT : </b> if you are using custom html message template for email that has to be sent to user, <u>provide a <b>{{link}}</b> as a template tag to contain verification link.</u> 
<b>You Must Pass This In Your Template</b>. Otherwise, the sent mail will not contain the verification link.
For Ex :
```my_custom_email_message.html : ```
```
<div class="format-font" >
    <a href="{{link}}" class="my-button" >Verify</a>  # ----> The "link" variable is passed by the app's backend containing verification link.
</div>

%package help
Summary:	Development documents and examples for Django-Verify-Email
Provides:	python3-Django-Verify-Email-doc
%description help
In your settings.py :
```
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_PORT = 587
EMAIL_USE_TLS = True
EMAIL_HOST_USER = os.environ.get('EMAIL_ID') 
EMAIL_HOST_PASSWORD = os.environ.get('EMAIL_PW')
DEFAULT_FROM_EMAIL = 'noreply<no_reply@domain.com>'
```
## Main steps... <hr>
### Step 1 :-
Add "verify_email" to your INSTALLED_APPS setting like this:
```
    INSTALLED_APPS = [
        "verify_email.apps.VerifyEmailConfig",
    ]
```
<p id="step2">
<h3>Step 2 :-</h3>
Include the "verify_email" URLconf in your project urls.py like this:
```
urlpatterns = [
	path('verification/', include('verify_email.urls')),	
]
```
</p>
<p id="step3">
<h3>Step 3 :-</h3>
Apply migrations...
```
python manage.py migrate
```
</p>
### Step 4 :-
For sending email from a signup form, in your views.py import:
```
from verify_email.email_handler import send_verification_email
```
Now in the function where you are validating the form:
```
def register_user(request):
    if form.is_valid():
        inactive_user = send_verification_email(request, form)
```
<b>Attention : </b>"send_verification_email()" takes two arguments, requests and form in order to set user's active status. 
The "inactive_user" that is returned by "send_verification_email()" contains a saved user object just like form.save() would do(with is_active status set as False), which you can further use to extract user information from cleaned_data dictionary, as shown below :
```
inactive_user.cleaned_data['email']
# Output: test-user123@gmail.com
```
The user is already being saved as inactive and you don't have to .save() it explicitly.
<b>If anything goes wrong in sending the verification link email, the user will not be saved, so that the user can try again.</b>
### At this point, you are good to go...
 Start the development server and signup with an email and you should be getting an email on the entered email with the default template for account activation. (You can provide your own HTML template. see <a href='#advance'>Advance Section</a>)
 <b>Note : </b>The app comes with default email templates which can be overriden. See <a href='#customemailtemplate'> Custom Email Templates</a>
# Verifying User's email : 
<h3 style='text-align:center'>Nothing...</h3><br>
That's right! , you don't have to implement any other code for validating users with their respective unique tokens and emails. 
<b>The app takes care of everything in the background.</b>
* When the user clicks on the verification link, it comes to :
    ```
    path('verification/', include('verify_email')),
    ```
    which you defined in your project's urls.py in <a href='#step2'>step 2</a> above.
* This pattern is further extended in this app's urls.py where it accepts encoded email and encoded hashed tokens from the verification link.
* It then checks for users by that email.
* If the user exists, it then checks for a token if it is valid for that user or not.
* If the token is valid, it activates the user's account by setting is_active attribute to True and last_login to timezone.now().
* If the token is already been redeemed or modified, you'll be redirected to a "verification failed" page.
#### This whole process from generating HMAC hashed token for each user to verify it for a unique user, is abstracted within the app 😃.
<p id="advance">
<h1>Advance</h1>
<p id="link-expiring">
<h2>Expiration of link and Resending emails :</h2>
If you want your link to expire after a certain amount of time, you can use signed links, <b>All you have to do is just set a variable in the settings.py file and BAMM! you got yourself a link that will expire after the specified time.</b><br>
It's that simple, just setting a variable. <br><br>
If you don't set this variable, the link will expire after being used at least once. 
<br>
The link, by default, does not expire until it has been used at least once, however, you can 
**change** this behavior by specifying the time as
"EXPIRE_AFTER" in settings.py. The variable can be set as :
* By default the time is considered in seconds, so if you set "EXPIRE_AFTER" as an integer, that will be considered in seconds.
* You can specify time unit for large times, max unit is days.
* **Its very simple** just suffix the "EXPIRE_AFTER" variable's value with a time unit from ["s", "m", "h", "d"]. (Keep in mind, the "m" here is minutes, not month)
**Example**
* If I have to make a link expire after **one-day**, then I'd do:
    * EXPIRE_AFTER = "1d"  # Will expire after one day from link generation
* If I have to make a link expire after **one-hour**, then I'd do:
    * EXPIRE_AFTER = "1h"  # Will expire after one hour from link generation
* If I have to make a link expire after **one-minute**, then I'd do:
    * EXPIRE_AFTER = "1m"  # Will expire after 1 minute from link generation
**Note:** By default, if you do not specify a unit, it'll be considered in seconds.
</p>
<p id="resending-email">
<h2>Re-Sending Email</h2> <hr>
</p>
A user can request a new verification link **For a specific no. of times** in case the previous one has expired. By default, a user can request
new link **two times** which, obviously can be modified by you.
Set a "MAX_RETRIES" variable in settings.py specifying the no. of times a user is allowed to request a new link.
After that no. is exceeded, the user will be automatically redirected to an error page showing that you have maxed out.
<p id="resending-email-using-link">
<h2>Re-Sending Email using previous link</h2> 
</p>
When the link expires, the user will be redirected to a page displaying that the link is expired and has a button to request a new email, now as long as the user hasn't exceeded max retries, the user can request a new email simply by clicking on that button.
<p id='resending-email-using-form'>
<h2>Resend Email using Email Form</h2> 
</p>
In case when previous email/link is lost or deleted by the client, they can request a new email by specifying their email.
The path for that is `https://yourdomain/verification/user/verify-email/request-new-link/`, at this path, there will be a form that will ask for the email of the registered user.
The pathname is `request-new-link-from-email` which you can use to create a button on your front end and redirect traffic to the request email page.
Something like:
```html
<a href="{% url 'request-new-link-from-email' %}">
```
This will redirect you to full path `/verification/user/verify-email/request-new-link/`
There are several checks done before sending an email again:
* if the email is registered and the user's account is not been activated
* the user hasn't exceeded max retry limit(set by you),
Then a new email will be sent to the given email.
The form template is supposed to be changed unless you are okay with the default template provided with the package.
To set your own custom template for form, set a variable name `REQUEST_NEW_EMAIL_TEMPLATE` in settings.py with the path of template you want to use. Example:
```py
REQUEST_NEW_EMAIL_TEMPLATE = 'mytemplates/mycustomtemplate.html'
```
and then your template will be displayed at the path.
**Making Form:** while making your custom template, keep in mind that the view will pass a variable named `form` to the provided template, this form will contain only 1 field `email`. Sample code that you can use while making your template is here:
```html
<form method='POST' >
            {% csrf_token %}
            <fieldset>
                {{form}}
            </fieldset>
            <div style="margin-top: 50px;">
                <button class="btn btn-outline-info" type="submit">Request New Email</button>
            </div>
</form>
```
You can apply your styles or whatever you want. (this code is used in the default template)
**NOTE:** This info is stored in the database so you have to apply migrations (<a href='#step3'>step 3</a>) to use this feature. 
</p>
<p id="customemailtemplate">
<h2>Custom Email Templates : </h2>
The app is packed with default HTML templates to handle the web pages but if you want to provide your own template you can do it by setting an attribute in settings.py :
```
HTML_MESSAGE_TEMPLATE = "path/to/html_template.html"
VERIFICATION_SUCCESS_TEMPLATE = "path/to/success.html"
VERIFICATION_FAILED_TEMPLATE = "path/to/failed.html"
REQUEST_NEW_EMAIL_TEMPLATE = "path/to/email.html"
LINK_EXPIRED_TEMPLATE = 'path/to/expired.html'
NEW_EMAIL_SENT_TEMPLATE  = 'path/to/new_email_sent.html'
```
```
SUBJECT = 'subject of email'
# default subject is: Email Verification Mail
```
</p>
## Inside Templates : <hr>
### Custom HTML Message Template :
Two variables are passed in context dict of "HTML_MESSAGE_TEMPLATE" :
* ```{{request}}``` : Which is the same request passed in to send_verification_email.
* ```{{link}}``` : Which contains verification link
<b>IMPORTANT : </b> if you are using custom html message template for email that has to be sent to user, <u>provide a <b>{{link}}</b> as a template tag to contain verification link.</u> 
<b>You Must Pass This In Your Template</b>. Otherwise, the sent mail will not contain the verification link.
For Ex :
```my_custom_email_message.html : ```
```
<div class="format-font" >
    <a href="{{link}}" class="my-button" >Verify</a>  # ----> The "link" variable is passed by the app's backend containing verification link.
</div>

%prep
%autosetup -n Django-Verify-Email-2.0.3

%build
%py3_build

%install
%py3_install
install -d -m755 %{buildroot}/%{_pkgdocdir}
if [ -d doc ]; then cp -arf doc %{buildroot}/%{_pkgdocdir}; fi
if [ -d docs ]; then cp -arf docs %{buildroot}/%{_pkgdocdir}; fi
if [ -d example ]; then cp -arf example %{buildroot}/%{_pkgdocdir}; fi
if [ -d examples ]; then cp -arf examples %{buildroot}/%{_pkgdocdir}; fi
pushd %{buildroot}
if [ -d usr/lib ]; then
	find usr/lib -type f -printf "/%h/%f\n" >> filelist.lst
fi
if [ -d usr/lib64 ]; then
	find usr/lib64 -type f -printf "/%h/%f\n" >> filelist.lst
fi
if [ -d usr/bin ]; then
	find usr/bin -type f -printf "/%h/%f\n" >> filelist.lst
fi
if [ -d usr/sbin ]; then
	find usr/sbin -type f -printf "/%h/%f\n" >> filelist.lst
fi
touch doclist.lst
if [ -d usr/share/man ]; then
	find usr/share/man -type f -printf "/%h/%f.gz\n" >> doclist.lst
fi
popd
mv %{buildroot}/filelist.lst .
mv %{buildroot}/doclist.lst .

%files -n python3-Django-Verify-Email -f filelist.lst
%dir %{python3_sitelib}/*

%files help -f doclist.lst
%{_docdir}/*

%changelog
* Wed May 10 2023 Python_Bot <Python_Bot@openeuler.org> - 2.0.3-1
- Package Spec generated