def send_recover_mail(self): '''Creates a slug to identify the user and sends a mail to the given address to enable resetting the password. ''' controls = self.request.POST.items() try: appstruct = send_mail_form().validate(controls) except d.ValidationFailure as e: return dict(pagetitle=self.tr(self.PASSWORD_TITLE), email_form=e.render()) '''Form validation passes, so create a slug and the url and send an email to the user to enable him to reset his password.''' email = appstruct['email'] user = sas.query(User).filter(User.email == email).first() # Create the slug to identify the user and save it in the db si = SlugIdentification.create_unique_slug(user) sas.add(si) sas.flush() # Create the url and send it to the user slug = si.user_slug password_link = self.url('reset_password', action='recover', slug=slug) settings = self.request.registry.settings sender = settings.get('mail.message.author','*****@*****.**') appname = settings.get('app.name', 'Mootiro') recipient = email subject = appname + ' - ' + _("Change password") message = _("To set a new password please click on the link: ") msg = Message(sender, recipient, self.tr(subject)) msg.plain = self.tr(message) + password_link msg.send() return dict(pagetitle=self.tr(self.PASSWORD_TITLE), email_form=None)