Exemplo n.º 1
0
    def pswrecovery(self):
        if hasattr(self, 'form_result'):
            email = self.form_result.get('email', None)
            # TODO: this needs to be resolved, get_global is wrong here:
            user = User.get_global(email)
            if user is not None:
                if not user.recovery_key:
                    user.gen_recovery_key()
                email_password_reset(user)
                meta.Session.commit()
                h.flash(_('Password recovery email sent. Please check your inbox.'))
            else:
                h.flash(_('User account not found.'))

        return htmlfill.render(self._pswrecovery_form())
Exemplo n.º 2
0
    def fromMessageText(cls, message_text, force=False):
        message = cls.parseMessage(message_text)
        message_id = message.getMessageId()
        g = message.getGroup()

        #use the numerical group id
        if g is None:
            return

        group_id = g.id

        if cls.get(message_id, group_id):
            raise MessageAlreadyExists(message_id, group_id)

        mime_message = mimetools.Message(StringIO(message_text))
        author_name, author_address = parseaddr(mime_message['From'])
        author = User.get_global(author_address)
        in_moderation_queue = False

        whitelist = [i.email for i in g.whitelist] + [
            config.get('ututi_email_from', '*****@*****.**')]
        if not (author_address in whitelist or
                author is not None and g.is_member(author)
                or force):
            if g.mailinglist_moderated:
                in_moderation_queue = True
            else:
                return # Bounce

        reply_to_message_id = message.getHeader('in-reply-to')
        reply_to = cls.get(reply_to_message_id, group_id)

        # XXX Hacky way to find messages this message might be a reply to
        if not reply_to:
            sbj = message.getSubject()
            parts = sbj.split(':')
            if len(parts) > 1:
                real_sbj = parts[-1].strip()
                reply_to = meta.Session.query(cls).filter_by(subject=real_sbj,
                                                             group_id=group_id).first()
        return cls(message_text,
                   message_id,
                   group_id,
                   message.getSubject(),
                   message.getDate(),
                   reply_to,
                   in_moderation_queue)
Exemplo n.º 3
0
def prepare_logo(obj_type, obj_id, width=None, height=None, default_img_path=None, square=False):
    obj = None
    if obj_id is not None:
        if obj_type == 'user':
            obj = User.get_global(obj_id)
        else:
            obj_types = {
                'group': Group,
                'locationtag': LocationTag,
                'registration': UserRegistration,
                'theme': Theme,
            }
            obj_cls = obj_types[obj_type]
            obj = obj_cls.get(obj_id)

    if obj is not None and obj.has_logo():
        return prepare_image(obj.logo, width, height, square)
    elif default_img_path is not None:
        stream = resource_stream("ututi", default_img_path).read()
        return prepare_image(stream, width, height, square)
    else:
        return None
Exemplo n.º 4
0
 def getAuthor(self):
     author_name, author_address = parseaddr(self.getHeader("from"))
     return User.get_global(author_address)
Exemplo n.º 5
0
 def getAuthor(self):
     author_name, author_address = parseaddr(self.mime_message['From'])
     return User.get_global(author_address)