def process_form(self, wtf, **kwargs): # # this is where any database processing would happen # msg.flash("Got it! string={}, integer={}, etc.".format( wtf.s.data, wtf.i.data)) return msg.success("All good.", return_def="page_example_about")
def login(): error = None if request.method == 'POST': this_user = database.check_login(request.form, bcrypt) if msg.is_good(this_user): login_user(this_user) msg.flash('Welcome, {}'.format(this_user.s_name)) return redirect(url_for('index')) else: msg.flash(this_user) return redirect(url_for('login')) return render_template('login.html', error=error)
def page_handler(page, source_def, key, **kwargs): if msg.is_bad(page.status): msg.flash(page.status) return redirect(url_for('index')) if page.admin_required: if not g.admin_flag: msg.flash('You must be an administrator.', t="warning", log_level=logging.WARNING) return redirect(url_for('index')) if page.login_required: if not current_user.is_authenticated: msg.flash('You must be logged in.', t="warning", log_level=logging.INFO) return redirect(url_for('index')) # # handle purposeful bypass # if hasattr(page, "fondum_bypass"): return page.fondum_bypass(**kwargs) # # form handling # if page.wtf: if page.wtf.is_submitted(): if page.wtf.validate_on_submit(): if not hasattr(page.wtf, "process_form"): msg.flash('FONDUM error: no process_form method found', t="bug") return redirect(url_for(source_def)) result = page.wtf.process_form(page.wtf, **kwargs) if isinstance(result, Response): return result msg.flash(result) if result.return_def: if result.return_def_parms: return redirect( url_for(result.return_def, **result.return_def_parms)) return redirect(url_for(result.return_def)) return redirect(url_for(source_def, **kwargs)) else: if hasattr(page.wtf, 'set_field_values'): result = page.wtf.set_field_values(False, **kwargs) if msg.is_msg(result): msg.flash(result) if result.return_def: if result.return_def_parms: return redirect( url_for(result.return_def, **result.return_def_parms)) return redirect(url_for(result.return_def)) else: if hasattr(page.wtf, 'set_field_values'): result = page.wtf.set_field_values(True, **kwargs) if msg.is_msg(result): msg.flash(result) if result.return_def: if result.return_def_parms: return redirect( url_for(result.return_def, **result.return_def_parms)) return redirect(url_for(result.return_def)) # # generate html # article = database.read_article_byKey(key) html = parsing.generate_html(article, page) # # # logger.debug("Served Page /{}/".format(key)) return render_template('page.html', page=page, key=key, html=html)
def google_authorized(resp, est): if resp is None: msg.flash( 'Access denied: reason=%s error=%s' % (request.args['error_reason'], request.args['error_description'])) return redirect(url_for('index')) if str(type(resp)) == "<class 'flask_oauthlib.client.OAuthException'>": msg.flash('Access denied: desc=%s error=%s' % (resp.data['error_description'], resp.data['error'])) return redirect(url_for('index')) session['google_token'] = (resp['access_token'], '') person = google.get('userinfo') # person.data = { # u'family_name': last_name, # u'name': full_name, # u'picture': url, # u'gender': u'male' or u'female', # u'email': email_addr, # u'link': google_plus_url, # u'given_name': first_name, # u'id': u'101149719268028298009', # u'hd': domain_name, # u'verified_email': True } session.pop('_flashes', None) email = person.data[u'email'] authid = person.data[u'id'] # picture_url = person.data[u'picture'] if est == "new": user = database.create_user_byOAuth(email, authid, "google") if msg.is_bad(user): msg.flash(user) return redirect(url_for('index')) account = account__database.create_account(user, person.data[u'name']) if msg.is_bad(account): msg.flash(account) return redirect(url_for('index')) login_user(user) msg.flash( msg.success( 'Welcome, your name has been determined to be <b>{}</b>'. format(account.s_name), return_def="index")) return redirect(url_for('index')) user = database.read_user_byOAuth(email, authid, "google") if msg.is_bad(user): msg.flash(user) return redirect(url_for('index')) login_user(user) msg.flash(msg.success('Welcome back.', return_def="index")) return redirect(url_for('index'))
def fondum_bypass(self, **kwargs): doc_id = kwargs["id"] response = delete_testDocument(doc_id) msg.flash(response) return redirect("/example/copy-fields/")