Ejemplo n.º 1
0
 def reset(self, id):
     c.page_user = get_entity_or_abort(model.User,
                                       id,
                                       instance_filter=False)
     try:
         if c.page_user.reset_code != self.form_result.get('c'):
             raise ValueError()
         new_password = random_token()
         c.page_user.password = new_password
         model.meta.Session.add(c.page_user)
         model.meta.Session.commit()
         body = (
             _("your password has been reset. It is now:") + "\r\n\r\n  " +
             new_password + "\r\n\r\n" +
             _("Please login and change the password in your user "
               "settings.") + "\n\n" +
             _("Your user name to login is: %s") % c.page_user.user_name)
         libmail.to_user(c.page_user, _("Your new password"), body)
         h.flash(
             _("Success. You have been sent an email with your new "
               "password."), 'success')
     except Exception:
         h.flash(
             _("The reset code is invalid. Please repeat the password"
               " recovery procedure."), 'error')
     redirect('/login')
Ejemplo n.º 2
0
def user_import(_users,
                email_subject,
                email_template,
                creator,
                instance,
                reinvite=False):
    names = []
    created = []
    mailed = []
    errors = False
    users = []
    for user_info in _users:
        try:
            name = user_info['user_name']
            email = user_info['email']

            try:
                display_name = user_info['display_name']
                names.append(name)
                if reinvite:
                    user = model.User.find(name)
                else:
                    user = model.User.create(name,
                                             email,
                                             display_name=display_name,
                                             autojoin=False)
                    user.activation_code = user.IMPORT_MARKER + random_token()
                password = random_token()
                user_info['password'] = password
                user.password = password

                for badge in user_info['user_badges']:
                    badge.assign(user, creator=creator)

                model.meta.Session.add(user)
                model.meta.Session.commit()
                users.append(user)
                created.append(user.user_name)
                url = base_url("/user/%s/activate?c=%s" %
                               (user.user_name, user.activation_code),
                               instance=instance,
                               absolute=True)

                user_info['url'] = url
                body = email_template.format(*user_info.get('rest', []),
                                             **user_info)
                to_user(user, email_subject, body, decorate_body=False)
                mailed.append(user.user_name)

            except Exception, E:
                log.error('user import for user %s, email %s, exception %s' %
                          (user_info['user_name'], user_info['email'], E))
                errors = True
                continue
        except Exception, E:
            log.error('user import invalid user exception %s' % E)
            errors = True
            continue
Ejemplo n.º 3
0
def user_import(_users, email_subject, email_template, creator, instance,
                reinvite=False):
    names = []
    created = []
    mailed = []
    errors = False
    users = []
    for user_info in _users:
        try:
            name = user_info['user_name']
            email = user_info['email']

            try:
                display_name = user_info['display_name']
                names.append(name)
                if reinvite:
                    user = model.User.find(name)
                else:
                    user = model.User.create(name, email,
                                             display_name=display_name,
                                             autojoin=False)
                    user.activation_code = user.IMPORT_MARKER + random_token()
                password = random_token()
                user_info['password'] = password
                user.password = password

                for badge in user_info['user_badges']:
                    badge.assign(user, creator=creator)

                model.meta.Session.add(user)
                model.meta.Session.commit()
                users.append(user)
                created.append(user.user_name)
                url = base_url(
                    "/user/%s/activate?c=%s" % (user.user_name,
                                                user.activation_code),
                    instance=instance,
                    absolute=True)

                user_info['url'] = url
                body = email_template.format(*user_info.get('rest', []),
                                             **user_info)
                to_user(user, email_subject, body, decorate_body=False)
                mailed.append(user.user_name)

            except Exception, E:
                log.error('user import for user %s, email %s, exception %s' %
                          (user_info['user_name'], user_info['email'], E))
                errors = True
                continue
        except Exception, E:
            log.error('user import invalid user exception %s' % E)
            errors = True
            continue
