Add 2FA support
This commit is contained in:
parent
b19393562c
commit
42c610f37f
@ -16,6 +16,10 @@ body
|
|||||||
visibility: hidden;
|
visibility: hidden;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.hidden{
|
||||||
|
visibility: hidden;
|
||||||
|
}
|
||||||
|
|
||||||
header {
|
header {
|
||||||
grid-area: header;
|
grid-area: header;
|
||||||
}
|
}
|
||||||
@ -38,7 +42,15 @@ main > nav
|
|||||||
margin-bottom: 4vw;
|
margin-bottom: 4vw;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*Color text */
|
||||||
|
|
||||||
|
.alert {
|
||||||
|
color: var(--pico-color-red-500);
|
||||||
|
}
|
||||||
|
|
||||||
|
.success {
|
||||||
|
color: var(--pico-color-green-500);
|
||||||
|
}
|
||||||
|
|
||||||
@media only screen and (max-width: 600px)
|
@media only screen and (max-width: 600px)
|
||||||
{
|
{
|
||||||
@ -167,6 +179,12 @@ footer
|
|||||||
color: var(--pico-color-red-50);
|
color: var(--pico-color-red-50);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.btn-alert {
|
||||||
|
background-color: var(--pico-color-red-550);
|
||||||
|
color: var(--pico-color-red-50);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
article {
|
article {
|
||||||
text-align: center;
|
text-align: center;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,3 +1,4 @@
|
|||||||
|
|
||||||
<script src="{{ url_for('static', filename='vendors/jquery/jquery.min.js') }}"></script>
|
<script src="{{ url_for('static', filename='vendors/jquery/jquery.min.js') }}"></script>
|
||||||
<script src="{{ url_for('static', filename='vendors/picocss/theme-switcher.js') }}"></script>
|
<script src="{{ url_for('static', filename='vendors/picocss/theme-switcher.js') }}"></script>
|
||||||
|
<script src="{{ url_for('static', filename='js/qrcode.min.js') }}"></script>
|
||||||
|
|||||||
@ -30,6 +30,7 @@ def init_db():
|
|||||||
age TEXT,
|
age TEXT,
|
||||||
website TEXT,
|
website TEXT,
|
||||||
blog_theme TEXT,
|
blog_theme TEXT,
|
||||||
|
totp CHAR(40),
|
||||||
Token CHAR(64),
|
Token CHAR(64),
|
||||||
Lost_password_token CHAR(128),
|
Lost_password_token CHAR(128),
|
||||||
invitations INTEGER DEFAULT (20),
|
invitations INTEGER DEFAULT (20),
|
||||||
@ -96,14 +97,16 @@ def db_migrate():
|
|||||||
blog_theme_col = False
|
blog_theme_col = False
|
||||||
updated_col = False
|
updated_col = False
|
||||||
lost_password_token_col = False
|
lost_password_token_col = False
|
||||||
|
totp_col = False
|
||||||
|
|
||||||
for col in db_columns:
|
for col in db_columns:
|
||||||
if "invitations" == col[0]:
|
if "invitations" == col[0]:
|
||||||
invitations_col = True
|
invitations_col = True
|
||||||
if "Lost_password_token" == col[0]:
|
if "Lost_password_token" == col[0]:
|
||||||
lost_password_token_col = True
|
lost_password_token_col = True
|
||||||
|
if "totp" == col[0]:
|
||||||
|
totp_col = True
|
||||||
|
|
||||||
cursor.execute("""SELECT name FROM PRAGMA_TABLE_INFO('Blog_posts');""")
|
cursor.execute("""SELECT name FROM PRAGMA_TABLE_INFO('Blog_posts');""")
|
||||||
db_columns = cursor.fetchall()
|
db_columns = cursor.fetchall()
|
||||||
for col in db_columns:
|
for col in db_columns:
|
||||||
@ -125,6 +128,12 @@ def db_migrate():
|
|||||||
conn.commit()
|
conn.commit()
|
||||||
print ("Ajout du champ Lost_password_token dans la table Users")
|
print ("Ajout du champ Lost_password_token dans la table Users")
|
||||||
|
|
||||||
|
if not(totp_col):
|
||||||
|
cursor.execute("""ALTER TABLE Users ADD COLUMN totp CHAR(40);""")
|
||||||
|
conn.commit()
|
||||||
|
print ("Ajout du champ totp dans la table Users")
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if not(blog_theme_col):
|
if not(blog_theme_col):
|
||||||
cursor.execute("""ALTER TABLE Blog_posts ADD COLUMN blog_theme TEXT;""")
|
cursor.execute("""ALTER TABLE Blog_posts ADD COLUMN blog_theme TEXT;""")
|
||||||
@ -136,6 +145,6 @@ def db_migrate():
|
|||||||
conn.commit()
|
conn.commit()
|
||||||
print ("Ajout du champ updated dans la table BLog")
|
print ("Ajout du champ updated dans la table BLog")
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
conn.close()
|
conn.close()
|
||||||
|
|||||||
@ -3,6 +3,8 @@ import sqlite3
|
|||||||
import os
|
import os
|
||||||
import string
|
import string
|
||||||
import random
|
import random
|
||||||
|
import time
|
||||||
|
import pyotp
|
||||||
|
|
||||||
app = Flask( 'pywallter' )
|
app = Flask( 'pywallter' )
|
||||||
app.config.from_pyfile('config.py')
|
app.config.from_pyfile('config.py')
|
||||||
@ -129,3 +131,13 @@ def gen_token(token_type):
|
|||||||
case "Lost password":
|
case "Lost password":
|
||||||
sample = ''.join(random.sample(digits + letters, 64))
|
sample = ''.join(random.sample(digits + letters, 64))
|
||||||
return sample
|
return sample
|
||||||
|
|
||||||
|
def totp_is_valid(code_key, code):
|
||||||
|
res = True
|
||||||
|
|
||||||
|
if code_key:
|
||||||
|
mytotp = pyotp.TOTP(code_key)
|
||||||
|
if not(code == mytotp.now() and res):
|
||||||
|
res = False
|
||||||
|
|
||||||
|
return res
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user