def bunq_oauth_reauthorize(): """ Endpoint to reauthorize OAuth with bunq """ cookie = request.cookies.get('session') if cookie is None or cookie != util.get_session_cookie(): return render_template("message.html", msgtype="danger", msg=\ "Invalid request: session cookie not set or not valid") return auth.bunq_oauth_reauthorize()
def set_bunq_oauth_response(): """ Endpoint for the bunq OAuth response """ cookie = request.cookies.get('session') if cookie is None or cookie != util.get_session_cookie(): return render_template("message.html", msgtype="danger", msg=\ "Invalid request: session cookie not set or not valid") return auth.set_bunq_oauth_response()
def home_get(): """ Endpoint for the homepage """ cookie = request.cookies.get('session') if cookie is None or cookie != util.get_session_cookie(): return render_template("start.html") config = bunq.retrieve_config() bunqkeymode = config.get("mode") iftttkeyset = (util.get_ifttt_service_key("") is not None) accounts = util.get_bunq_accounts_with_permissions(config) enableexternal = util.get_external_payment_enabled() bunq_oauth = storage.get_value("bunq2IFTTT", "bunq_oauth") if bunq_oauth is not None and bunqkeymode != "APIkey": expire = arrow.get(bunq_oauth["timestamp"] + 90 * 24 * 3600) oauth_expiry = "{} ({})".format(expire.humanize(), expire.isoformat()) else: oauth_expiry = None # Google AppEngine does not provide fixed ip addresses defaultallips = (os.getenv("GAE_INSTANCE") is not None) return render_template("main.html",\ iftttkeyset=iftttkeyset, bunqkeymode=bunqkeymode, accounts=accounts,\ enableexternal=enableexternal, defaultallips=defaultallips,\ oauth_expiry=oauth_expiry)
def set_ifttt_service_key(): """ Endpoint for IFTTT service key submission """ cookie = request.cookies.get('session') if cookie is None or cookie != util.get_session_cookie(): return render_template("message.html", msgtype="danger", msg=\ "Invalid request: session cookie not set or not valid") return auth.set_ifttt_service_key()
def mode_master(): """ Endpoint to switch to master mode """ cookie = request.cookies.get('session') if cookie is None or cookie != util.get_session_cookie(): return render_template("message.html", msgtype="danger", msg=\ "Invalid request: session cookie not set or not valid") util.save_app_mode('master') return render_template("message.html", msgtype="success", msg=\ 'Master mode set<br><br>'\ '<a href="/">Click here to return home</a>')
def update_accounts(): """ Endpoint to update the list of bunq accounts """ cookie = request.cookies.get('session') if cookie is None or cookie != util.get_session_cookie(): return render_template("message.html", msgtype="danger", msg=\ "Invalid request: session cookie not set or not valid") util.update_bunq_accounts() return render_template("message.html", msgtype="success", msg=\ 'Account update completed<br><br>'\ '<a href="/">Click here to return home</a>')
def mode_slave(): """ Endpoint to switch to slave mode """ cookie = request.cookies.get('session') if cookie is None or cookie != util.get_session_cookie(): return render_template("message.html", msgtype="danger", msg=\ "Invalid request: session cookie not set or not valid") util.save_app_mode('slave') return render_template("message.html", msgtype="success", msg=\ 'Slave mode set<br><br>'\ '<a href="/">Click here to return home</a><br>'\ 'Please make sure to set the URL to the master instance!')
def account_change_draft(): """ Enable/disable an account for draft payments """ cookie = request.cookies.get('session') if cookie is None or cookie != util.get_session_cookie(): return render_template("message.html", msgtype="danger", msg=\ "Invalid request: session cookie not set or not valid") if util.change_account_enabled_local(request.args["iban"], "enableDraft", request.args["value"]): return render_template("message.html", msgtype="success", msg=\ 'Status changed<br><br>'\ '<a href="/">Click here to return home</a>') return render_template("message.html", msgtype="danger", msg=\ 'Something went wrong, please check the logs!<br><br>'\ '<a href="/">Click here to return home</a>')
def home_get(): """ Endpoint for the homepage """ cookie = request.cookies.get('session') if cookie is None or cookie != util.get_session_cookie(): return render_template("start.html") iftttkeyset = (util.get_ifttt_service_key() is not None) bunqkeymode = util.get_bunq_security_mode() accounts = util.get_bunq_accounts_combined() appmode = util.get_app_mode() masterurl = util.get_app_master_url() enableexternal = util.get_external_payment_enabled() # Google AppEngine does not provide fixed ip addresses defaultallips = (os.getenv("GAE_INSTANCE") is not None) return render_template("main.html",\ iftttkeyset=iftttkeyset, bunqkeymode=bunqkeymode, accounts=accounts,\ appmode=appmode, masterurl=masterurl, enableexternal=enableexternal,\ defaultallips=defaultallips)
def set_master_url(): """ Endpoint to set the master URL used in slave mode """ cookie = request.cookies.get('session') if cookie is None or cookie != util.get_session_cookie(): return render_template("message.html", msgtype="danger", msg=\ "Invalid request: session cookie not set or not valid") url = request.form["masterurl"] if not url.startswith("http://") and not url.startswith("https://"): return render_template("message.html", msgtype="danger", msg=\ 'Invalid URL, it doesnt start with http(s)://<br><br>'\ '<a href="/">Click here to return home</a><br>') if not url.endswith("/"): url += "/" util.save_app_master_url(url) return render_template("message.html", msgtype="success", msg=\ 'Master URL set<br><br>'\ '<a href="/">Click here to return home</a><br>')
def account_change_request(): """ Enable/disable an account for request triggers """ cookie = request.cookies.get('session') if cookie is None or cookie != util.get_session_cookie(): return render_template("message.html", msgtype="danger", msg=\ "Invalid request: session cookie not set or not valid") if util.get_bunq_security_mode() == "OAuth": return render_template("message.html", msgtype="danger", msg=\ 'Callbacks can only be set with an API key!<br><br>'\ '<a href="/">Click here to return home</a>') if util.change_account_enabled_callback(request.args["iban"], "enableRequest", request.args["value"]): return render_template("message.html", msgtype="success", msg=\ 'Status changed<br><br>'\ '<a href="/">Click here to return home</a>') return render_template("message.html", msgtype="danger", msg=\ 'Something went wrong, please check the logs!<br><br>'\ '<a href="/">Click here to return home</a>')