diff --git a/api.py b/api.py index 3fc4902..d8c9254 100644 --- a/api.py +++ b/api.py @@ -43,6 +43,7 @@ def __init__(self, facebook_auth_filename=SECRETS_FILENAME): self.authed = False self.profiles = None self.friends = set() + def _load_fb_auth(self): diff --git a/app.py b/app.py index 4e31ba5..be48a6d 100644 --- a/app.py +++ b/app.py @@ -1,18 +1,48 @@ - - -from flask import Flask, render_template +from flask import Flask, render_template, request, g import api app = Flask('tinder-detective') -stalker = api.NSASimulator() - @app.route('/') def index(): - profiles = stalker.get_profiles() - return render_template("main.html", profiles=profiles) + + stalker = getattr(g, 'stalker', None) + + if stalker is None: + try: + stalker = api.NSASimulator() + except api.AuthenticationError: + return render_template("create_secrets.html") + + g.stalker = stalker + + error = None + profiles = None + try: + profiles = stalker.get_profiles() + except api.AuthenticationError: + print("Auth error") + error = "There was a problem with authentication" + return render_template("profiles.html", profiles=profiles, error=error) + + +@app.route('/create_secret', methods=['POST']) +def create_secret(): + data = request.form + + user_id = data['user_id'] + user_secret = data['user_secret'] + + with open('SECRETS.json', 'w') as f: + f.write("{\n") + f.write(" \"facebook_id\": \"" + user_id + "\",\n") + f.write(" \"facebook_token\": \"" + user_secret + "\"") + f.write("\n") + f.write("}") + + return "Successfully wrote to file, please reload the main page" if __name__ == '__main__': - app.run(debug=True) + app.run(debug=False, port=8080) diff --git a/templates/base.html b/templates/base.html new file mode 100644 index 0000000..2c1eb62 --- /dev/null +++ b/templates/base.html @@ -0,0 +1,27 @@ + + +
+ + + + + + + +