Esempio n. 1
0
    def go(self, comp):
        if not self.state:
            # step 1:
            # - ask the user to fill a registration form
            # - send him a confirmation email
            username = comp.call(RegistrationForm(self.app_title, self.custom_css))
            if username:
                confirmation = self._create_email_confirmation(username)
                confirmation.send_email(self.mail_sender)
                comp.call(confirmation)
        else:
            # step 2: the user confirms his email by clicking on the
            # confirmation link
            # - check the token (to avoid cheating)
            # - show a confirmation screen
            username, token = self.state

            confirmation = self._create_email_confirmation(username)
            if confirmation.confirm_email_address(token):
                log.debug(_("Registration successful for user %s") % username)
                comp.call(RegistrationConfirmation(self.app_title, self.custom_css), model="success")
            else:
                log.debug(_("Registration failure for user %s") % username)
                comp.call(RegistrationConfirmation(self.app_title, self.custom_css), model="failure")

            redirect_to("/kansha")
Esempio n. 2
0
def init_app__new_mail(self, url, comp, http_method, request):
    username, token = (url[1], url[2])
    get_user = lambda: UserManager.get_by_username(username)
    confirmation = self._services(
        forms.EmailConfirmation,
        self.app_title,
        self.app_banner,
        self.custom_css,
        get_user
    )
    if confirmation.confirm_email_address(token):
        log.debug(_('Change email success for user %s') % get_user().username)
        comp.becomes(self._services(
            forms.ChangeEmailConfirmation,
            self.app_title,
            self.app_banner,
            self.custom_css,
            request.application_url
        ),
            model='success'
        )
        confirmation.reset_token(token)
    else:
        log.debug(_('Change email failure for user %s') % get_user().username)
        comp.becomes(
            self._services(
                forms.ChangeEmailConfirmation,
                self.app_title,
                self.app_banner,
                self.custom_css,
                request.application_url
            ),
            model='failure'
        )
Esempio n. 3
0
 def load(self, file_id):
     log.debug("Load Image")
     package = pkg_resources.Requirement.parse('kansha')
     fname = pkg_resources.resource_filename(package, 'kansha/services/dummyassetsmanager/tie.jpg')
     with open(fname, 'r') as f:
         data = f.read()
     return data, {}
Esempio n. 4
0
 def load(self, file_id):
     log.debug("Load Image")
     package = pkg_resources.Requirement.parse('kansha')
     fname = pkg_resources.resource_filename(
         package, 'kansha/services/dummyassetsmanager/tie.jpg')
     with open(fname, 'r') as f:
         data = f.read()
     return data, {}
Esempio n. 5
0
    def send(self,
             subject,
             to,
             content,
             html_content=None,
             from_='',
             cc=[],
             bcc=[],
             type='plain',
             mpart_type='alternative'):
        """Sends an email

        In:
         - ``subject`` -- email subject
         - ``to`` -- list of recipients' emails
         - ``content`` --  email content
         - ``from_`` -- email sender adress
         - ``cc`` --  list of CC emails
         - ``bcc`` -- list of BCC emails
         - ``type`` --  email type ('plain' or 'html')
         - ``mpart_type`` -- email part type

        """
        from_ = from_ if from_ else self.default_sender
        # create the message envelop
        msg = MIMEMultipart(mpart_type)
        msg['Subject'] = subject
        msg['Date'] = formatdate(localtime=True)
        msg['From'] = from_
        msg['To'] = COMMASPACE.join(to)

        if cc:
            msg['Cc'] = COMMASPACE.join(cc)

        # attach the mail content
        charset = 'us-ascii'
        if isinstance(content, unicode):
            content = content.encode('UTF-8')
            charset = 'UTF-8'
        msg.attach(MIMEText(content, type, charset))
        if html_content:
            msg.attach(MIMEText(html_content, 'html', charset))

        # log
        log.info(
            '%s mail:\n  subject=%s\n  from=%s\n  to=%s\n  cc=%s\n  bcc=%s',
            'sending' if self.activated else 'ignoring', subject, from_, to,
            cc, bcc)
        log.debug('Mail content:\n' + content)

        # post the email to the SMTP server
        if self.activated:
            self._smtp_send(from_, to + cc + bcc, msg.as_string())
