awacke1 commited on
Commit
80ce47e
β€’
1 Parent(s): cb1646f

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +4 -90
README.md CHANGED
@@ -10,93 +10,7 @@ pinned: true
10
  license: mit
11
  ---
12
 
13
- import hashlib
14
- import streamlit as st
15
- import textflowsms as tf
16
-
17
-
18
- # Function to ensure phone number is correctly formatted
19
- def format_phone_number(phone_number):
20
- if len(phone_number) == 10 and not phone_number.startswith('+'):
21
- return '+1' + phone_number
22
- return phone_number
23
-
24
- # Initialize session state variables if they don't exist
25
- if 'phone_number' not in st.session_state:
26
- st.session_state['phone_number'] = '+19522583980' # Default phone number
27
- if 'password' not in st.session_state:
28
- st.session_state['password'] = ''
29
- if 'hash' not in st.session_state:
30
- st.session_state['hash'] = ''
31
-
32
- # Function to hash a password
33
- def hash_password(password):
34
- return hashlib.sha256(password.encode()).hexdigest()[:6]
35
-
36
- # Function to append to the log file or create it if it doesn't exist
37
- def append_to_log(phone_number):
38
- if not os.path.exists('LoggedConfirmations.txt'):
39
- with open('LoggedConfirmations.txt', 'w') as log_file:
40
- log_file.write(f"{phone_number}\n")
41
- else:
42
- with open('LoggedConfirmations.txt', 'a') as log_file:
43
- log_file.write(f"{phone_number}\n")
44
-
45
- # Mobile Phone field with emoji
46
- user_phone_input = st.sidebar.text_input("πŸ“± Mobile Phone", value=st.session_state.get('phone_number', ''))
47
-
48
- # Password field with emoji
49
- password_input = st.sidebar.text_input("πŸ”‘ Set Password", type='password')
50
-
51
- # Button to save the phone number and password
52
- if st.sidebar.button('πŸ’Ύ Save Settings'):
53
- st.session_state['phone_number'] = format_phone_number(user_phone_input)
54
- st.session_state['password'] = hash_password(password_input)
55
- st.sidebar.success("Settings saved successfully!")
56
-
57
- # Function to send verification SMS
58
- def send_verification_sms():
59
-
60
- # Load the API key from an environment variable
61
- api_key = os.getenv('API_KEY')
62
- tf.useKey(api_key)
63
- #tf.sendSMS("+19522583980", "Test 2")
64
-
65
- base_url = "https://huggingface.co/spaces/awacke1/RT-SMS-Phone-Verify"
66
- # Correct the sendSMS function call
67
- #phone=st.session_state['phone_number']
68
- phone=user_phone_input
69
- st.write('Sending SMS to phone number ' + phone)
70
-
71
- hashmessage=f"Verify here: {base_url}?hash={st.session_state['password']}"
72
- st.write('Hash message: ' + hashmessage)
73
-
74
- result = tf.sendSMS(phone, hashmessage)
75
-
76
- if(result.ok):
77
- print(result.data)
78
- st.sidebar.success("Verification link sent via SMS")
79
- else:
80
- print(result.message)
81
-
82
-
83
- # Check if the hash parameter is provided
84
- query_params = st.experimental_get_query_params()
85
- if 'hash' in query_params:
86
- st.session_state['hash'] = query_params['hash'][0]
87
- append_to_log(st.session_state['phone_number'])
88
- st.write("βœ… User has authenticated using text")
89
-
90
- # Show verification button if hash is not in session
91
- if not st.session_state['hash']:
92
- if st.sidebar.button('πŸ“¨ Send Verify Request'):
93
- send_verification_sms()
94
-
95
- # Display history log
96
- st.write("## πŸ“œ Verification History")
97
- if os.path.exists('LoggedConfirmations.txt'):
98
- with open('LoggedConfirmations.txt', 'r') as log_file:
99
- history = log_file.read()
100
- st.text(history)
101
- else:
102
- st.write("No verification history found.")
 
10
  license: mit
11
  ---
12
 
13
+ This app uses textflowsms - see links below for more info
14
+ https://pypi.org/project/textflowsms/
15
+ https://textflow.me/dashboard
16
+ https://textflow.me/api