asv7j commited on
Commit
fb9a22f
·
verified ·
1 Parent(s): f68c539

Update app.py

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