Esempio n. 6
0
 def __init__(self, config_filename, error, host, port, default_sender,
              activated):
     super(MailSender, self).__init__(config_filename, error)
     self.host = host
     self.port = port
     self.default_sender = default_sender
     self.activated = activated
     if self.activated:
         log.debug('The mail service will connect to %s on port %s' %
                   (self.host, self.port))
     else:
         log.warning('The mail service will drop all messages!')
Esempio n. 7
0
    def dump_cumulated(self, count=None):
        sorted_timings = sorted(self.data.timings.iteritems(),
                                key=operator.itemgetter(1), reverse=True)
        filtered_timings = sorted_timings[:count or len(sorted_timings)]

        log.debug('%d/%d slowest queries (%dms/%dms):',
                  len(filtered_timings),
                  len(sorted_timings),
                  sum(ms for (__, ms) in filtered_timings),
                  sum(ms for (__, ms) in sorted_timings))

        for (sql, ms) in filtered_timings:
            log.debug('  + %dms: %s', ms, sql[:100].replace('\n', '') + '...')
Esempio n. 8
0
    def dump_cumulated(self, count=None):
        sorted_timings = sorted(self.data.timings.iteritems(),
                                key=operator.itemgetter(1),
                                reverse=True)
        filtered_timings = sorted_timings[:count or len(sorted_timings)]

        log.debug('%d/%d slowest queries (%dms/%dms):', len(filtered_timings),
                  len(sorted_timings),
                  sum(ms for (__, ms) in filtered_timings),
                  sum(ms for (__, ms) in sorted_timings))

        for (sql, ms) in filtered_timings:
            log.debug('  + %dms: %s', ms, sql[:100].replace('\n', '') + '...')
Esempio n. 9
0
File: mail.py Progetto: bcroq/kansha
 def __init__(self, config_filename, error, host, port, default_sender, activated):
     super(MailSender, self).__init__(config_filename, error)
     self.host = host
     self.port = port
     self.default_sender = default_sender
     self.activated = activated
     if self.activated:
         log.debug(
             'The mail service will connect to %s on port %s' %
             (self.host, self.port)
         )
     else:
         log.warning('The mail service will drop all messages!')
Esempio n. 10
0
    def remove_member(self, username):
        """Remove member username from card member"""
        data_member = usermanager.UserManager.get_by_username(username)
        if not data_member:
            raise exceptions.KanshaException(_("User not found : %s" % username))

        log.debug('Removing %s from card %s' % (username, self.card.id))
        self.card.remove_member(data_member)
        for member in self.members:
            if member().username == username:
                self.members.remove(member)
                values = {'user_id': member().username, 'user': member().data.fullname, 'card': self.card.get_title()}
                self.action_log.add_history(security.get_user(), u'card_remove_member', values)
Esempio n. 11
0
 def remove_member(self, username):
     """Remove member username from card member"""
     data_member = usermanager.UserManager.get_by_username(username)
     if data_member:
         log.debug('Removing %s from card %s' % (username, self.id))
         data = self.data
         data.members.remove(data_member)
         for member in self.members:
             if member().username == username:
                 self.members.remove(member)
                 values = {'user_id': member().username, 'user': member().data.fullname, 'card': data.title}
                 notifications.add_history(self.column.board.data, data, security.get_user().data, u'card_remove_member', values)
     else:
         raise exceptions.KanshaException(_("User not found : %s" % username))
Esempio n. 12
0
    def edit(self, comp):
        content = comp.call(PageEditor(self))

        if content is not None:
            log.info('New content for page [%s]: [%s...]' % (self.title, content[:50]))
            security.check_permissions('wiki.editor', self)
            page = PageData.get_by(pagename=self.title)
            page.data = content

            # If the creator of the page is not already set, set it with the
            # current user
            if page.creator is None:
                page.creator = security.get_user().id
                log.debug('New creator for page [%s]: [%s]' % (page.pagename, page.creator))
