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

Upload 4 files

Browse files
Files changed (3) hide show
  1. DockerFile +10 -9
  2. app.py +44 -54
  3. templates/index.html +1 -1
DockerFile CHANGED
@@ -1,9 +1,10 @@
1
- FROM python:3.9
2
-
3
- WORKDIR /code
4
-
5
- RUN pip install fastapi requests uvicorn[standard]==0.17.*
6
-
7
- COPY . .
8
-
9
- CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]
 
 
1
+ FROM python:3.9
2
+
3
+ WORKDIR /python-docker
4
+
5
+ COPY requirements.txt requirements.txt
6
+ RUN pip3 install -r requirements.txt
7
+
8
+ COPY . .
9
+
10
+ CMD [ "python3", "-m" , "flask", "run", "--host=0.0.0.0"]
app.py CHANGED
@@ -1,54 +1,44 @@
1
- from fastapi import FastAPI, HTTPException, Form
2
- from fastapi.middleware.cors import CORSMiddleware
3
- import requests
4
-
5
- app = FastAPI()
6
-
7
- # CORS middleware to allow cross-origin requests
8
- app.add_middleware(
9
- CORSMiddleware,
10
- allow_origins=["*"], # Adjust this according to your frontend's origin
11
- allow_credentials=True,
12
- allow_methods=["POST"],
13
- allow_headers=["*"],
14
- )
15
-
16
- @app.get('/')
17
- def index():
18
- return {"message": "Welcome to FastAPI"}
19
-
20
- @app.post('/loginChat')
21
- def login_chat(username: str = Form(...), password: str = Form(...)):
22
- try:
23
- # Call send_request function to handle the HTTP POST request to external system
24
- response = send_request(password, username)
25
-
26
- # Process the response and return appropriate JSON response
27
- if response == '1':
28
- return {'response': 1, 'message': 'Login successful'}
29
- elif response == '2':
30
- return {'response': 2, 'message': 'Invalid username or password'}
31
- elif response == '3':
32
- return {'response': 3, 'message': 'Special action required (e.g., page reload)'}
33
- else:
34
- return {'response': 0, 'message': 'Unknown response from external system'}
35
-
36
- except Exception as e:
37
- raise HTTPException(status_code=500, detail=str(e))
38
-
39
- def send_request(password: str, username: str):
40
- try:
41
- response = requests.post('system/encoded/login.php', data={
42
- 'password': password,
43
- 'username': username
44
- })
45
-
46
- return response.text.strip() # Return the response text from the external system
47
-
48
- except requests.exceptions.RequestException as e:
49
- print(f"Error: {e}")
50
- return '0' # Return '0' or handle error as per your application's requirements
51
-
52
- if __name__ == '__main__':
53
- import uvicorn
54
- uvicorn.run(app, host="0.0.0.0", port=7860)
 
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)
 
 
 
 
 
 
 
 
 
 
templates/index.html CHANGED
@@ -51,7 +51,7 @@ sendLogin = function(){
51
  else {
52
  if(waitReply == 0){
53
  waitReply = 1;
54
- $.post('/loginChat', {
55
  password: upass,
56
  username: uuser
57
  }, function(response) {
 
51
  else {
52
  if(waitReply == 0){
53
  waitReply = 1;
54
+ $.post('/login', {
55
  password: upass,
56
  username: uuser
57
  }, function(response) {