Exemple #1
0
    def notify_on_membership_op(self, user_info, org_info, operation):
        addr_from = ADDR_FROM
        addr_to = user_info['email']

        if operation == 'approval':
            email_template = load_template('zpt/org_membership_approved.zpt')
            subject = "%s: Approved organisation membership" % NETWORK_NAME
        elif operation == 'rejection':
            email_template = load_template('zpt/org_membership_rejected.zpt')
            subject = "%s: Rejected organisation membership" % NETWORK_NAME

        options = {
            'org_info': org_info,
            'user_info': user_info,
            'context': self,
            'network_name': NETWORK_NAME
        }
        message = _create_plain_message(
            email_template(**options).encode('utf-8'))
        message['From'] = addr_from
        message['To'] = user_info['email']
        message['Subject'] = subject

        try:
            mailer = getUtility(IMailDelivery, name="Mail")
            mailer.send(addr_from, [addr_to], message.as_string())
        except ComponentLookupError:
            mailer = getUtility(IMailDelivery, name="naaya-mail-delivery")
            mailer.send(addr_from, [addr_to], message)
    def _send_token_email(self, addr_to, token, user_info):
        addr_from = ADDR_FROM
        email_template = load_template('zpt/pwreset_token_email.zpt')
        expiration_time = datetime.utcnow() + timedelta(days=1)
        options = {
            'token_url': self.absolute_url() + "/confirm_email?token=" + token,
            'user_info': user_info,
            'context': self,
            'network_name': NETWORK_NAME,
            'expiration_time': expiration_time.strftime("%Y-%m-%d %H:%M:%S")
        }
        print(options['token_url'])
        message = _create_plain_message(
            email_template(**options).encode('utf-8'))
        message['From'] = addr_from
        message['To'] = addr_to
        message['Subject'] = "%s account password recovery" % NETWORK_NAME

        try:
            mailer = getUtility(IMailDelivery, name="Mail")
            mailer.send(addr_from, [addr_to], message.as_string())
        except ComponentLookupError:
            mailer = getUtility(IMailDelivery, name="naaya-mail-delivery")
            try:
                mailer.send(addr_from, [addr_to], message.as_string())
            except (ValueError, AssertionError):
                mailer.send(addr_from, [addr_to], message)
Exemple #3
0
 def render(self, name, **options):
     context = self.aq_parent
     template = load_template(name)
     namespace = template.pt_getContext((), options)
     namespace['common'] = self.common_factory(context)
     namespace['browserview'] = self.browserview
     return template.pt_render(namespace)
Exemple #4
0
 def html(self):
     session = self.request.SESSION
     if self.name in session.keys():
         messages = dict(session[self.name])
         del session[self.name]
     else:
         messages = {}
     tmpl = load_template('zpt/session_messages.zpt')
     return tmpl(messages=messages)
Exemple #5
0
    def render(self, name, **options):
        context = self.aq_parent
        template = load_template(name)
        options['context'] = self.aq_parent
        options['request'] = self.aq_parent.REQUEST

        namespace = template.pt_getContext((), options)
        namespace['common'] = self.common_factory(context)
        return template.pt_render(namespace)
Exemple #6
0
 def _render_template(self, name, **options):
     tmpl = load_template(name)
     # Naaya groupware integration. If present, use the standard template
     # of the current site
     macro = self.aq_parent.restrictedTraverse('/').get('gw_macro')
     if macro:
         try:
             layout = self.aq_parent.getLayoutTool().getCurrentSkin()
             main_template = layout.getTemplateById('standard_template')
         except Exception:
             main_template = self.aq_parent.restrictedTraverse(
                 'standard_template.pt')
     else:
         main_template = self.aq_parent.restrictedTraverse(
             'standard_template.pt')
     main_page_macro = main_template.macros['page']
     options.update({'network_name': NETWORK_NAME})
     return self._zope2_wrapper(main_page_macro=main_page_macro,
                                body_html=tmpl(**options))
Exemple #7
0
    def change_password(self, REQUEST):
        """ view """
        form = REQUEST.form
        user_id = logged_in_user(REQUEST)
        agent = self._get_ldap_agent(bind=True, write=True)
        user_info = agent.user_info(user_id)

        if form['new_password'] != form['new_password_confirm']:
            _set_session_message(REQUEST, 'error',
                                 "New passwords do not match")
            return REQUEST.RESPONSE.redirect(self.absolute_url() +
                                             '/change_password_html')

        try:
            agent.bind_user(user_id, form['old_password'])
            agent.set_user_password(user_id, form['old_password'],
                                    form['new_password'])

            options = {
                'first_name': user_info['first_name'],
                'password': form['new_password'],
                'network_name': NETWORK_NAME,
            }

            email_template = load_template('zpt/email_change_password.zpt')
            email_password_body = email_template.pt_render(options)
            addr_to = user_info['email']

            message = MIMEText(email_password_body)
            message['From'] = ADDR_FROM
            message['To'] = addr_to
            message['Subject'] = "%s Account - New password" % NETWORK_NAME

            try:
                mailer = getUtility(IMailDelivery, name="Mail")
                mailer.send(ADDR_FROM, [addr_to], message.as_string())
            except ComponentLookupError:
                mailer = getUtility(IMailDelivery, name="naaya-mail-delivery")
                mailer.send(ADDR_FROM, [addr_to], message)

        except ValueError:
            _set_session_message(REQUEST, 'error', "Old password is wrong")
            return REQUEST.RESPONSE.redirect(self.absolute_url() +
                                             '/change_password_html')
        except CONSTRAINT_VIOLATION as e:
            if e.message['info'] in ['Password fails quality checking policy']:
                try:
                    defaultppolicy = agent.conn.search_s(
                        'cn=defaultppolicy,ou=pwpolicies,o=EIONET,'
                        'l=Europe', SCOPE_BASE)
                    p_length = defaultppolicy[0][1]['pwdMinLength'][0]
                    message = '%s (min. %s characters)' % (e.message['info'],
                                                           p_length)
                except NO_SUCH_OBJECT:
                    message = e.message['info']
            else:
                message = e.message['info']
            _set_session_message(REQUEST, 'error', message)
            return REQUEST.RESPONSE.redirect(self.absolute_url() +
                                             '/change_password_html')

        REQUEST.RESPONSE.redirect(self.absolute_url() +
                                  '/password_changed_html')
Exemple #8
0
 def macros(self):
     return load_template('zpt/macros.zpt').macros
Exemple #9
0
    db = UsersDB(
        ldap_server=config['ldap_server'],
        # next is for bwd compat with objects created with v1.0.0
        users_rdn=config.get('users_rdn', defaults['users_rdn']),
        users_dn=config['users_dn'],
        orgs_dn=config['orgs_dn'],
        roles_dn=config['roles_dn'])

    if bind:
        if secondary:
            db.perform_bind(config['secondary_admin_dn'],
                            config['secondary_admin_pw'])
        else:
            db.perform_bind(config['admin_dn'], config['admin_pw'])

    return db


def _get_ldap_agent(context, bind=False, secondary=False):
    ''' get the ldap agent '''
    agent = ldap_agent_with_config(context._config, bind, secondary=secondary)
    try:
        agent._author = logged_in_user(context.REQUEST)
    except AttributeError:
        agent._author = "System user"

    return agent


edit_macro = load_template('zpt/ldap_config.zpt').macros['edit']
Exemple #10
0
def get_template_macro(name):
    return load_template('zpt/orgs_macros.zpt').macros[name]