Example #1
0
    def handle_submit(self, converted):
        request = self.request
        context = self.context

        # *will be* modified event
        objectEventNotify(ObjectWillBeModifiedEvent(context))

        simple_fields = ['title', 'text', 'caption', 'publication_date']
        for field in simple_fields:
            setattr(context, field, converted[field])

        # save tags, attachments, photo
        set_tags(context, request, converted['tags'])
        userid = authenticated_userid(request)
        attachments_folder = context['attachments']
        upload_attachments(converted['attachments'], attachments_folder,
                           userid, request)
        handle_photo_upload(context, converted)
        self.filestore.clear

        # mark as modified
        context.modified_by = userid
        objectEventNotify(ObjectModifiedEvent(context))

        location = resource_url(context, request)
        msg = "?status_message=News%20Item%20edited"
        return HTTPFound(location=location + msg)
Example #2
0
    def handle_submit(self, converted):
        context = self.context
        request = self.request
        userid = converted['login']
        users = self.users
        if (users.get_by_id(userid) is not None or
            users.get_by_login(userid) is not None or
            userid in context):
            msg = "User ID '%s' is already in use" % userid
            raise ValidationError(login=msg)
        users.add(userid, userid, converted['password'], converted['groups'])

        # prepend http:// to the website URL if necessary
        if converted.get('website', '').startswith('www.'):
            converted['website'] = 'http://%s' % converted['website']
        kw = {}
        for k, v in converted.items():
            if k in ('login', 'password', 'password_confirm',
                     'photo', 'groups'):
                continue
            kw[k] = v
        profile = create_content(IProfile, **kw)
        context[userid] = profile

        workflow = get_workflow(IProfile, 'security', context)
        if workflow is not None:
            workflow.initialize(profile)

        handle_photo_upload(profile, converted, thumbnail=True)
        location = model_url(profile, request)
        return HTTPFound(location=location)
Example #3
0
    def handle_submit(self, converted):
        request = self.request
        context = self.context

        #create the news item and store it
        creator = authenticated_userid(request)
        newsitem = create_content(
            INewsItem,
            title=converted['title'],
            text=converted['text'],
            creator=creator,
            publication_date=converted['publication_date'],
            caption=converted['caption'],
        )
        name = make_unique_name(context, converted['title'])
        context[name] = newsitem

        # tags, attachments, and photos
        set_tags(newsitem, request, converted['tags'])
        attachments_folder = newsitem['attachments']
        upload_attachments(converted['attachments'], attachments_folder,
                           creator, request)
        try:
            handle_photo_upload(newsitem, converted)
        except Invalid, e:
            raise ValidationError(**e.error_dict)
    def handle_submit(self, converted):
        request = self.request
        context = self.context

        #create the news item and store it
        creator = authenticated_userid(request)
        newsitem = create_content(
            INewsItem,
            title=converted['title'],
            text=converted['text'],
            creator=creator,
            publication_date=converted['publication_date'],
            caption=converted['caption'],
            )
        name = make_unique_name(context, converted['title'])
        context[name] = newsitem
        relocate_temp_images(newsitem, request)

        # tags, attachments, and photos
        set_tags(newsitem, request, converted['tags'])
        attachments_folder = newsitem['attachments']
        upload_attachments(converted['attachments'], attachments_folder,
                           creator, request)
        try:
            handle_photo_upload(newsitem, converted)
        except Invalid, e:
            raise ValidationError(**e.error_dict)
Example #5
0
    def handle_submit(self, converted):
        request = self.request
        context = self.context
        
        #create the news item and store it
        creator = authenticated_userid(request)
        newsitem = create_content(
            INewsItem,
            title=converted['title'],
            text=converted['text'],
            creator=creator,
            publication_date=converted['publication_date'],
            caption=converted['caption'],
            )
        name = make_unique_name(context, converted['title'])
        context[name] = newsitem

        # tags, attachments, and photos
        set_tags(newsitem, request, converted['tags'])
        attachments_folder = newsitem['attachments']
        upload_attachments(converted['attachments'], attachments_folder,
                           creator, request)
        handle_photo_upload(newsitem, converted)
        self.filestore.clear()

        location = model_url(newsitem, request)
        return HTTPFound(location=location)
    def handle_submit(self, converted):
        request = self.request
        context = self.context

        # *will be* modified event
        objectEventNotify(ObjectWillBeModifiedEvent(context))

        simple_fields = ['title', 'text', 'caption', 'publication_date']
        for field in simple_fields:
            setattr(context, field, converted[field])

        # save tags, attachments, photo
        set_tags(context, request, converted['tags'])
        userid = authenticated_userid(request)
        attachments_folder = context['attachments']
        upload_attachments(converted['attachments'], attachments_folder,
                           userid, request)
        handle_photo_upload(context, converted)
        self.filestore.clear

        # mark as modified
        context.modified_by = userid
        objectEventNotify(ObjectModifiedEvent(context))

        location = resource_url(context, request)
        msg = "?status_message=News%20Item%20edited"
        return HTTPFound(location=location+msg)