Esempio n. 13
0
    def edit(self, comp):
        content = comp.call(PageEditor(self))

        if content is not None:
            log.info('New content for page [%s]: [%s...]' % (self.title, content[:50]))
            security.check_permissions('wiki.editor', self)
            page = PageData.get_by(pagename=self.title)
            page.data = content

            # If the creator of the page is not already set, set it with the
            # current user
            if page.creator is None:
                page.creator = security.get_user().id
                log.debug('New creator for page [%s]: [%s]' % (page.pagename, page.creator))
Esempio n. 14
0
    def add_member(self, new_data_member):
        """Attach new member to card

        In:
            - ``new_data_member`` -- UserData instance
        Return:
            - the new DataMember added
        """
        data = self.data
        if (new_data_member not in data.members and
                new_data_member in self.get_authorized_users()):
            log.debug('Adding %s to members' % (new_data_member.username,))

            data.members.append(new_data_member)
            self.members.append(component.Component(usermanager.UserManager.get_app_user(new_data_member.username, data=new_data_member)))
            return new_data_member
Esempio n. 15
0
    def add_member(self, new_data_member):
        """Attach new member to card

        In:
            - ``new_data_member`` -- UserData instance
        Return:
            - the new DataMember added
        """
        if (new_data_member not in self.card.members and
            new_data_member.id in self.get_available_user_ids()):

            self.card.add_member(new_data_member)
            log.debug('Adding %s to members' % (new_data_member.username,))
            self.members.append(
                component.Component(usermanager.UserManager.get_app_user(
                    new_data_member.username, data=new_data_member)))
Esempio n. 16
0
    def add_member(self, new_data_member):
        """Attach new member to card

        In:
            - ``new_data_member`` -- UserData instance
        Return:
            - the new DataMember added
        """
        if (new_data_member not in self.card.members
                and new_data_member.id in self.get_available_user_ids()):

            self.card.add_member(new_data_member)
            log.debug('Adding %s to members' % (new_data_member.username, ))
            self.members.append(
                component.Component(
                    usermanager.UserManager.get_app_user(
                        new_data_member.username, data=new_data_member)))
Esempio n. 17
0
def init_app__new_mail(self, url, comp, http_method, request):
    username, token = (url[1], url[2])
    get_user = lambda: UserManager.get_by_username(username)
    confirmation = self._services(forms.EmailConfirmation, self.app_title,
                                  self.app_banner, self.theme, get_user)
    if confirmation.confirm_email_address(token):
        log.debug(_('Change email success for user %s') % get_user().username)
        comp.becomes(self._services(forms.ChangeEmailConfirmation,
                                    self.app_title, self.app_banner,
                                    self.theme, request.application_url),
                     model='success')
        confirmation.reset_token(token)
    else:
        log.debug(_('Change email failure for user %s') % get_user().username)
        comp.becomes(self._services(forms.ChangeEmailConfirmation,
                                    self.app_title, self.app_banner,
                                    self.theme, request.application_url),
                     model='failure')
Esempio n. 18
0
File: mail.py Progetto: bcroq/kansha
    def send(self, subject, to, content, html_content=None, from_='', cc=[], bcc=[],
             type='plain', mpart_type='alternative'):
        """Sends an email

        In:
         - ``subject`` -- email subject
         - ``to`` -- list of recipients' emails
         - ``content`` --  email content
         - ``from_`` -- email sender adress
         - ``cc`` --  list of CC emails
         - ``bcc`` -- list of BCC emails
         - ``type`` --  email type ('plain' or 'html')
         - ``mpart_type`` -- email part type

        """
        from_ = from_ if from_ else self.default_sender
        # create the message envelop
        msg = MIMEMultipart(mpart_type)
        msg['Subject'] = subject
        msg['Date'] = formatdate(localtime=True)
        msg['From'] = from_
        msg['To'] = COMMASPACE.join(to)

        if cc:
            msg['Cc'] = COMMASPACE.join(cc)

        # attach the mail content
        charset = 'us-ascii'
        if isinstance(content, unicode):
            content = content.encode('UTF-8')
            charset = 'UTF-8'
        msg.attach(MIMEText(content, type, charset))
        if html_content:
            msg.attach(MIMEText(html_content, 'html', charset))

        # log
        log.info('%s mail:\n  subject=%s\n  from=%s\n  to=%s\n  cc=%s\n  bcc=%s',
                 'sending' if self.activated else 'ignoring', subject, from_, to, cc, bcc)
        log.debug('Mail content:\n' + content)

        # post the email to the SMTP server
        if self.activated:
            self._smtp_send(from_, to + cc + bcc, msg.as_string())
