-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
285 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,4 +11,5 @@ cert.key | |
.env | ||
posts.json | ||
users.json | ||
add_fake_data.py | ||
add_fake_data.py | ||
.vscode |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
{% extends "base.html" %} | ||
|
||
{% block title %}ورود{% endblock %} | ||
|
||
{% block content %} | ||
<h2 class="mt-4 bold-font">احراز هویت با شماره تلفن</h2> | ||
<div class="form mx-md-3"> | ||
<p class="mt-4"></p> | ||
<form action="" method="post"> | ||
<div class="d-grid gap-2 col-md-6"> | ||
{{ form.as_p }} | ||
</div> | ||
{% csrf_token %} | ||
<input type="hidden" name="next" value="{{ next }}" /> | ||
<div class="d-grid gap-2 col-md-6"> | ||
<input class="btn btn-success" type="submit" value="ارسال کد تایید"> | ||
</div> | ||
</form> | ||
<p class="mt-5 mb-2"> | ||
<p class="mb-2">احراز هویت با ایمیل:</p> | ||
<a href="{% if request.GET.next %}{% url 'account:register' %}?next={{ request.GET.next }}{% else %}{% url 'account:register' %}{% endif %}" class="btn btn-primary btn-sm"> | ||
ثبت نام با ایمیل | ||
</a> | ||
<a href="{% if request.GET.next %}{% url 'account:login' %}?next={{ request.GET.next }}{% else %}{% url 'account:login' %}{% endif %}" class="btn btn-primary btn-sm"> | ||
ورود با ایمیل | ||
</a> | ||
</p> | ||
</div> | ||
<div class="py-5"></div> | ||
{% endblock %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
{% extends "base.html" %} | ||
|
||
{% block title %}ورود{% endblock %} | ||
|
||
{% block content %} | ||
<h2 class="mt-4 bold-font">ورود به حساب کاربری</h2> | ||
<div class="form mx-md-3"> | ||
<a class="mt-4 btn btn-primary google-login bold-font" href="{% url 'account:otp_auth' %}"> | ||
ارسال دوباره کد تایید | ||
</a> | ||
<p class="mt-4"></p> | ||
<form action="" method="post"> | ||
<div class="d-grid gap-2 col-md-6"> | ||
{{ form.as_p }} | ||
</div> | ||
{% csrf_token %} | ||
<input type="hidden" name="next" value="{{ next }}" /> | ||
<div class="d-grid gap-2 col-md-6"> | ||
<input class="btn btn-success" type="submit" value="ورود"> | ||
</div> | ||
</form> | ||
<p class="mt-5 mb-2"> | ||
<p class="mb-2">احراز هویت با ایمیل:</p> | ||
<a href="{% if request.GET.next %}{% url 'account:register' %}?next={{ request.GET.next }}{% else %}{% url 'account:register' %}{% endif %}" class="btn btn-primary btn-sm"> | ||
ثبت نام با ایمیل | ||
</a> | ||
<a href="{% if request.GET.next %}{% url 'account:login' %}?next={{ request.GET.next }}{% else %}{% url 'account:login' %}{% endif %}" class="btn btn-primary btn-sm"> | ||
ورود با ایمیل | ||
</a> | ||
</p> | ||
</div> | ||
<div class="py-5"></div> | ||
{% endblock %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
from random import choices | ||
from django.conf import settings | ||
from django.utils.timezone import now | ||
from kavenegar import ( | ||
KavenegarAPI, | ||
APIException, | ||
HTTPException, | ||
) | ||
from background_task import background | ||
|
||
from . import models | ||
|
||
|
||
@background(schedule=0) | ||
def send_otp(phone, otp): | ||
try: | ||
api = KavenegarAPI(settings.API_KEY) | ||
params = { | ||
'receptor': phone, | ||
'template': 'verify', | ||
'token': otp, | ||
'type': 'sms', | ||
} | ||
response = api.verify_lookup(params) | ||
except APIException: | ||
response = None | ||
except HTTPException: | ||
response = None | ||
return response | ||
|
||
|
||
def generate_otp(length=4): | ||
return "".join(choices("123456789", k=length)) | ||
|
||
|
||
def check_otp_expiration(otp: models.OTP): | ||
diff = now() - otp.created | ||
if diff.seconds > 120: | ||
return False | ||
return True |
Oops, something went wrong.