def get_form(self): from forms import CreateArticle self.session = get_session(self.request) self.session['csrf'] = get_csrf_token(self.session) schema = CreateArticle().bind(request=self.request) submit = deform.Button(name='submit', css_class='blog-form__button') self.form = deform.Form(schema, buttons=(submit, )) return self.form
def get_form(self): from forms import CreateArticle self.session = get_session(self.request) self.session['csrf'] = get_csrf_token(self.session) schema = CreateArticle().bind(request=self.request) submit = deform.Button(name='submit', css_class='blog-form__button') self.form = deform.Form(schema, buttons=(submit,)) return self.form
def deferred_csrf_default(node, kw): request = kw.get('request') session = get_session(request) csrf_token = get_csrf_token(session) return csrf_token
def validate_csrf_token(node, value): request = kw.get('request') session = get_session(request) csrf_token = get_csrf_token(session) if value != csrf_token: raise colander.Invalid(node, 'Bad CSRF token')