Example #7
0
 def handle_submit(self, converted):
     context = self.context
     request = self.request
     objectEventNotify(ObjectWillBeModifiedEvent(context))
     _normalize_websites(converted)
     # Handle the easy ones
     for name in self.simple_field_names:
         setattr(context, name, converted.get(name))
     # Handle the picture and clear the temporary filestore
     try:
         handle_photo_upload(context, converted)
     except Invalid, e:
         raise ValidationError(**e.error_dict)
Example #8
0
 def handle_submit(self, converted):
     context = self.context
     request = self.request
     objectEventNotify(ObjectWillBeModifiedEvent(context))
     _normalize_websites(converted)
     # Handle the easy ones
     for name in self.simple_field_names:
         setattr(context, name, converted.get(name))
     # Handle the picture and clear the temporary filestore
     try:
         handle_photo_upload(context, converted)
     except Invalid, e:
         raise ValidationError(**e.error_dict)
Example #9
0
    def handle_submit(self, converted):
        context = self.context
        community = self.community
        request = self.request
        users = find_users(context)
        profiles = self.profiles

        password = converted['password']
        password_confirm = converted['password_confirm']

        if password != password_confirm:
            msg = 'Mismatched password and confirm'
            raise ValidationError(password_confirm=msg, password=msg)

        username = converted['username']
        if username in profiles:
            raise ValidationError(username='******')

        community_href = model_url(community, request)
        groups = [ community.members_group_name ]
        users.add(username, username, password, groups)
        plugin = request.environ['repoze.who.plugins']['auth_tkt']
        identity = {'repoze.who.userid':username}
        remember_headers = plugin.remember(request.environ, identity)
        profile = create_content(
            IProfile,
            firstname=converted['firstname'],
            lastname=converted['lastname'],
            email=context.email,
            phone=converted['phone'],
            extension=converted['extension'],
            department=converted['department'],
            position=converted['position'],
            organization=converted['organization'],
            location=converted['location'],
            country=converted['country'],
            website=converted['website'],
            languages=converted['languages']
            )
        profiles[username] = profile
        workflow = get_workflow(IProfile, 'security')
        if workflow is not None:
            workflow.initialize(profile)
        handle_photo_upload(profile, converted, thumbnail=True)

        del context.__parent__[context.__name__]
        url = model_url(community, request,
                        query={'status_message':'Welcome!'})
        _send_ai_email(community, community_href, username, profile)
        self.filestore.clear()
        return HTTPFound(headers=remember_headers, location=url)
Example #10
0
    def handle_submit(self, converted):
        context = self.context
        community = self.community
        request = self.request
        users = find_users(context)
        profiles = self.profiles

        password = converted['password']
        password_confirm = converted['password_confirm']

        if password != password_confirm:
            msg = 'Mismatched password and confirm'
            raise ValidationError(password_confirm=msg, password=msg)

        username = converted['username']
        if username in profiles:
            raise ValidationError(username='******')

        community_href = resource_url(community, request)
        groups = [ community.members_group_name ]
        users.add(username, username, password, groups)
        plugin = request.environ['repoze.who.plugins']['auth_tkt']
        identity = {'repoze.who.userid':username}
        remember_headers = plugin.remember(request.environ, identity)
        profile = create_content(
            IProfile,
            firstname=converted['firstname'],
            lastname=converted['lastname'],
            email=context.email,
            phone=converted['phone'],
            extension=converted['extension'],
            department=converted['department'],
            position=converted['position'],
            organization=converted['organization'],
            location=converted['location'],
            country=converted['country'],
            websites=converted['websites'],
            date_format=converted['date_format'],
            languages=converted['languages']
            )
        profiles[username] = profile
        workflow = get_workflow(IProfile, 'security')
        if workflow is not None:
            workflow.initialize(profile)
        try:
            handle_photo_upload(profile, converted)
        except Invalid, e:
            raise ValidationError(**e.error_dict)