Ejemplo n.º 4
0
def _send(message,
          force_resend=False,
          massmessage=True,
          email_subject_format=None,
          email_body_template=None):
    from adhocracy.model import Notification
    from adhocracy.lib import mail, event

    if massmessage:
        event_type = event.T_MASSMESSAGE_SEND
    else:
        event_type = event.T_MESSAGE_SEND

    e = event.emit(event_type,
                   message.creator,
                   instance=message.instance,
                   message=message,
                   sender=message.creator)
    notification = Notification(e, message.creator)
    meta.Session.add(notification)

    for r in message.recipients:
        if force_resend or not r.email_sent:
            if (r.recipient.is_email_activated()
                    and r.recipient.email_messages):

                body = render_body(message.body, r.recipient)

                mail.to_user(r.recipient,
                             email_subject(message, r.recipient,
                                           email_subject_format),
                             email_body(message,
                                        r.recipient,
                                        body,
                                        email_body_template,
                                        massmessage=massmessage),
                             headers={},
                             decorate_body=False,
                             email_from=message.email_from,
                             name_from=message.name_from)

            # creator already got a notification
            if r.recipient != message.creator:
                notification = Notification(e,
                                            r.recipient,
                                            type=event.N_MESSAGE_RECEIVE)
                meta.Session.add(notification)

            r.email_sent = True

    meta.Session.commit()
Ejemplo n.º 5
0
class MessageController(BaseController):
    def new(self, id, format='html', errors={}):
        c.page_user = get_entity_or_abort(model.User, id)
        require.user.message(c.page_user)
        html = render("/message/new.html", overlay=format == u'overlay')
        return htmlfill.render(html,
                               defaults=request.params,
                               errors=errors,
                               force_defaults=False)

    def create(self, id, format='html'):
        c.page_user = get_entity_or_abort(model.User, id)
        require.user.message(c.page_user)
        try:
            self.form_result = MessageCreateForm().to_python(request.params)
        except Invalid, i:
            return self.new(id, errors=i.unpack_errors())

        c.body = self.form_result.get('body')
        c.subject = self.form_result.get('subject')
        message = render("/message/body.txt")
        headers = {}
        if c.user.is_email_activated():
            headers['Reply-To'] = c.user.email

        from adhocracy.lib.mail import to_user
        label = h.site.name() if c.instance is None else c.instance.label
        subject = _("[%s] Message from %s: %s") % (label, c.user.name,
                                                   c.subject)
        to_user(c.page_user, subject, message, headers=headers)

        h.flash(_("Your message has been sent. Thanks."), 'success')
        redirect(h.entity_url(c.page_user, instance=c.instance))
Ejemplo n.º 6
0
 def reset_request(self):
     c.page_user = model.User.find_by_email(self.form_result.get('email'))
     if c.page_user is None:
         msg = _("There is no user registered with that email address.")
         return htmlfill.render(self.reset_form(), errors=dict(email=msg))
     c.page_user.reset_code = random_token()
     model.meta.Session.add(c.page_user)
     model.meta.Session.commit()
     url = h.base_url(c.instance,
                      path="/user/%s/reset?c=%s" % (c.page_user.user_name,
                                                    c.page_user.reset_code))
     body = _("you have requested that your password be reset. In order "
              "to confirm the validity of your claim, please open the "
              "link below in your browser:") + "\r\n\r\n  " + url
     libmail.to_user(c.page_user, _("Reset your password"), body)
     return render("/user/reset_pending.html")
Ejemplo n.º 7
0
 def reset_request(self):
     c.page_user = model.User.find_by_email(self.form_result.get('email'))
     if c.page_user is None:
         msg = _("There is no user registered with that email address.")
         return htmlfill.render(self.reset_form(), errors=dict(email=msg))
     c.page_user.reset_code = random_token()
     model.meta.Session.add(c.page_user)
     model.meta.Session.commit()
     url = h.base_url(c.instance,
                      path="/user/%s/reset?c=%s" %
                      (c.page_user.user_name, c.page_user.reset_code))
     body = _("you have requested that your password be reset. In order "
              "to confirm the validity of your claim, please open the "
              "link below in your browser:") + "\r\n\r\n  " + url
     libmail.to_user(c.page_user, _("Reset your password"), body)
     return render("/user/reset_pending.html")