Esempio n. 19
0
    def remove_member(self, username):
        """Remove member username from card member"""
        data_member = usermanager.UserManager.get_by_username(username)
        if not data_member:
            raise exceptions.KanshaException(
                _("User not found : %s" % username))

        log.debug('Removing %s from card %s' % (username, self.card.id))
        self.card.remove_member(data_member)
        for member in self.members:
            if member().username == username:
                self.members.remove(member)
                values = {
                    'user_id': member().username,
                    'user': member().data.fullname,
                    'card': self.card.get_title()
                }
                self.action_log.add_history(security.get_user(),
                                            u'card_remove_member', values)
Esempio n. 20
0
    def add_member(self, new_data_member):
        """Attach new member to card

        In:
            - ``new_data_member`` -- UserData instance
        Return:
            - the new DataMember added
        """
        data = self.data
        if (new_data_member not in data.members
                and new_data_member in self.get_authorized_users()):
            log.debug('Adding %s to members' % (new_data_member.username, ))

            data.members.append(new_data_member)
            self.members.append(
                component.Component(
                    usermanager.UserManager.get_app_user(
                        new_data_member.username, data=new_data_member)))
            return new_data_member
Esempio n. 21
0
    def go(self, comp):
        if not self.state:
            # step 1:
            # - ask the user to fill a registration form
            # - send him a confirmation email
            if self.username:
                username, application_url = comp.call(
                    EmailRegistrationForm(
                        self.app_title,
                        self.app_banner,
                        self.theme,
                        self.username
                    )
                )
            else:
                username, application_url = comp.call(RegistrationForm(
                    self.app_title, self.app_banner, self.theme))
            if username:
                if self.identicons:
                    appuser = self.user_manager.get_app_user(username)
                    appuser.reset_avatar(self.assets_manager)
                confirmation = self._create_email_confirmation(username, application_url)
                if confirmation.send_email(self.mail_sender):
                    comp.call(confirmation)
                else:
                    comp.call(confirmation, model='send_email_failed')
        else:
            # step 2: the user confirms his email by clicking on the
            # confirmation link
            # - check the token (to avoid cheating)
            # - show a confirmation screen
            username, token = self.state

            confirmation = self._create_email_confirmation(username)
            if confirmation.confirm_email_address(token):
                log.debug(_("Registration successful for user %s") % username)
                base_url = comp.call(RegistrationConfirmation(self.app_title, self.app_banner, self.theme), model='success')
            else:
                log.debug(_("Registration failure for user %s") % username)
                base_url = comp.call(RegistrationConfirmation(self.app_title, self.app_banner, self.theme), model='failure')

            redirect_to(base_url)
Esempio n. 22
0
 def remove_member(self, username):
     """Remove member username from card member"""
     data_member = usermanager.UserManager.get_by_username(username)
     if data_member:
         log.debug('Removing %s from card %s' % (username, self.id))
         data = self.data
         data.members.remove(data_member)
         for member in self.members:
             if member().username == username:
                 self.members.remove(member)
                 values = {
                     'user_id': member().username,
                     'user': member().data.fullname,
                     'card': data.title
                 }
                 notifications.add_history(self.column.board.data, data,
                                           security.get_user().data,
                                           u'card_remove_member', values)
     else:
         raise exceptions.KanshaException(
             _("User not found : %s" % username))
