diff --git a/mysite/.gitignore b/mysite/.gitignore new file mode 100644 index 0000000..ba520cc --- /dev/null +++ b/mysite/.gitignore @@ -0,0 +1 @@ +db.sqlite3 \ No newline at end of file diff --git a/mysite/account/.gitignore b/mysite/account/.gitignore new file mode 100644 index 0000000..826e47b --- /dev/null +++ b/mysite/account/.gitignore @@ -0,0 +1,2 @@ +credentials.py +__pycache__ \ No newline at end of file diff --git a/mysite/account/admin.py b/mysite/account/admin.py index d5ac218..85769e0 100644 --- a/mysite/account/admin.py +++ b/mysite/account/admin.py @@ -2,9 +2,10 @@ #password: adminpassword from django.contrib import admin -from .models import Case, Profile, Passwords +from .models import Case, Profile, Passwords, Otp_database # Register your models here. admin.site.register(Case) admin.site.register(Passwords) admin.site.register(Profile) +admin.site.register(Otp_database) diff --git a/mysite/account/migrations/0002_otp_database.py b/mysite/account/migrations/0002_otp_database.py new file mode 100644 index 0000000..626e02b --- /dev/null +++ b/mysite/account/migrations/0002_otp_database.py @@ -0,0 +1,22 @@ +# Generated by Django 2.0.9 on 2019-03-17 17:31 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('account', '0001_initial'), + ] + + operations = [ + migrations.CreateModel( + name='Otp_database', + fields=[ + ('username', models.CharField(max_length=20, primary_key=True, serialize=False)), + ('otp_id', models.CharField(max_length=10)), + ('otp_text', models.CharField(max_length=10)), + ('timestamp', models.DateTimeField()), + ], + ), + ] diff --git a/mysite/account/migrations/__pycache__/0001_initial.cpython-36.pyc b/mysite/account/migrations/__pycache__/0001_initial.cpython-36.pyc index 665afcc..da34e91 100644 Binary files a/mysite/account/migrations/__pycache__/0001_initial.cpython-36.pyc and b/mysite/account/migrations/__pycache__/0001_initial.cpython-36.pyc differ diff --git a/mysite/account/migrations/__pycache__/__init__.cpython-36.pyc b/mysite/account/migrations/__pycache__/__init__.cpython-36.pyc index 8e9ff5e..e6cea3e 100644 Binary files a/mysite/account/migrations/__pycache__/__init__.cpython-36.pyc and b/mysite/account/migrations/__pycache__/__init__.cpython-36.pyc differ diff --git a/mysite/account/models.py b/mysite/account/models.py index 9897fd5..18ca1a9 100644 --- a/mysite/account/models.py +++ b/mysite/account/models.py @@ -18,3 +18,9 @@ class Passwords(models.Model): email = models.CharField(max_length=100) encrypted_password = models.CharField(max_length=100) belongs_to = models.ForeignKey(Profile, on_delete=models.CASCADE) + +class Otp_database(models.Model): + username = models.CharField(max_length=20, primary_key=True) + otp_id = models.CharField(max_length=10) + otp_text = models.CharField(max_length=10) + timestamp = models.DateTimeField() diff --git a/mysite/account/sendOTP.py b/mysite/account/sendOTP.py new file mode 100644 index 0000000..dc9410c --- /dev/null +++ b/mysite/account/sendOTP.py @@ -0,0 +1,26 @@ +from twilio.rest import Client +from .credentials import account_sid, auth_token, my_cell, my_twilio + +# Find these values at https://twilio.com/user/account + + +my_msg = ''.join(['Hi Mayur!!\n' for i in range(100)]) +my_msg+="-from MATHUR ;) " + + +mayur_cell="+917678599539" +def send_otp(reg_number,num): + client = Client(account_sid, auth_token) + reg_number=my_twilio + otp= "Your One Time Password is: " + print(otp+num) + message = client.messages \ + .create( + body=otp+num, + from_=reg_number, + status_callback='http://postb.in/1234abcd', + to=my_cell + ) + return message.sid + +#print(message) diff --git a/mysite/account/static/account/otp_css.css b/mysite/account/static/account/otp_css.css new file mode 100644 index 0000000..9833890 --- /dev/null +++ b/mysite/account/static/account/otp_css.css @@ -0,0 +1,51 @@ +.new-login-area{ + padding:24px; +} +h3 { + font-size: 36px; + line-height: 30px; +} +label { + font-size: 24px; +} +.request-otp-header { + margin: 40px 0px; + font-weight: 900; + +} +.login-label label { + color: #c74032; + font-weight: 600; +} +.input-edit { + border: none !important; + border-bottom: 5px solid #ccc !important; + padding: 6px 0px; + opacity: 0.8; +} +.input-edit:focus { + border-bottom-color: #c74032 !important; + box-shadow: none; + outline: 0; +} + +.request-otp { + margin-top: 40px; + background: linear-gradient(#c74032, #91041b); + font-size: 14px; + color: #fff; +} +.request-otp:focus { + box-shadow: none; +} +.fa-chevron-left { + cursor: pointer; +} +.resend-otp{ + margin-top:6px; + cursor:pointer; +} +.btn-default{ + color: #fff; + background-color: #c74032; +} diff --git a/mysite/account/static/account/otp_js.js b/mysite/account/static/account/otp_js.js new file mode 100644 index 0000000..565c723 --- /dev/null +++ b/mysite/account/static/account/otp_js.js @@ -0,0 +1,20 @@ +//$('#verify-otp').hide(); +//$('#request-otp').on('click',function(){ +//// $.ajax({ +//// type: "GET", +//// url: '\one_time_password_request', +//// success: function(data){ +//// alert(data); +//// } +//// }); +//// $.get('/one_time_password_request', function (data) { +//// //console.log(data); +//// alert(data); +//// }); +// $('#sign-in').hide(); +// $('#verify-otp').show(); +//}); +//$('.fa-chevron-left').on('click',function(){ +// $('#sign-in').show(); +// $('#verify-otp').hide(); +//}); \ No newline at end of file diff --git a/mysite/account/templates/account/base.html b/mysite/account/templates/account/base.html index 43282b8..1dee738 100644 --- a/mysite/account/templates/account/base.html +++ b/mysite/account/templates/account/base.html @@ -28,4 +28,4 @@
Your suitc {% block body %} {% endblock %} - + \ No newline at end of file diff --git a/mysite/account/templates/account/change_password.html b/mysite/account/templates/account/change_password.html new file mode 100644 index 0000000..baf97bc --- /dev/null +++ b/mysite/account/templates/account/change_password.html @@ -0,0 +1,20 @@ +{% extends 'account/base.html' %} +{% block body %} + +
+ {% csrf_token %} +
+ Change your Password. +
+ + +
+
+ + +
+ +
+
+ +{% endblock %} \ No newline at end of file diff --git a/mysite/account/templates/account/login.html b/mysite/account/templates/account/login.html index e354b39..0950ce5 100644 --- a/mysite/account/templates/account/login.html +++ b/mysite/account/templates/account/login.html @@ -25,6 +25,7 @@
+ diff --git a/mysite/account/templates/account/otp_input_page.html b/mysite/account/templates/account/otp_input_page.html new file mode 100644 index 0000000..85f11cb --- /dev/null +++ b/mysite/account/templates/account/otp_input_page.html @@ -0,0 +1,62 @@ +{% extends 'account/base.html' %} +{% block body %} + + + + OTP Request + + + + + + + + + + + +
+ +
+ {% csrf_token %} + +
+
+ + + + + + +{% endblock %} \ No newline at end of file diff --git a/mysite/account/templates/account/otp_request_page.html b/mysite/account/templates/account/otp_request_page.html new file mode 100644 index 0000000..41bb41d --- /dev/null +++ b/mysite/account/templates/account/otp_request_page.html @@ -0,0 +1,60 @@ +{% extends 'account/base.html' %} +{% block body %} + + + + OTP Request + + + + + + + + + + + + + +
+
+ +
+ +
+ + + + + + +{% endblock %} \ No newline at end of file diff --git a/mysite/account/templates/account/profile.html b/mysite/account/templates/account/profile.html new file mode 100644 index 0000000..6ade0ca --- /dev/null +++ b/mysite/account/templates/account/profile.html @@ -0,0 +1,10 @@ + + + + + Title + + +

