nagasurendra commited on
Commit
48b2b81
·
verified ·
1 Parent(s): c007dc3

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +0 -79
app.py CHANGED
@@ -1,87 +1,8 @@
1
  import gradio as gr
2
  import pandas as pd
3
  from bcrypt import hashpw, gensalt, checkpw
4
- mport requests
5
- import json
6
-
7
- # Salesforce Credentials
8
- CONSUMER_KEY = "3MVG9PwZx9R6_UrcDlsRUsfM9CGTVKE82QnI5Vz02b.lv3H2yjDv_wy9.nrYihWYLUD1bv08N_qCG_gxiV5y8"
9
- CONSUMER_SECRET = "94983416FB1DF4E754B56F69982F07D94D8971523E6893B8A62D75CD8E9E3E34"
10
- USERNAME = "surendra@sathkrutha.ccom"
11
- PASSWORD = "Lavanyanaga@123"
12
- SECURITY_TOKEN = "GH9RG97LroDoLe6gAAOHaJBP"
13
-
14
- # Salesforce Authentication
15
- AUTH_URL = "https://login.salesforce.com/services/oauth2/token"
16
- BASE_URL = None
17
- HEADERS = None
18
-
19
-
20
- def authenticate_salesforce():
21
- global BASE_URL, HEADERS
22
- data = {
23
- "grant_type": "password",
24
- "client_id": CONSUMER_KEY,
25
- "client_secret": CONSUMER_SECRET,
26
- "username": USERNAME,
27
- "password": PASSWORD + SECURITY_TOKEN,
28
- }
29
- response = requests.post(AUTH_URL, data=data)
30
- if response.status_code == 200:
31
- auth_data = response.json()
32
- BASE_URL = auth_data["instance_url"]
33
- HEADERS = {
34
- "Authorization": f"Bearer {auth_data['access_token']}",
35
- "Content-Type": "application/json",
36
- }
37
- else:
38
- raise Exception(f"Failed to authenticate with Salesforce: {response.text}")
39
 
40
 
41
- def check_credentials(email, password):
42
- """Check user credentials during login."""
43
- try:
44
- authenticate_salesforce()
45
- query = f"SELECT Password__c FROM User_Login__c WHERE Email__c = '{email}'"
46
- response = requests.get(f"{BASE_URL}/services/data/v56.0/query?q={query}", headers=HEADERS)
47
- if response.status_code == 200:
48
- records = response.json().get("records", [])
49
- if records and records[0]["Password__c"] == password:
50
- return True
51
- return False
52
- except Exception as e:
53
- print(f"Error checking credentials: {e}")
54
- return False
55
-
56
-
57
- def save_user(name, phone, email, password):
58
- """Save user details to Salesforce."""
59
- try:
60
- authenticate_salesforce()
61
- # Check if email already exists
62
- query = f"SELECT Id FROM User_Login__c WHERE Email__c = '{email}'"
63
- response = requests.get(f"{BASE_URL}/services/data/v56.0/query?q={query}", headers=HEADERS)
64
- if response.status_code == 200:
65
- if response.json().get("totalSize", 0) > 0:
66
- return False # Email already exists
67
-
68
- # Create new user
69
- user_data = {
70
- "Name__c": name,
71
- "Phone__c": phone,
72
- "Email__c": email,
73
- "Password__c": password,
74
- }
75
- response = requests.post(f"{BASE_URL}/services/data/v56.0/sobjects/User_Login__c/", headers=HEADERS, json=user_data)
76
- if response.status_code == 201:
77
- return True
78
- else:
79
- print(f"Error saving user: {response.text}")
80
- return False
81
- except Exception as e:
82
- print(f"Error saving user: {e}")
83
- return False
84
-
85
  # Function to load the menu data
86
  def load_menu():
87
  menu_file = "menu.xlsx" # Ensure this file exists in the same directory
 
1
  import gradio as gr
2
  import pandas as pd
3
  from bcrypt import hashpw, gensalt, checkpw
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4
 
5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6
  # Function to load the menu data
7
  def load_menu():
8
  menu_file = "menu.xlsx" # Ensure this file exists in the same directory