Skip to content

Commit

Permalink
task 2
Browse files Browse the repository at this point in the history
  • Loading branch information
dhrumilp12 committed Jun 3, 2024
1 parent e6d703d commit c12dda4
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 1 deletion.
7 changes: 6 additions & 1 deletion server/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,23 @@

from flask import Flask
from flask_cors import CORS
from flask_jwt_extended import JWTManager

from routes.user import user_routes
from routes.user import user_routes
from routes.ai import ai_routes


# Set up the app
app = Flask(__name__)
app.config['JWT_SECRET_KEY'] = 't54WKRE5t5UaZnEWDvUd75Qe5ilYAKKe9n8tbUGv3_Q'
jwt = JWTManager(app)
CORS(app)

# Register routes
app.register_blueprint(user_routes)
app.register_blueprint(ai_routes)


# Base endpoint
@app.get("/")
def root():
Expand Down
Binary file modified server/requirements.txt
Binary file not shown.
17 changes: 17 additions & 0 deletions server/routes/user.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import logging

from flask import Blueprint, request, jsonify
from flask_jwt_extended import create_access_token

from werkzeug.security import generate_password_hash
from models.user import User as UserModel
Expand Down Expand Up @@ -39,3 +40,19 @@ def signup():
except Exception as e:
logging.error(f"Exception during time_registration: {str(e)}")
return jsonify({"error": str(e)}), 400

@user_routes.post('/anonymous_signin')
def anonymous_signin():
try:
# Set a reasonable expiration time for tokens, e.g., 24 hours
#expires = timedelta(hours=24)

identity = {'anonymous': True}
access_token = create_access_token(identity=identity, expires_delta=False) # Token never expires; adjust as needed
logging.info("create access token successful")
return jsonify(access_token=access_token), 200

except Exception as e:
# Log the error and return an appropriate error message
logging.error(f"Failed to create access token: {str(e)}")
return jsonify({"msg": "Failed to create access token"}), 500

0 comments on commit c12dda4

Please sign in to comment.