awacke1 commited on
Commit
77ac838
β€’
1 Parent(s): 6ef82da

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +27 -19
app.py CHANGED
@@ -12,11 +12,16 @@ if 'phone_number' not in st.session_state:
12
  st.session_state['phone_number'] = '9522583980' # Default phone number
13
  if 'password' not in st.session_state:
14
  st.session_state['password'] = ''
 
 
15
 
16
  # Function to hash a password
17
  def hash_password(password):
18
  return hashlib.sha256(password.encode()).hexdigest()[:6]
19
 
 
 
 
20
  # Mobile Phone field with emoji
21
  st.sidebar.text_input("πŸ“± Mobile Phone", key='phone_number')
22
 
@@ -29,24 +34,27 @@ if st.sidebar.button('Save Password'):
29
  st.session_state['password'] = hashed_password
30
  st.sidebar.success("Password set successfully!")
31
 
32
- # Verify request button
33
- if st.sidebar.button('Send Verify Request'):
34
- # Generate verification URL with hashed password
35
- verification_url = f"https://example.com/verify?code={st.session_state['password']}"
36
- # Send the SMS
37
- tf.sendSMS(recipient=st.session_state['phone_number'], text=f"Your verification link: {verification_url}")
38
  st.sidebar.success("Verification link sent via SMS")
39
 
40
- # Interface for login test
41
- user_entered_code = st.text_input("πŸ”‘ Enter Verification Code")
42
- if st.button('Login Test'):
43
- # Verify the code
44
- resultCode = tf.verifyCode(st.session_state['phone_number'], user_entered_code)
45
- if resultCode.valid:
46
- st.success("Phone number verified successfully!")
47
- else:
48
- st.error("Verification failed. Please try again.")
49
-
50
- # Run the app
51
- if __name__ == '__main__':
52
- st.run()
 
 
 
 
 
 
12
  st.session_state['phone_number'] = '9522583980' # Default phone number
13
  if 'password' not in st.session_state:
14
  st.session_state['password'] = ''
15
+ if 'hash' not in st.session_state:
16
+ st.session_state['hash'] = ''
17
 
18
  # Function to hash a password
19
  def hash_password(password):
20
  return hashlib.sha256(password.encode()).hexdigest()[:6]
21
 
22
+ # Base URL for the verification link
23
+ base_url = "https://huggingface.co/spaces/awacke1/RT-SMS-Phone-Verify"
24
+
25
  # Mobile Phone field with emoji
26
  st.sidebar.text_input("πŸ“± Mobile Phone", key='phone_number')
27
 
 
34
  st.session_state['password'] = hashed_password
35
  st.sidebar.success("Password set successfully!")
36
 
37
+ # Function to send verification SMS
38
+ def send_verification_sms():
39
+ verification_url = f"{base_url}?hash={st.session_state['password']}"
40
+ tf.sendSMS(recipient=st.session_state['phone_number'], text=f"Verify here: {verification_url}")
 
 
41
  st.sidebar.success("Verification link sent via SMS")
42
 
43
+ # Check if the hash parameter is provided
44
+ query_params = st.experimental_get_query_params()
45
+ if 'hash' in query_params:
46
+ st.session_state['hash'] = query_params['hash'][0]
47
+ with open('LoggedConfirmations.txt', 'a') as log_file:
48
+ log_file.write(f"{st.session_state['phone_number']}\n")
49
+ st.write("User has authenticated using text")
50
+
51
+ # Show verification button if hash is not in session
52
+ if not st.session_state['hash']:
53
+ if st.sidebar.button('Send Verify Request'):
54
+ send_verification_sms()
55
+
56
+ # Display history log
57
+ st.write("## Verification History")
58
+ with open('LoggedConfirmations.txt', 'r') as log_file:
59
+ history = log_file.read()
60
+ st.text(history)