Beispiel #1
0
def create_user(request, appstruct):
    if appstruct and 'user_data' in appstruct:
        source_data = appstruct.get('source_data', {})
        data = appstruct.get('user_data', {})
        root = getSite()
        locale = my_locale_negotiator(request)
        data['locale'] = locale
        person = Person(**data)
        person.set_source_data(source_data)
        principals = find_service(root, 'principals')
        name = person.first_name + ' ' + person.last_name
        users = principals['users']
        name = name_chooser(users, name=name)
        users[name] = person
        grant_roles(person, roles=('Member',))
        grant_roles(person, (('Owner', person),))
        person.state.append('active')
        person.init_annotations()
        person.annotations.setdefault(
            PROCESS_HISTORY_KEY, PersistentList())
        person.reindex()
        root.addtoproperty('news_letter_members', person)
        newsletters = root.get_newsletters_automatic_registration()
        email = getattr(person, 'email', '')
        if newsletters and email:
            for newsletter in newsletters:
                newsletter.subscribe(
                    person.first_name, person.last_name, email)

        transaction.commit()
        return person

    return None
Beispiel #2
0
    def start(self, context, request, appstruct, **kw):
        datas = context.get_data(
            select(omit(InvitationSchema(), ['_csrf_token_']), [
                'user_title', 'roles', 'first_name', 'last_name', 'email',
                'organization'
            ]))
        roles = datas.pop('roles')
        password = appstruct['password']
        datas['locale'] = my_locale_negotiator(request)
        person = Person(password=password, **datas)
        root = getSite(context)
        principals = find_service(root, 'principals')
        users = principals['users']
        name = person.first_name + ' ' + person.last_name
        name = name_chooser(users, name=name)
        users[name] = person
        if getattr(context, 'ismanager', False) and \
           context.organization:
            grant_roles(person,
                        (('OrganizationResponsible', context.organization), ))

        person.state.append('active')
        grant_roles(person, roles)
        grant_roles(person, (('Owner', person), ))
        manager = context.manager
        root.delfromproperty('invitations', context)
        root.addtoproperty('news_letter_members', person)
        newsletters = root.get_newsletters_automatic_registration()
        email = getattr(person, 'email', '')
        if newsletters and email:
            for newsletter in newsletters:
                newsletter.subscribe(person.first_name, person.last_name,
                                     email)

        context.person = person
        if manager:
            mail_template = root.get_mail_template(
                'accept_invitation',
                getattr(manager, 'user_locale', root.locale))
            localizer = request.localizer
            email_data = get_user_data(person, 'user', request)
            novaideo_title = request.root.title
            roles_translate = [
                localizer.translate(APPLICATION_ROLES.get(r, r)) for r in roles
            ]
            subject = mail_template['subject'].format(
                novaideo_title=novaideo_title, **email_data)
            email_data.update(get_user_data(manager, 'recipient', request))
            email_data.update(get_entity_data(person, 'user', request))
            message = mail_template['template'].format(
                roles=", ".join(roles_translate),
                novaideo_title=novaideo_title,
                **email_data)
            alert('email', [root.get_site_sender()], [manager.email],
                  subject=subject,
                  body=message)

        return {}
Beispiel #3
0
    def start(self, context, request, appstruct, **kw):
        data = context.get_data(PersonSchema())
        annotations = getattr(context, 'annotations',
                              {}).get(PROCESS_HISTORY_KEY, [])
        data.update({'password': appstruct['password']})
        data = {
            key: value
            for key, value in data.items() if value is not colander.null
        }
        data.pop('title')
        root = getSite()
        locale = my_locale_negotiator(request)
        data['locale'] = locale
        person = Person(**data)
        principals = find_service(root, 'principals')
        name = person.first_name + ' ' + person.last_name
        users = principals['users']
        name = name_chooser(users, name=name)
        users[name] = person
        grant_roles(person, roles=('Member', ))
        grant_roles(person, (('Owner', person), ))
        person.state.append('active')
        oid = str(get_oid(context))
        get_socket().send_pyobj(('stop', 'persistent_' + oid))
        organization = context.organization
        if organization:
            person.setproperty('organization', organization)

        root.delfromproperty('preregistrations', context)
        person.init_annotations()
        person.annotations.setdefault(PROCESS_HISTORY_KEY,
                                      PersistentList()).extend(annotations)
        person.reindex()
        request.registry.notify(ActivityExecuted(self, [person], person))
        root.addtoproperty('news_letter_members', person)
        newsletters = root.get_newsletters_automatic_registration()
        email = getattr(person, 'email', '')
        if newsletters and email:
            for newsletter in newsletters:
                newsletter.subscribe(person.first_name, person.last_name,
                                     email)

        transaction.commit()
        if email:
            mail_template = root.get_mail_template('registration_confiramtion',
                                                   person.user_locale)
            subject = mail_template['subject'].format(
                novaideo_title=root.title)
            recipientdata = get_user_data(person, 'recipient', request)
            message = mail_template['template'].format(
                login_url=request.resource_url(root, '@@login'),
                novaideo_title=root.title,
                **recipientdata)
            alert('email', [root.get_site_sender()], [email],
                  subject=subject,
                  body=message)

        return {'person': person}