Example #11
0
File: members.py Project: zagy/karl
    def handle_submit(self, converted):
        context = self.context
        community = self.community
        request = self.request
        users = find_users(context)
        profiles = self.profiles

        password = converted['password']
        password_confirm = converted['password_confirm']

        if password != password_confirm:
            msg = 'Mismatched password and confirm'
            raise ValidationError(password_confirm=msg, password=msg)

        username = converted['username']
        if username in profiles:
            raise ValidationError(username='******')

        community_href = resource_url(community, request)
        groups = [community.members_group_name]
        users.add(username, username, password, groups)
        remember_headers = remember(request, username)
        profile = create_content(IProfile,
                                 firstname=converted['firstname'],
                                 lastname=converted['lastname'],
                                 email=context.email,
                                 phone=converted['phone'],
                                 extension=converted['extension'],
                                 department=converted['department'],
                                 position=converted['position'],
                                 organization=converted['organization'],
                                 location=converted['location'],
                                 country=converted['country'],
                                 websites=converted['websites'],
                                 date_format=converted['date_format'],
                                 biography=converted['biography'],
                                 languages=converted['languages'])
        profiles[username] = profile
        workflow = get_workflow(IProfile, 'security')
        if workflow is not None:
            workflow.initialize(profile)
        try:
            handle_photo_upload(profile, converted)
        except Invalid, e:
            raise ValidationError(**e.error_dict)
Example #12
0
 def handle_submit(self, converted):
     context = self.context
     request = self.request
     objectEventNotify(ObjectWillBeModifiedEvent(context))
     # prepend http:// to the website URL if necessary
     if converted.get('website', '').startswith('www.'):
         converted['website'] = 'http://%s' % converted['website']
     # Handle the easy ones
     for name in self.simple_field_names:
         setattr(context, name, converted.get(name))
     # Handle the picture and clear the temporary filestore
     handle_photo_upload(context, converted, thumbnail=True)
     self.filestore.clear()
     # Emit a modified event for recataloging
     objectEventNotify(ObjectModifiedEvent(context))
     # Whew, we made it!
     path = model_url(context, request)
     msg = '?status_message=Profile%20edited'
     return HTTPFound(location=path+msg)
Example #13
0
    def handle_submit(self, converted):
        context = self.context
        request = self.request
        users = find_users(context)
        profiles = self.profiles

        password = converted['password']
        password_confirm = converted['password_confirm']

        if password != password_confirm:
            msg = 'Mismatched password and confirm'
            raise ValidationError(password_confirm=msg, password=msg)

        username = converted['username']
        if username in profiles:
            raise ValidationError(username='******')

        groups = self.get_groups()
        users.add(username, username, password, groups)
        remember_headers = remember(request, username)

        data = dict(
            firstname=converted['firstname'],
            lastname=converted['lastname'],
            email=context.email
        )
        for field_name in get_setting(self.context, 'member_fields'):
            if field_name in self.fields:
                data[field_name] = converted[field_name]
        profile = create_content(IProfile, **data)

        profiles[username] = profile
        workflow = get_workflow(IProfile, 'security')
        if workflow is not None:
            workflow.initialize(profile)
        try:
            handle_photo_upload(profile, converted)
        except Invalid, e:
            raise ValidationError(**e.error_dict)
Example #14
0
    def handle_submit(self, converted):
        context = self.context
        request = self.request
        users = find_users(context)
        profiles = self.profiles

        password = converted['password']
        password_confirm = converted['password_confirm']

        if password != password_confirm:
            msg = 'Mismatched password and confirm'
            raise ValidationError(password_confirm=msg, password=msg)

        username = converted['username']
        if username in profiles:
            raise ValidationError(username='******')

        groups = self.get_groups()
        users.add(username, username, password, groups)
        remember_headers = remember(request, username)

        data = dict(firstname=converted['firstname'],
                    lastname=converted['lastname'],
                    email=context.email)
        for field_name in get_setting(self.context, 'member_fields'):
            if field_name in self.fields:
                data[field_name] = converted[field_name]
        profile = create_content(IProfile, **data)

        profiles[username] = profile
        workflow = get_workflow(IProfile, 'security')
        if workflow is not None:
            workflow.initialize(profile)
        try:
            handle_photo_upload(profile, converted)
        except Invalid, e:
            raise ValidationError(**e.error_dict)
Example #15
0
 def _callFUT(self, context, form, thumbnail=False):
     from karl.views.utils import handle_photo_upload
     return handle_photo_upload(context, form, thumbnail=thumbnail)