Ejemplo n.º 8
0
def mail_sink(pipeline):
    for notification in pipeline:
        if notification.user.is_email_activated() and \
            notification.priority >= notification.user.email_priority:
            notification.language_context()
            headers = {'X-Notification-Id': notification.id,
                       'X-Notification-Priority': str(notification.priority)}

            log.debug("mail to %s: %s" % (notification.user.email,
                                          notification.subject))
            mail.to_user(notification.user,
                     notification.subject,
                     notification.body,
                     headers=headers)

        else:
            yield notification
Ejemplo n.º 9
0
    def _create_users(self, form_result, format='html'):
        names = []
        created = []
        mailed = []
        errors = False
        users = []
        for user_info in form_result['users_csv']:
            try:
                name = user_info['user_name']
                email = user_info['email']
                display_name = user_info['display_name']
                names.append(name)
                user = model.User.create(name,
                                         email,
                                         display_name=display_name,
                                         autojoin=False)
                user.activation_code = user.IMPORT_MARKER + random_token()
                password = random_token()
                user_info['password'] = password
                user.password = password

                for badge in user_info['user_badges']:
                    badge.assign(user, creator=c.user)

                model.meta.Session.add(user)
                model.meta.Session.commit()
                users.append(user)
                created.append(user.user_name)
                url = base_url("/user/%s/activate?c=%s" %
                               (user.user_name, user.activation_code),
                               absolute=True)

                user_info['url'] = url
                body = form_result['email_template'].format(
                    *user_info.get('rest', []), **user_info)
                to_user(user,
                        form_result['email_subject'],
                        body,
                        decorate_body=False)
                mailed.append(user.user_name)

            except Exception, E:
                log.error('user import for user %s, email %s, exception %s' %
                          (name, email, E))
                errors = True
                continue
Ejemplo n.º 10
0
    def _create_users(self, form_result):
        names = []
        created = []
        mailed = []
        errors = False
        users = []
        for user_info in form_result['users_csv']:
            try:
                name = user_info['user_name']
                email = user_info['email']
                display_name = user_info['display_name']
                names.append(name)
                user = model.User.create(name,
                                         email,
                                         display_name=display_name)
                user.activation_code = user.IMPORT_MARKER + random_token()
                password = random_token()
                user_info['password'] = password
                user.password = password
                model.meta.Session.add(user)
                model.meta.Session.commit()
                users.append(user)
                created.append(user.user_name)
                url = base_url(c.instance,
                               path="/user/%s/activate?c=%s" %
                               (user.user_name, user.activation_code))

                user_info['url'] = url
                body = form_result['email_template'].format(**user_info)
                to_user(user,
                        form_result['email_subject'],
                        body,
                        decorate_body=False)
                mailed.append(user.user_name)
                if c.instance:
                    membership = model.Membership(user, c.instance,
                                                  c.instance.default_group)
                    model.meta.Session.expunge(membership)
                    model.meta.Session.add(membership)
                    model.meta.Session.commit()

            except Exception, E:
                log.error('user import for user %s, email %s, exception %s' %
                          (name, email, E))
                errors = True
                continue
Ejemplo n.º 11
0
    def notify(self, force_resend=False):

        if (self.recipient.is_email_activated()
                and self.recipient.email_messages):

            from adhocracy.lib import mail
            from adhocracy.lib.message import render_body

            body = render_body(self.message.body, self.recipient,
                               self.message.include_footer)

            mail.to_user(self.recipient,
                         self.message.subject,
                         body,
                         headers={},
                         decorate_body=False,
                         email_from=self.message.sender_email,
                         name_from=self.message.sender_name)