Beispiel #4
0
    def start(self, context, request, appstruct, **kw):
        data = context.get_data(PersonSchema())
        annotations = getattr(context, 'annotations', {}).get(PROCESS_HISTORY_KEY, [])
        data.update({'password': appstruct['password']})
        data = {key: value for key, value in data.items()
                if value is not colander.null}
        data.pop('title')
        root = getSite()
        locale = my_locale_negotiator(request)
        data['locale'] = locale
        person = Person(**data)
        principals = find_service(root, 'principals')
        name = person.first_name + ' ' + person.last_name
        users = principals['users']
        name = name_chooser(users, name=name)
        users[name] = person
        grant_roles(person, roles=('Member',))
        grant_roles(person, (('Owner', person),))
        person.state.append('active')
        oid = str(get_oid(context))
        get_socket().send_pyobj(('stop', 'persistent_' + oid))
        organization = context.organization
        if organization:
            person.setproperty('organization', organization)

        root.delfromproperty('preregistrations', context)
        person.init_annotations()
        person.annotations.setdefault(
            PROCESS_HISTORY_KEY, PersistentList()).extend(annotations)
        person.reindex()
        request.registry.notify(ActivityExecuted(self, [person], person))
        root.addtoproperty('news_letter_members', person)
        newsletters = root.get_newsletters_automatic_registration()
        email = getattr(person, 'email', '')
        if newsletters and email:
            for newsletter in newsletters:
                newsletter.subscribe(
                    person.first_name, person.last_name, email)

        transaction.commit()
        if email:
            mail_template = root.get_mail_template(
                'registration_confiramtion', person.user_locale)
            subject = mail_template['subject'].format(
                novaideo_title=root.title)
            recipientdata = get_user_data(person, 'recipient', request)
            message = mail_template['template'].format(
                login_url=request.resource_url(root, '@@login'),
                novaideo_title=root.title,
                **recipientdata)
            alert('email', [root.get_site_sender()], [email],
                  subject=subject, body=message)

        return {'person': person}
Beispiel #5
0
    def start(self, context, request, appstruct, **kw):
        preregistration = appstruct['_object_data']
        preregistration.__name__ = gen_random_token()
        preregistration.locale = my_locale_negotiator(request)
        root = getSite()
        root.addtoproperty('preregistrations', preregistration)
        deadline = DEADLINE_PREREGISTRATION * 1000
        call_id = 'persistent_' + str(get_oid(preregistration))
        push_callback_after_commit(remove_expired_preregistration_callback,
                                   deadline,
                                   call_id,
                                   root=root,
                                   preregistration=preregistration)
        preregistration.state.append('pending')
        preregistration.reindex()
        transaction.commit()
        if not getattr(root, 'moderate_registration', False):
            accept_preregistration(request, preregistration, root)
        else:
            admins = get_users_with_role(role='SiteAdmin')
            alert('internal', [root],
                  admins,
                  internal_kind=InternalAlertKind.admin_alert,
                  subjects=[preregistration],
                  alert_kind='new_registration')
            url = request.resource_url(preregistration, '@@index')
            for admin in [a for a in admins if getattr(a, 'email', '')]:
                mail_template = root.get_mail_template(
                    'moderate_preregistration', admin.user_locale)
                subject = mail_template['subject'].format(
                    novaideo_title=root.title)
                email_data = get_user_data(admin, 'recipient', request)
                message = mail_template['template'].format(
                    url=url, novaideo_title=root.title, **email_data)
                alert('email', [root.get_site_sender()], [admin.email],
                      subject=subject,
                      body=message)

        request.registry.notify(ActivityExecuted(self, [preregistration],
                                                 None))
        return {'preregistration': preregistration}
Beispiel #6
0
def accept_preregistration(request, preregistration, root):
    preregistration.init_deadline(datetime.datetime.now(tz=pytz.UTC))
    if getattr(preregistration, 'email', ''):
        deadline_date = preregistration.get_deadline_date()
        locale = my_locale_negotiator(request)
        url = request.resource_url(preregistration, "")
        mail_template = root.get_mail_template(
            'preregistration', getattr(preregistration, 'locale', locale))
        email_data = get_user_data(preregistration, 'recipient', request)
        subject = mail_template['subject'].format(
            novaideo_title=root.title)
        deadline_str = to_localized_time(
            deadline_date, request, translate=True)
        message = mail_template['template'].format(
            url=url,
            deadline_date=deadline_str.lower(),
            novaideo_title=root.title,
            **email_data
            )
        alert('email', [root.get_site_sender()], [preregistration.email],
              subject=subject, body=message)