Example #16
0
 def _callFUT(self, context, form):
     from karl.views.utils import handle_photo_upload
     return handle_photo_upload(context, form)
Example #17
0
    def handle_submit(self, converted):
        context = self.context
        request = self.request
        userid = converted['login']
        users = self.users
        if (users.get_by_id(userid) is not None or
            users.get_by_login(userid) is not None):
            msg = "User ID '%s' is already in use" % userid
            raise ValidationError(login=msg)
        profile = context.get(userid)
        if profile is not None:
            if profile.security_state == 'inactive':
                url = resource_url(profile, request, 'reactivate.html')
                self.reactivate_user = dict(userid=userid, url=url)
                msg = ("User ID '%s' is used by a previously deactivated "
                       "user.  Perhaps you mean to reactivate this user. "
                       "See link above."%
                       userid)
            else:
                msg = "User ID '%s' is already in use" % userid
            raise ValidationError(login=msg)

        search = ICatalogSearch(context)
        count, docids, resolver = search(
            interfaces=[IProfile], email=converted['email']
        )
        if count:
            msg = 'Email address is already in use by another user(s).'
            if count == 1:
                profile = resolver(docids[0])
                if profile.security_state ==  'inactive':
                    url = resource_url(profile, request, 'reactivate.html')
                    userid = profile.__name__
                    self.reactivate_user = dict(userid=userid, url=url)
                    msg = ("Email address is in use by a previously "
                           "deactivated user.  Perhaps you mean to reactivate "
                           "this user. See link above.")
            raise ValidationError(email=msg)

        # If user was previously invited to join any communities, those
        # invitations are no longer needed.
        count, docids, resolver = search(
            interfaces=[IInvitation], email=converted['email'])
        for docid in docids:
            invitation = resolver(docid)
            del invitation.__parent__[invitation.__name__]

        users.add(userid, userid, converted['password'], converted['groups'])

        _normalize_websites(converted)
        kw = {}
        for k, v in converted.items():
            if k in ('login', 'password', 'password_confirm',
                     'photo', 'groups'):
                continue
            kw[k] = v
        profile = create_content(IProfile, **kw)
        profile.modified_by = authenticated_userid(request)
        context[userid] = profile

        workflow = get_workflow(IProfile, 'security', context)
        if workflow is not None:
            workflow.initialize(profile)

        try:
            handle_photo_upload(profile, converted)
        except Invalid, e:
            raise ValidationError(**e.error_dict)
Example #18
0
 def _callFUT(self, context, form):
     from karl.views.utils import handle_photo_upload
     return handle_photo_upload(context, form)
Example #19
0
    def handle_submit(self, converted):
        context = self.context
        request = self.request
        userid = converted['login']
        users = self.users
        if (users.get_by_id(userid) is not None
                or users.get_by_login(userid) is not None):
            msg = "User ID '%s' is already in use" % userid
            raise ValidationError(login=msg)
        profile = context.get(userid)
        if profile is not None:
            if profile.security_state == 'inactive':
                url = resource_url(profile, request, 'reactivate.html')
                self.reactivate_user = dict(userid=userid, url=url)
                msg = ("User ID '%s' is used by a previously deactivated "
                       "user.  Perhaps you mean to reactivate this user. "
                       "See link above." % userid)
            else:
                msg = "User ID '%s' is already in use" % userid
            raise ValidationError(login=msg)

        search = ICatalogSearch(context)
        count, docids, resolver = search(interfaces=[IProfile],
                                         email=converted['email'])
        if count:
            msg = 'Email address is already in use by another user(s).'
            if count == 1:
                profile = resolver(docids[0])
                if profile.security_state == 'inactive':
                    url = resource_url(profile, request, 'reactivate.html')
                    userid = profile.__name__
                    self.reactivate_user = dict(userid=userid, url=url)
                    msg = ("Email address is in use by a previously "
                           "deactivated user.  Perhaps you mean to reactivate "
                           "this user. See link above.")
            raise ValidationError(email=msg)

        # If user was previously invited to join any communities, those
        # invitations are no longer needed.
        count, docids, resolver = search(interfaces=[IInvitation],
                                         email=converted['email'])
        for docid in docids:
            invitation = resolver(docid)
            del invitation.__parent__[invitation.__name__]

        users.add(userid, userid, converted['password'], converted['groups'])

        _normalize_websites(converted)
        kw = {}
        for k, v in converted.items():
            if k in ('login', 'password', 'password_confirm', 'photo',
                     'groups'):
                continue
            kw[k] = v
        profile = create_content(IProfile, **kw)
        profile.modified_by = authenticated_userid(request)
        context[userid] = profile

        workflow = get_workflow(IProfile, 'security', context)
        if workflow is not None:
            workflow.initialize(profile)

        try:
            handle_photo_upload(profile, converted)
        except Invalid, e:
            raise ValidationError(**e.error_dict)
