import random import string from website.app import create_app from website.models import Client, db app = create_app() app.app_context().push() app_name = "" app_description = "" client_id = "" confidential = "" redirect_uris = "" while not app_name: app_name = input("Application name (ie. Printmaster): ").strip() while not app_description: app_description = input("Application description (ie. Print control software): ").strip() while not client_id: client_id = input("OAuth Client ID (ie. printmaster): ").strip() while not confidential: confidential = input("Is the client confidential? Say yes for web apps, no for mobile apps: [yn] ").strip() while not redirect_uris: redirect_uris = input("Whitespace-delimited redirect URIs: ").strip() if confidential.lower().startswith('y'): confidential = True else: confidential = False print("\n\nSummary\n-------") print("Application name:", app_name) print("Application description:", app_description) print("Client ID:", client_id) print("Confidential client:", confidential) print("Redirect URIs:", redirect_uris) while input("Type YES to continue. ") != "YES": pass c = Client() c.name = app_name c.description = app_description c.client_id = client_id c.client_secret = ''.join([random.choice("0123456789abcdef") for _ in range(32)]) c.is_confidential = confidential c.redirect_uris_ = redirect_uris db.session.add(c) db.session.commit() print("Client secret:", c.client_secret)