This is your profile.

+ + \ No newline at end of file diff --git a/mysite/account/urls.py b/mysite/account/urls.py index 90968ad..130c2e1 100644 --- a/mysite/account/urls.py +++ b/mysite/account/urls.py @@ -21,4 +21,8 @@ url(r'login/', views.login, name='login'), url(r'profile/(?P[0-9]+)/', views.profile, name='profile'), url(r'addPassword/(?P[0-9]+)/', views.addPassword, name='addPassword'), + url(r'otp_request_page/', views.render_otp_request_page, name='otp_request_page'), + url(r'one_time_password_request/',views.sendOTP,name="one_time_password_request"), + url(r'one_time_password_enter/(?P[A-Za-z0-9_-]{3,20})/',views.render_otp_input_page,name="one_time_password_enter"), + url(r'change_password/(?P[A-Za-z0-9_-]{3,20})/', views.change_password_view, name='change_password'), ] diff --git a/mysite/account/views.py b/mysite/account/views.py index 2f12b60..a366608 100644 --- a/mysite/account/views.py +++ b/mysite/account/views.py @@ -1,10 +1,15 @@ from django.shortcuts import render, redirect from .forms import RegisterForm, LoginForm, AddPasswordForm -from .models import Case, Profile, Passwords +from .models import Case, Profile, Passwords, Otp_database from .encryption import encrypt from .getPasswords import main from django.contrib.auth.models import User from django.contrib.auth import authenticate, login as lgin ,logout as lgout +from .sendOTP import send_otp +import random +import datetime; +from django.utils import timezone +from django.utils.timezone import utc def getFromId(id): @@ -184,3 +189,88 @@ def addPassword(request, id): return render(request, 'account/addPassword.html', context) else: return redirect(login) + +#<================== OTP Functionality =========================> +def render_otp_request_page(request): + return render(request, 'account/otp_request_page.html') + +def change_password_view(request,username): + if request.method == 'POST': + p1=request.POST['password1'] + p2=request.POST['password2'] + if p1 == p2: + obj=Case.objects.get(username=username) + print(obj.password) + obj.password=encrypt(p1) + print(obj.password) + obj.save() + return redirect('login') + context={'error': 404} + return render(request,'account/change_password.html',context) + else: + print(username + " &&&") + context={} + return render(request,'account/change_password.html',context) +def render_otp_input_page(request,username): + print(request) + print(username + "$$$$$$") + if request.method == 'POST': + otp_input=request.POST['otp_number'] + # retrive OTP and other row from DB using username + otp_database=Otp_database.objects.filter(username=username) + print(otp_database) + otp_num=otp_database.values('otp_text')[0]['otp_text'] + t_stamp=otp_database.values('timestamp')[0]['timestamp'] + print(otp_num) + print(t_stamp) + # if timeGap > 2min delete the OTP from DB and send alert OTP expired + diff_time=datetime.datetime.utcnow().replace(tzinfo=utc) - t_stamp + print(diff_time.total_seconds()) + if diff_time.total_seconds() > 120.0 : + #delete from DB + otp_database.delete() + context={"error": 0} + return render(request, 'account/otp_input_page.html', context) + #if OTP didnt match , send Failure and delete the OTP + if otp_input == otp_num: + otp_database.delete() + print(otp_input + "==" + otp_num) + context={"username": username} + return redirect('change_password', username) + else: + otp_database.delete() + context={"error": 1} + return render(request, 'account/otp_input_page.html', context) + else: + context={"username": username} + return render(request, 'account/otp_input_page.html', context) + +def sendOTP(request): + details="heelo" + print(details) + context={'otp_details':details} + print(request) + uname=request.GET['input_username'] + print(uname) + query=Case.objects.filter(username=uname).values('phone_number') + if len(query)!=0: + reg_mobile=query[0]['phone_number'] + else : + context = {"error": "true"} + return render(request, 'account/otp_request_page.html', context) + #generate random number + num=random.randint(100001,999999) + print(num) + print(reg_mobile) + details = send_otp(reg_mobile, str(num)) + #print(details) + #save username and OTP and OTP_id and Timestamp in DB + opt_database=Otp_database() + opt_database.username=uname + opt_database.otp_text=num + opt_database.otp_id='1' + opt_database.timestamp=datetime.datetime.utcnow().replace(tzinfo=utc) + opt_database.save() + return redirect('one_time_password_enter', uname) + #return render(request, 'account/otp_input_page.html', context) #how to send details data to front end? + diff --git a/mysite/mysite/__pycache__/__init__.cpython-36.pyc b/mysite/mysite/__pycache__/__init__.cpython-36.pyc new file mode 100644 index 0000000..4fd8522 Binary files /dev/null and b/mysite/mysite/__pycache__/__init__.cpython-36.pyc differ diff --git a/mysite/mysite/__pycache__/settings.cpython-36.pyc b/mysite/mysite/__pycache__/settings.cpython-36.pyc new file mode 100644 index 0000000..106e973 Binary files /dev/null and b/mysite/mysite/__pycache__/settings.cpython-36.pyc differ diff --git a/mysite/mysite/__pycache__/urls.cpython-36.pyc b/mysite/mysite/__pycache__/urls.cpython-36.pyc new file mode 100644 index 0000000..4e3ffa0 Binary files /dev/null and b/mysite/mysite/__pycache__/urls.cpython-36.pyc differ diff --git a/mysite/mysite/__pycache__/wsgi.cpython-36.pyc b/mysite/mysite/__pycache__/wsgi.cpython-36.pyc new file mode 100644 index 0000000..7a91cab Binary files /dev/null and b/mysite/mysite/__pycache__/wsgi.cpython-36.pyc differ