Example #20
0
class AdminEditProfileFormController(EditProfileFormController):
    """
    Extends the default profile edit controller w/ all of the extra
    logic that the admin form requires.
    """
    simple_field_names = EditProfileFormController.simple_field_names
    simple_field_names = simple_field_names + ['home_path']

    def __init__(self, context, request):
        super(AdminEditProfileFormController, self).__init__(context, request)
        self.users = find_users(context)
        self.userid = context.__name__
        self.user = self.users.get_by_id(self.userid)
        if self.user is not None:
            self.is_active = True
            self.user_groups = set(self.user['groups'])
            self.group_options = get_group_options(self.context)
        else:
            self.is_active = False

    def form_fields(self):
        context = self.context
        home_path_field = schemaish.String(
            validator=karlvalidators.PathExists(context),
            description=('The first page to show after logging in. '
                         'Leave blank to show a community or the '
                         'community list.'))
        if self.user is not None:
            password_field = schemaish.String(
                validator=karlvalidators.PasswordLength(min_pw_length()),
                title='Reset Password',
                description=('Enter a new password for the user here, '
                             'or leave blank to leave the password '
                             'unchanged.'))
            fields = [('login', login_field), ('groups', groups_field),
                      ('home_path', home_path_field),
                      ('password', password_field)]
        else:
            fields = [('home_path', home_path_field)]
        fields += super(AdminEditProfileFormController, self).form_fields()
        return fields

    def form_widgets(self, fields):
        widgets = super(AdminEditProfileFormController,
                        self).form_widgets(fields)
        if self.user is not None:
            groups_widget = formish.CheckboxMultiChoice(self.group_options)
            widgets.update({
                'login': formish.Input(empty=''),
                'groups': groups_widget,
                'password': karlwidgets.KarlCheckedPassword(),
            })
        widgets.update({
            'home_path':
            formish.Input(empty=''),
            'websites':
            formish.TextArea(rows=3, converter_options={'delimiter': '\n'}),
        })
        return widgets

    def form_defaults(self):
        defaults = super(AdminEditProfileFormController, self).form_defaults()
        context = self.context
        if self.user is not None:
            defaults.update({
                'login': self.user['login'],
                'groups': self.user_groups,
                'password': ''
            })
        defaults['home_path'] = context.home_path
        return defaults

    def __call__(self):
        _fix_website_validation_errors(self.request.form)
        api = TemplateAPI(self.context, self.request, self.page_title)
        layout_provider = get_layout_provider(self.context, self.request)
        layout = layout_provider('generic')
        self.request.form.edge_div_class = 'k3_admin_role'
        form_title = 'Edit User and Profile Information'
        return {
            'api': api,
            'actions': (),
            'layout': layout,
            'form_title': form_title,
            'include_blurb': False,
            'admin_edit': True,
            'is_active': self.is_active
        }

    def handle_submit(self, converted):
        context = self.context
        request = self.request
        users = self.users
        userid = self.userid
        user = self.user
        if user is not None:
            login = converted.get('login')
            login_changed = users.get_by_login(login) != user
            if (login_changed and (users.get_by_id(login) is not None
                                   or users.get_by_login(login) is not None
                                   or login in context)):
                msg = "Login '%s' is already in use" % login
                raise ValidationError(login=msg)
        objectEventNotify(ObjectWillBeModifiedEvent(context))
        if user is not None:
            # Set new login
            try:
                users.change_login(userid, converted['login'])
            except ValueError, e:
                raise ValidationError(login=str(e))
            # Set group memberships
            user_groups = self.user_groups
            chosen_groups = set(converted['groups'])
            for group, group_title in self.group_options:
                if group in chosen_groups and group not in user_groups:
                    users.add_user_to_group(userid, group)
                if group in user_groups and group not in chosen_groups:
                    users.remove_user_from_group(userid, group)
            # Edit password
            if converted.get('password', None):
                users.change_password(userid, converted['password'])
        _normalize_websites(converted)
        # Handle the easy ones
        for name in self.simple_field_names:
            setattr(context, name, converted.get(name))
        # Handle the picture and clear the temporary filestore
        try:
            handle_photo_upload(context, converted)
        except Invalid, e:
            raise ValidationError(**e.error_dict)