Esempio n. 23
0
    def go(self, comp):
        if not self.state:
            # step 1:
            # - ask the user email
            # - send him a confirmation email
            username, application_url = comp.call(
                PasswordResetForm(self.app_title, self.app_banner, self.theme,
                                  self._get_user))
            if username:
                confirmation = self._create_password_reset_confirmation(
                    username, application_url)
                confirmation.send_email(self.mail_sender)
                comp.call(confirmation, model='email')
                redirect_to(application_url)
        else:
            # step 2: the user clicked on the confirmation link on his email
            # - check the token (to avoid cheating)
            # - ask for the new password
            username, token, application_url = self.state

            confirmation = self._create_password_reset_confirmation(
                username, application_url)
            if confirmation.confirm_password_reset(token):
                log.debug(_("Resetting the password for user %s") % username)
                ret = comp.call(
                    PasswordEditor(
                        self.app_title,
                        self.app_banner,
                        self.theme,
                        lambda username=username: self._get_user(username),
                        check_old_password=False))
                if ret:
                    confirmation.reset_token(token)
                    comp.call(confirmation, model='success')

            else:
                log.debug(_("Password reset failure for user %s") % username)
                comp.call(confirmation, model='failure')

            redirect_to(application_url)
Esempio n. 24
0
    def go(self, comp):
        if not self.state:
            # step 1:
            # - ask the user email
            # - send him a confirmation email
            username, application_url = comp.call(PasswordResetForm(self.app_title,
                                                   self.app_banner,
                                                   self.theme,
                                                   self._get_user))
            if username:
                confirmation = self._create_password_reset_confirmation(
                    username, application_url)
                if confirmation.send_email(self.mail_sender):
                    comp.call(confirmation, model='email')
                else:
                    comp.call(confirmation, model='send_email_failed')
                redirect_to(application_url)
        else:
            # step 2: the user clicked on the confirmation link on his email
            # - check the token (to avoid cheating)
            # - ask for the new password
            username, token, application_url = self.state

            confirmation = self._create_password_reset_confirmation(username, application_url)
            if security.get_user() is None and confirmation.confirm_password_reset(token):
                log.debug(_("Resetting the password for user %s") % username)
                ret = comp.call(PasswordEditor(self.app_title, self.app_banner, self.theme,
                                lambda username=username: self._get_user(username),
                                check_old_password=False))
                if ret:
                    confirmation.reset_token(token)
                    comp.call(confirmation, model='success')

            else:
                log.debug(_("Password reset failure for user %s") % username)
                comp.call(confirmation, model='failure')

            redirect_to(application_url)
Esempio n. 25
0
    def go(self, comp):
        if not self.state:
            # step 1:
            # - ask the user email
            # - send him a confirmation email
            username = comp.call(PasswordResetForm(self.app_title, self.custom_css, self._get_user))
            if username:
                confirmation = self._create_password_reset_confirmation(username)
                confirmation.send_email(self.mail_sender)
                comp.call(confirmation, model="email")
                redirect_to("/kansha")
        else:
            # step 2: the user clicked on the confirmation link on his email
            # - check the token (to avoid cheating)
            # - ask for the new password
            username, token = self.state

            confirmation = self._create_password_reset_confirmation(username)
            if confirmation.confirm_password_reset(token):
                log.debug(_("Resetting the password for user %s") % username)
                comp.call(
                    PasswordEditor(
                        self.app_title,
                        self.custom_css,
                        lambda username=username: self._get_user(username),
                        check_old_password=False,
                    )
                )
                confirmation.reset_token(token)
                comp.call(confirmation, model="success")

            else:
                log.debug(_("Password reset failure for user %s") % username)
                comp.call(confirmation, model="failure")

            redirect_to("/kansha")
Esempio n. 26
0
def _default_log(msg, duration):
    log.debug(msg, duration)
Esempio n. 27
0
def _default_log(msg, duration):
    log.debug(msg, duration)
Esempio n. 28
0
 def __init__(self, host, port, default_sender):
     self.host = host
     self.port = port
     self.default_sender = default_sender
     log.debug(
         'The mail sender will connect to %s on port %s' % (host, port))
Esempio n. 29
0
 def save(self, data, file_id=None, metadata={}):
     log.debug("Save Image")
     log.debug("%s" % metadata)
     return 'mock_id'
Esempio n. 30
0
 def save(self, data, file_id=None, metadata={}):
     log.debug("Save Image")
     log.debug("%s" % metadata)
     return 'mock_id'