Update app.py
Browse files
app.py
CHANGED
@@ -1,44 +1,43 @@
|
|
1 |
-
from flask import Flask, render_template, request, jsonify
|
2 |
-
from flask_cors import CORS
|
3 |
-
import requests
|
4 |
-
|
5 |
-
app = Flask(__name__)
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
'
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
if __name__ == '__main__':
|
44 |
app.run(host='0.0.0.0', port=8000)
|
|
|
1 |
+
from flask import Flask, render_template, request, jsonify
|
2 |
+
from flask_cors import CORS
|
3 |
+
import requests
|
4 |
+
|
5 |
+
app = Flask(__name__)
|
6 |
+
|
7 |
+
@app.route('/')
|
8 |
+
def index():
|
9 |
+
return render_template('index.html')
|
10 |
+
|
11 |
+
@app.route('/login', methods=["POST"])
|
12 |
+
def loginChat():
|
13 |
+
username = request.form.get('username')
|
14 |
+
password = request.form.get('password')
|
15 |
+
|
16 |
+
# Call send_request function to handle the HTTP POST request to external system
|
17 |
+
response = send_request(password, username)
|
18 |
+
|
19 |
+
# Process the response and return appropriate JSON response
|
20 |
+
if response == '1':
|
21 |
+
return jsonify({'response': 1, 'message': 'Login successful'})
|
22 |
+
elif response == '2':
|
23 |
+
return jsonify({'response': 2, 'message': 'Invalid username or password'})
|
24 |
+
elif response == '3':
|
25 |
+
return jsonify({'response': 3, 'message': 'Special action required (e.g., page reload)'})
|
26 |
+
else:
|
27 |
+
return jsonify({'response': 0, 'message': 'Unknown response from external system'})
|
28 |
+
|
29 |
+
def send_request(password, username):
|
30 |
+
try:
|
31 |
+
response = requests.post('https://girlschat.org/chat/system/encoded/login.php', data={
|
32 |
+
'password': password,
|
33 |
+
'username': username
|
34 |
+
})
|
35 |
+
|
36 |
+
return response.text.strip() # Return the response text from the external system
|
37 |
+
|
38 |
+
except requests.exceptions.RequestException as e:
|
39 |
+
print(f"Error: {e}")
|
40 |
+
return '0' # Return '0' or handle error as per your application's requirements
|
41 |
+
|
42 |
+
if __name__ == '__main__':
|
|
|
43 |
app.run(host='0.0.0.0', port=8000)
|