|
|
|
import os |
|
import streamlit as st |
|
from PIL import Image |
|
from streamlit_extras.switch_page_button import switch_page |
|
from baam_functions import * |
|
from datetime import datetime |
|
from bokeh.models.widgets import Button |
|
from bokeh.models import CustomJS |
|
from streamlit_bokeh_events import streamlit_bokeh_events |
|
|
|
|
|
sourceFileDir = os.path.dirname(os.path.abspath(__file__)) |
|
os.chdir(sourceFileDir) |
|
|
|
logo = Image.open('img/logo.png') |
|
st.set_page_config(page_title = "BAAM", page_icon = logo) |
|
|
|
|
|
st.session_state['user_dict'] = {} |
|
st.session_state['verification'] = False |
|
st.session_state['location'] = "" |
|
st.session_state['raw_location'] = "" |
|
st.session_state['username'] = "" |
|
|
|
|
|
def main(): |
|
"""Banking Advanced Authentication System""" |
|
|
|
|
|
contact_url = "https://www.linkedin.com/in/linhvuu" |
|
st.write("I am running out of energy. Please contact [my assistant](%s) to wake me up." % contact_url) |
|
|
|
menu = ["Home", "SignUp", "Login"] |
|
choice = st.sidebar.selectbox("Menu", menu) |
|
|
|
if choice == "Home": |
|
st.subheader("Banking Advanced Authentication Module") |
|
st.image("img/home.png") |
|
st.write("Please select one action from the Menu on the side bar. Thank you.") |
|
st.image("img/menu.png") |
|
|
|
elif choice == "SignUp": |
|
st.subheader("Create New Account") |
|
new_user = st.text_input("Username") |
|
new_password = st.text_input("Password",type='password') |
|
|
|
if st.button("Signup"): |
|
create_user_table() |
|
add_user_data(new_user,make_hashes(new_password)) |
|
st.success("You have successfully created a valid Account") |
|
st.info("Go to Login Menu to login") |
|
|
|
elif choice == "Login": |
|
|
|
|
|
col1, col2, col3 = st.columns(3) |
|
with col1: |
|
st.write(' ') |
|
|
|
|
|
with col2: |
|
st.image("img/Standard_Chartered.png", width=175) |
|
with col3: |
|
st.write(' ') |
|
|
|
|
|
st.subheader("Login") |
|
username = st.text_input("Username") |
|
password = st.text_input("Password",type='password') |
|
|
|
is_tester = st.checkbox('Login to test') |
|
login_button = Button(label="Login") |
|
|
|
|
|
login_button.js_on_event("button_click", CustomJS(code=""" |
|
navigator.geolocation.getCurrentPosition( |
|
(loc) => { |
|
document.dispatchEvent(new CustomEvent("GET_LOCATION", {detail: {lat: loc.coords.latitude, lon: loc.coords.longitude}})) |
|
} |
|
) |
|
""")) |
|
|
|
|
|
location = streamlit_bokeh_events( |
|
login_button, |
|
events="GET_LOCATION", |
|
key="get_location", |
|
refresh_on_update=False, |
|
override_height=75, |
|
debounce_time=0) |
|
|
|
|
|
if location: |
|
|
|
|
|
hashed_pswd = make_hashes(password) |
|
result = login_user(username,check_hashes(password, hashed_pswd)) |
|
|
|
|
|
if result: |
|
|
|
|
|
|
|
|
|
login_time = datetime.now() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if not(is_tester): |
|
|
|
|
|
|
|
user_dict, st.session_state['location'] = collect_data(username, location, login_time) |
|
|
|
|
|
st.session_state['user_dict'] = user_dict |
|
verification = verify_user(user_dict) |
|
|
|
|
|
|
|
weight = {'device_uuid': 40, 'mac_address': 40, 'device_name': 30.0, 'device_model': 20.0, \ |
|
'device_vendor': 4.0, 'ip_v4': 30, 'isp_name': 15.0, 'ip_country': 3.0, 'suburd': 30, 'district': 22.5, \ |
|
'city': 15.0, 'country': 3.0} |
|
|
|
|
|
|
|
|
|
|
|
st.session_state['verification'] = verification |
|
|
|
|
|
if verification: |
|
add_login_data(user_dict) |
|
|
|
|
|
switch_page("Transfer Money 💸") |
|
|
|
|
|
else: |
|
st.session_state['raw_location'] = location |
|
st.session_state['username'] = username |
|
|
|
switch_page("SelectUseCase") |
|
|
|
else: |
|
st.warning("Incorrect Username/Password") |
|
|
|
|
|
st.session_state['time_start'] = datetime.now() |
|
|
|
|
|
|
|
|
|
if __name__ == '__main__': |
|
main() |
|
|