Beispiel #7
0
def accept_preregistration(request, preregistration, root):
    preregistration.init_deadline(datetime.datetime.now(tz=pytz.UTC))
    if getattr(preregistration, 'email', ''):
        deadline_date = preregistration.get_deadline_date()
        locale = my_locale_negotiator(request)
        url = request.resource_url(preregistration, "")
        mail_template = root.get_mail_template(
            'preregistration', getattr(preregistration, 'locale', locale))
        email_data = get_user_data(preregistration, 'recipient', request)
        subject = mail_template['subject'].format(novaideo_title=root.title)
        deadline_str = to_localized_time(deadline_date,
                                         request,
                                         translate=True)
        message = mail_template['template'].format(
            url=url,
            deadline_date=deadline_str.lower(),
            novaideo_title=root.title,
            **email_data)
        alert('email', [root.get_site_sender()], [preregistration.email],
              subject=subject,
              body=message)
Beispiel #8
0
    def start(self, context, request, appstruct, **kw):
        preregistration = appstruct['_object_data']
        preregistration.__name__ = gen_random_token()
        preregistration.locale = my_locale_negotiator(request)
        root = getSite()
        root.addtoproperty('preregistrations', preregistration)
        deadline = DEADLINE_PREREGISTRATION * 1000
        call_id = 'persistent_' + str(get_oid(preregistration))
        push_callback_after_commit(
            remove_expired_preregistration_callback, deadline, call_id,
            root=root, preregistration=preregistration)
        preregistration.state.append('pending')
        preregistration.reindex()
        transaction.commit()
        if not getattr(root, 'moderate_registration', False):
            accept_preregistration(request, preregistration, root)
        else:
            admins = get_users_with_role(role='SiteAdmin')
            alert(
                'internal', [root], admins,
                internal_kind=InternalAlertKind.admin_alert,
                subjects=[preregistration], alert_kind='new_registration')
            url = request.resource_url(preregistration, '@@index')
            for admin in [a for a in admins if getattr(a, 'email', '')]:
                mail_template = root.get_mail_template(
                    'moderate_preregistration', admin.user_locale)
                subject = mail_template['subject'].format(
                    novaideo_title=root.title)
                email_data = get_user_data(admin, 'recipient', request)
                message = mail_template['template'].format(
                    url=url,
                    novaideo_title=root.title,
                    **email_data)
                alert('email', [root.get_site_sender()], [admin.email],
                      subject=subject, body=message)

        request.registry.notify(ActivityExecuted(self, [preregistration], None))
        return {'preregistration': preregistration}
Beispiel #9
0
    def start(self, context, request, appstruct, **kw):
        datas = context.get_data(select(omit(InvitationSchema(),
                                             ['_csrf_token_']),
                                        ['user_title',
                                         'roles',
                                         'first_name',
                                         'last_name',
                                         'email',
                                         'organization']))
        roles = datas.pop('roles')
        password = appstruct['password']
        datas['locale'] = my_locale_negotiator(request)
        person = Person(password=password, **datas)
        root = getSite(context)
        principals = find_service(root, 'principals')
        users = principals['users']
        name = person.first_name + ' ' + person.last_name
        name = name_chooser(users, name=name)
        users[name] = person
        if getattr(context, 'ismanager', False) and \
           context.organization:
            grant_roles(person, (('OrganizationResponsible',
                                   context.organization),))

        person.state.append('active')
        grant_roles(person, roles)
        grant_roles(person, (('Owner', person),))
        manager = context.manager
        root.delfromproperty('invitations', context)
        root.addtoproperty('news_letter_members', person)
        newsletters = root.get_newsletters_automatic_registration()
        email = getattr(person, 'email', '')
        if newsletters and email:
            for newsletter in newsletters:
                newsletter.subscribe(
                    person.first_name, person.last_name, email)

        context.person = person
        if manager:
            mail_template = root.get_mail_template(
                'accept_invitation',
                getattr(manager, 'user_locale', root.locale))
            localizer = request.localizer
            email_data = get_user_data(person, 'user', request)
            novaideo_title = request.root.title
            roles_translate = [localizer.translate(APPLICATION_ROLES.get(r, r))
                               for r in roles]
            subject = mail_template['subject'].format(
                novaideo_title=novaideo_title,
                **email_data
            )
            email_data.update(get_user_data(manager, 'recipient', request))
            email_data.update(get_entity_data(person, 'user', request))
            message = mail_template['template'].format(
                roles=", ".join(roles_translate),
                novaideo_title=novaideo_title,
                **email_data)
            alert('email', [root.get_site_sender()], [manager.email],
                  subject=subject, body=message)

        return {}