def service_login(service_name, next=''): if request.method == 'POST': account_class = get_service_class(service_name) account = account_class(request.form['username']) account.login(request.form['password']) g.account.services[service_name] = account g.account.save() flash("You were logged in with %s as '%s'." % (service_name, request.form['username'])) if next: redirect(next) return redirect(url_for('index')) return render_template( 'service_login.html', title=("Login to %s" % service_name) )
def _get_service_class_safe(service_name, message="Choose the service for this command:"): if service_name is None: app.logger.info(message) service_classes = list(get_service_classes()) for i, c in enumerate(service_classes): if i == 0: app.logger.message(" - [%d] %s [default]" % (i+1, c.service_name)) else: app.logger.message(" - [%d] %s" % (i+1, c.service_name)) choice = _prompt_index('service', max_val=len(service_classes)+1) service_name = service_classes[choice-1].service_name try: return get_service_class(service_name) except: raise Exception("No such service: %s" % service_name)