def _do_contact(self): name = request.POST.get('name') email = request.POST.get('email') message = request.POST.get('message') self._send_message(name, email, message) h.flash(u'Thank you for contacting us') redirect_to(h.url_for('home'))
def register(self): c.no_maps = True if request.environ.get('repoze.who.identity') == None: c.active_section = request.params.get('show','login-new') c.captcha_html = h.literal(recaptcha.client.captcha.displayhtml( g.captcha_pubkey)) return render('/user/login.mako') h.flash(u'Can\'t register while logged in. Please logout first.') redirect_to(h.url_for('home'))
def _do_edit(self, almanac_slug, page_slug): c.almanac = h.get_almanac_by_slug(almanac_slug) c.page = h.get_page_by_slug(c.almanac, page_slug) name = request.POST.get('name', u'') if name: # all we have to save is the name here for now c.page.name = name meta.Session.commit() h.flash(u'Page edited') redirect_to(h.url_for('page_view', almanac=c.almanac, page=c.page))
def _do_publish(self, almanac_slug): c.almanac = almanac = h.get_almanac_by_slug(almanac_slug) name = request.POST.get('name', u'') if not name: name = u'Unnamed' slug = Page.name_page(almanac, name) page = c.almanac.new_page(self.ensure_user, name=name, slug=slug) page.published = True meta.Session.commit() h.flash(u'Page created') redirect_to(h.url_for('page_view', almanac=almanac, page=page))
def _do_comment(self, almanac_slug, page_slug): almanac = h.get_almanac_by_slug(almanac_slug) page = h.get_page_by_slug(almanac, page_slug) comment = Comment(fullname=self.form_result['fullname'], email=self.form_result['email'], website=self.form_result['website'], text=self.form_result['text'], ) comment.page_id = page.id meta.Session.add(comment) meta.Session.commit() h.flash(u'Comment added') redirect_to(h.url_for('page_view', almanac=almanac, page=page))
def _request_reset(self): login = self.form_result['login'] try: user = meta.Session.query(FullUser).filter(or_(FullUser.username==login, FullUser.email_address==login)).one() except (orm.exc.NoResultFound, orm.exc.MultipleResultsFound): h.flash("Unable to find the username or email supplied.") redirect_to(h.url_for('home')) user.generate_key() meta.Session.commit() c.username = user.username c.key = user.reset_key message = mailer.Message() message.From = "Community Alamanc <noreply@%s>" % "communityalmanac.org" message.To = user.email_address message.Subject = "Community Almanac account details" message.Body, message.Html = self._email_strip(render('/email/account_details.mako'), message) server = mailer.Mailer(config['smtp_server']) server.send(message) h.flash(u'A password reset has been sent. Please check your email.') redirect_to(h.url_for('home'))
def _perform_reset(self, username, key): myparams = dict(request.params) myparams['username'] = username myparams['key'] = key schema = PerformResetSchema() try: form_result = schema.to_python(myparams) except validators.Invalid, error: c.form_result = error.value c.form_errors = error.error_dict or {} return render('/user/perform_reset.mako') password = form_result['password'] try: user = meta.Session.query(FullUser).filter(and_(FullUser.username==username, FullUser.reset_key==key)).one() except (orm.exc.NoResultFound, orm.exc.MultipleResultsFound): h.flash("Invalid reset key.") redirect_to(h.url_for('home')) user.reset_key = None if password: user.set_password(password) meta.Session.commit() self._login(username) h.flash(u'Your password has been reset') redirect_to(h.url_for('home')) def test(self): if request.environ.get('repoze.who.identity') == None: abort(401) return 'Success'