def start(self, context, request, appstruct, **kw): person = appstruct['_object_data'] root = context principals = find_service(root, 'principals') name = person.first_name + ' ' +person.last_name name = name_chooser(name=name) principals['users'][name] = person grant_roles(person, roles=('Member',)) grant_roles(person, (('Owner', person),)) person.state.append('active') localizer = request.localizer for i in range(root.tokens_mini): token = Token(title='Token_'+str(i)) person.addtoproperty('tokens_ref', token) person.addtoproperty('tokens', token) token.setproperty('owner', person) subject = CONFIRMATION_SUBJECT.format(novaideo_title=request.root.title) message = CONFIRMATION_MESSAGE.format( person=person, user_title=localizer.translate( _(getattr(person, 'user_title', ''))), login_url=request.resource_url(root, '@@login'), novaideo_title=request.root.title) mailer_send(subject=subject, recipients=[person.email], body=message) person.reindex() return {'person': person}
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
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 {}
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}
def start(self, context, request, appstruct, **kw): changepassword = appstruct['change_password']['changepassword'] current_user_password = appstruct['change_password']['currentuserpassword'] user = get_current() if changepassword and user.check_password(current_user_password): password = appstruct['change_password']['password'] context.set_password(password) context.set_title() name = name_chooser(name=context.title) if not context.name.startswith(name): principals = find_service(getSite(), 'principals') context.name = name_chooser(principals['users'], name=name) context.modified_at = datetime.datetime.now(tz=pytz.UTC) context.reindex() request.registry.notify(ActivityExecuted(self, [context], user)) return {}
def start(self, context, request, appstruct, **kw): changepassword = appstruct['change_password']['changepassword'] current_user_password = appstruct['change_password'][ 'currentuserpassword'] user = get_current() if changepassword and user.check_password(current_user_password): password = appstruct['change_password']['password'] context.set_password(password) context.set_title() name = name_chooser(name=context.title) if not context.name.startswith(name): principals = find_service(getSite(), 'principals') context.name = name_chooser(principals['users'], name=name) context.modified_at = datetime.datetime.now(tz=pytz.UTC) context.reindex() request.registry.notify(ActivityExecuted(self, [context], user)) return {}
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}
def choose_name(self, name, object): if not name: name = getattr(object, 'title', object.__class__.__name__) if not name: name = object.__class__.__name__ if isinstance(name, bytes): name = name.decode() new_name = name_chooser(self.data, name) return new_name
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') structure = data.pop('structure') site = get_site_folder(True) root = getSite() person = Person(**data) principals = find_service(root, 'principals') name = getattr(person, 'first_name', '') + ' '\ + getattr(person, 'last_name', '') users = principals['users'] name = name_chooser(users, name=name) users[name] = person if structure: grant_roles(person, roles=(('CulturalAnimator', site), )) person.setproperty('structure', structure) else: grant_roles(person, roles=(('Member', site), )) grant_roles(person, roles=('Member', )) grant_roles(person, (('Owner', person), )) person.state.append('active') person.reindex() get_socket().send_pyobj( ('stop', 'persistent_' + str(get_oid(context)))) root.delfromproperty('preregistrations', context) person.add_customeraccount() person.init_annotations() person.annotations.setdefault(PROCESS_HISTORY_KEY, PersistentList()).extend(annotations) request.registry.notify(ActivityExecuted(self, [person], person)) transaction.commit() localizer = request.localizer mail_template = site.get_mail_template('subscription_statement') subject = mail_template['subject'] message = mail_template['template'].format( person=person, user_title=localizer.translate(_(getattr(person, 'user_title', ''))), login_url=request.resource_url(root, '@@login'), lac_title=request.root.title) alert('email', [site.get_site_sender()], [person.email], { 'subject': subject, 'body': message }) return {'person': person}
def create_user(context, request, appstruct): if appstruct and 'external_login' in appstruct: account = appstruct.get('profile').get('accounts')[0] source_data = {'id': account['userid'], 'source_id': account['domain']} lac_index = find_catalog('lac') object_id_index = lac_index['object_id'] obj_id = source_data.get('id', '') + '_' +\ source_data.get('source_id', '') query = object_id_index.eq(obj_id) users = list(find_entities( interfaces=[IPerson], add_query=query)) person = None if users: person = users[0] else: name_parts = appstruct.get('profile').get( 'preferredUsername', '').split(' ') if len(name_parts) == 1: if name_parts[0]: name_parts.append('') else: name_parts = ['User', 'User'] data = { 'first_name': name_parts[0], 'last_name': ' '.join(name_parts[1:]), 'password': None, 'email': account.get('email', None) } site = get_site_folder(True) root = getSite() person = Person(**data) person.source_data = PersistentDict(source_data) principals = find_service(root, 'principals') name = getattr(person, 'first_name', '') + ' '\ + getattr(person, 'last_name', '') users = principals['users'] name = name_chooser(users, name=name) users[name] = person grant_roles(person, roles=(('Member', site),)) grant_roles(person, roles=('Member',)) grant_roles(person, (('Owner', person),)) person.state.append('active') person.reindex() person.add_customeraccount() person.init_annotations() transaction.commit() return {'user': person} return {'user': None}
def create_user(context, request, appstruct): if appstruct and 'external_login' in appstruct: account = appstruct.get('profile').get('accounts')[0] source_data = {'id': account['userid'], 'source_id': account['domain']} lac_index = find_catalog('lac') object_id_index = lac_index['object_id'] obj_id = source_data.get('id', '') + '_' +\ source_data.get('source_id', '') query = object_id_index.eq(obj_id) users = list(find_entities(interfaces=[IPerson], add_query=query)) person = None if users: person = users[0] else: name_parts = appstruct.get('profile').get('preferredUsername', '').split(' ') if len(name_parts) == 1: if name_parts[0]: name_parts.append('') else: name_parts = ['User', 'User'] data = { 'first_name': name_parts[0], 'last_name': ' '.join(name_parts[1:]), 'password': None, 'email': account.get('email', None) } site = get_site_folder(True) root = getSite() person = Person(**data) person.source_data = PersistentDict(source_data) principals = find_service(root, 'principals') name = getattr(person, 'first_name', '') + ' '\ + getattr(person, 'last_name', '') users = principals['users'] name = name_chooser(users, name=name) users[name] = person grant_roles(person, roles=(('Member', site), )) grant_roles(person, roles=('Member', )) grant_roles(person, (('Owner', person), )) person.state.append('active') person.reindex() person.add_customeraccount() person.init_annotations() transaction.commit() return {'user': person} return {'user': None}
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') structure = data.pop('structure') site = get_site_folder(True) root = getSite() person = Person(**data) principals = find_service(root, 'principals') name = getattr(person, 'first_name', '') + ' '\ + getattr(person, 'last_name', '') users = principals['users'] name = name_chooser(users, name=name) users[name] = person if structure: grant_roles(person, roles=(('CulturalAnimator', site),)) person.setproperty('structure', structure) else: grant_roles(person, roles=(('Member', site),)) grant_roles(person, roles=('Member',)) grant_roles(person, (('Owner', person),)) person.state.append('active') person.reindex() get_socket().send_pyobj( ('stop', 'persistent_' + str(get_oid(context)))) root.delfromproperty('preregistrations', context) person.add_customeraccount() person.init_annotations() person.annotations.setdefault( PROCESS_HISTORY_KEY, PersistentList()).extend(annotations) request.registry.notify(ActivityExecuted(self, [person], person)) transaction.commit() localizer = request.localizer mail_template = site.get_mail_template('subscription_statement') subject = mail_template['subject'] message = mail_template['template'].format( person=person, user_title=localizer.translate( _(getattr(person, 'user_title', ''))), login_url=request.resource_url(root, '@@login'), lac_title=request.root.title) alert('email', [site.get_site_sender()], [person.email], {'subject': subject, 'body': message}) return {'person': person}
def add_user(data, request, roles=('Member',)): from novaideo.content.person import Person root = request.root 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=roles) grant_roles(person, (('Owner', person),)) person.state.append('active') person.init_annotations() person.reindex() return person
def start(self, context, request, appstruct, **kw): changepassword = appstruct['change_password']['changepassword'] current_user_password = appstruct['change_password']['currentuserpassword'] user = get_current() if changepassword and user.check_password(current_user_password): password = appstruct['change_password']['password'] context.set_password(password) root = getSite() keywords_ids = appstruct.pop('keywords') result, newkeywords = root.get_keywords(keywords_ids) for nkw in newkeywords: root.addtoproperty('keywords', nkw) result.extend(newkeywords) context.setproperty('keywords_ref', result) context.set_title() context.name = name_chooser(name=context.title) context.modified_at = datetime.datetime.today() context.reindex() return {}
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 {}