Ejemplo n.º 12
0
    def _create_users(self, form_result):
        names = []
        created = []
        mailed = []
        errors = False
        users = []
        for user_info in form_result['users_csv']:
            try:
                name = user_info['user_name']
                email = user_info['email']
                display_name = user_info['display_name']
                names.append(name)
                user = model.User.create(name, email,
                                         display_name=display_name)
                user.activation_code = user.IMPORT_MARKER + random_token()
                password = random_token()
                user_info['password'] = password
                user.password = password
                model.meta.Session.add(user)
                model.meta.Session.commit()
                users.append(user)
                created.append(user.user_name)
                url = base_url(c.instance,
                               path="/user/%s/activate?c=%s" % (
                                   user.user_name,
                                   user.activation_code))

                user_info['url'] = url
                body = form_result['email_template'].format(**user_info)
                to_user(user, form_result['email_subject'], body,
                        decorate_body=False)
                mailed.append(user.user_name)
                if c.instance:
                    membership = model.Membership(user, c.instance,
                                                  c.instance.default_group)
                    model.meta.Session.expunge(membership)
                    model.meta.Session.add(membership)
                    model.meta.Session.commit()

            except Exception, E:
                log.error('user import for user %s, email %s, exception %s' %
                          (name, email, E))
                errors = True
                continue
Ejemplo n.º 13
0
def _send(message, force_resend=False, massmessage=True,
          email_subject_format=None, email_body_template=None):
    from adhocracy.model import Notification
    from adhocracy.lib import mail, event

    if massmessage:
        event_type = event.T_MASSMESSAGE_SEND
    else:
        event_type = event.T_MESSAGE_SEND

    e = event.emit(event_type, message.creator, instance=message.instance,
                   message=message,
                   sender=message.creator)
    notification = Notification(e, message.creator)
    meta.Session.add(notification)

    for r in message.recipients:
        if force_resend or not r.email_sent:
            if (r.recipient.is_email_activated() and
                    r.recipient.email_messages):

                body = render_body(message.body, r.recipient)

                mail.to_user(r.recipient,
                             email_subject(message, r.recipient,
                                           email_subject_format),
                             email_body(message, r.recipient, body,
                                        email_body_template,
                                        massmessage=massmessage),
                             headers={},
                             decorate_body=False,
                             email_from=message.email_from,
                             name_from=message.name_from)

            # creator already got a notification
            if r.recipient != message.creator:
                notification = Notification(e, r.recipient,
                                            type=event.N_MESSAGE_RECEIVE)
                meta.Session.add(notification)

            r.email_sent = True

    meta.Session.commit()
Ejemplo n.º 14
0
Archivo: sinks.py Proyecto: alkadis/vcv
def mail_sink(pipeline):
    for notification in pipeline:
        if notification.user.is_email_activated() and \
                notification.priority >= notification.user.email_priority:
            notification.language_context()
            headers = {
                'X-Notification-Id': notification.get_id(),
                'X-Notification-Priority': str(notification.priority)
            }

            log.debug("mail to %s: %s" %
                      (notification.user.email, notification.subject))
            mail.to_user(notification.user,
                         notification.subject,
                         notification.body,
                         headers=headers)

        else:
            yield notification
Ejemplo n.º 15
0
 def reset(self, id):
     c.page_user = get_entity_or_abort(model.User, id,
                                       instance_filter=False)
     try:
         if c.page_user.reset_code != self.form_result.get('c'):
             raise ValueError()
         new_password = random_token()
         c.page_user.password = new_password
         model.meta.Session.add(c.page_user)
         model.meta.Session.commit()
         body = (_("your password has been reset. It is now:") +
                 "\r\n\r\n  " + new_password + "\r\n\r\n" +
                 _("Please login and change the password in your user "
                   "settings."))
         libmail.to_user(c.page_user, _("Your new password"), body)
         h.flash(_("Success. You have been sent an email with your new "
                   "password."), 'success')
     except Exception:
         h.flash(_("The reset code is invalid. Please repeat the password"
                   " recovery procedure."), 'error')
     redirect('/login')
Ejemplo n.º 16
0
    def notify(self, force_resend=False):

        if (self.recipient.is_email_activated() and
           self.recipient.email_messages):

            from adhocracy.lib import helpers as h
            from adhocracy.lib import mail
            from adhocracy.lib.templating import render

            body = render("/massmessage/body.txt", {
                'body': self.message.render_body(self.recipient),
                'page_url': config.get('adhocracy.domain').strip(),
                'settings_url': h.entity_url(self.recipient,
                                             member='edit',
                                             absolute=True),
            })

            mail.to_user(self.recipient,
                         self.message.subject,
                         body,
                         headers={},
                         decorate_body=False,
                         email_from=self.message.sender_email)