def user_delete(context, request): principals = get_principals() if 'name' in request.params and request.params['name']: user_or_group = request.params['name'] principal = principals.search(name=user_or_group).first() if principal is None: request.session.flash(_('User was not found.'), 'error') else: is_group = user_or_group.startswith("group:") principal_type = _("Group") if is_group else _("User") # We already coming from the confirmation page. if 'delete' in request.POST: principals.__delitem__(principal.name) notify(UserDeleted(principal, request)) request.session.flash( _('${principal_type} ${title} was deleted.', mapping=dict(principal_type=principal_type, title=principal.title)), 'info') location = '{0}/@@setup-users'.format(request.application_url) return HTTPFound(location=location) api = template_api( context, request, page_title=_("Delete ${principal_type} ${title}", mapping=dict(principal_type=principal_type, title=principal.title)), principal_type=principal_type, principal=principal) return {'api': api, } else: request.session.flash(_('No name was given.'), 'error') return {'api': template_api(context, request), }
def user_delete(context, request): principals = get_principals() if 'name' in request.params and request.params['name']: user_or_group = request.params['name'] principal = principals.search(name=user_or_group).first() if principal is None: request.session.flash(_(u'User was not found.'), 'error') else: is_group = user_or_group.startswith("group:") principal_type = _(u"Group") if is_group else _(u"User") # We already coming from the confirmation page. if 'delete' in request.POST: principals.__delitem__(principal.name) notify(UserDeleted(principal, request)) request.session.flash( _(u'${principal_type} ${title} was deleted.', mapping=dict(principal_type=principal_type, title=principal.title)), 'info') location = "%s/@@setup-users" % request.application_url return HTTPFound(location=location) api = template_api( context, request, page_title=_(u"Delete ${principal_type} ${title}", mapping=dict(principal_type=principal_type, title=principal.title)), principal_type=principal_type, principal=principal) return {'api': api, } else: request.session.flash(_(u'No name was given.'), 'error') return {'api': template_api(context, request), }
def workflow_callback(context, info): wf = info.workflow to_state = info.transition.get('to_state') if to_state is None: if context.state: to_state = context.state else: to_state = wf.initial_state state_data = wf._state_data[to_state].copy() acl = [] # This could definitely be cached... for key, value in state_data.items(): if key.startswith('role:') or key == 'system.Everyone': for perm in value.split(): acl.append(("Allow", key, perm)) if state_data.get('inherit', '0').lower() not in TRUE_VALUES: acl.append(DENY_ALL) context.__acl__ = acl if info.transition: notify(WorkflowTransition(context, info))
def workflow_callback(context, info): wf = info.workflow to_state = info.transition.get('to_state') if to_state is None: if context.state: to_state = context.state else: to_state = wf.initial_state state_data = wf._state_data[to_state].copy() acl = [] # This could definitely be cached... special_roles = ('system.Everyone', 'system.Authenticated') for key, value in list(state_data.items()): if key.startswith('role:') or key in special_roles: for perm in value.split(): acl.append(("Allow", key, perm)) if state_data.get('inherit', '0').lower() not in TRUE_VALUES: acl.append(DENY_ALL) context.__acl__ = acl if info.transition: notify(WorkflowTransition(context, info))
def workflow_callback(context, info): wf = info.workflow to_state = info.transition.get("to_state") if to_state is None: if context.state: to_state = context.state else: to_state = wf.initial_state state_data = wf._state_data[to_state].copy() acl = [] # This could definitely be cached... special_roles = ("system.Everyone", "system.Authenticated") for key, value in state_data.items(): if key.startswith("role:") or key in special_roles: for perm in value.split(): acl.append(("Allow", key, perm)) if state_data.get("inherit", "0").lower() not in TRUE_VALUES: acl.append(DENY_ALL) context.__acl__ = acl if info.transition: notify(WorkflowTransition(context, info))
def view_signup(context, request): user_addform = SeaUnicornisUserAddFormView(context, request)() if request.is_response(user_addform): principal = get_principals().get(request.params[u'name']) notify(UserAdded(principal, request)) return user_addform return { 'api': template_api(context, request), 'user_addform': user_addform['form'], }
def register(context, request): schema = RegisterSchema().bind(request=request) form = Form(schema, buttons=(Button('register', _('Register')),)) rendered_form = None if 'register' in request.POST: try: appstruct = form.validate(request.POST.items()) except ValidationFailure as e: request.session.flash(_("There was an error."), 'error') rendered_form = e.render() else: settings = get_settings() appstruct['groups'] = '' appstruct['roles'] = '' register_groups = settings['kotti.register.group'] if register_groups: appstruct['groups'] = [register_groups] register_roles = settings['kotti.register.role'] if register_roles: appstruct['roles'] = {'role:' + register_roles} appstruct['send_email'] = True form = UserAddFormView(context, request) form.add_user_success(appstruct) success_msg = _( 'Congratulations! You are successfully registered. ' 'You should be receiving an email with a link to set your ' 'password. Doing so will activate your account.' ) request.session.flash(success_msg, 'success') name = appstruct['name'] notify(UserSelfRegistered(get_principals()[name], request)) return HTTPFound(location=request.application_url) if rendered_form is None: rendered_form = form.render(request.params) api = template_api( context, request, page_title=_("Register - ${title}", mapping=dict(title=context.title)), ) return { 'api': api, 'form': rendered_form, }
def register(context, request): schema = RegisterSchema().bind(request=request) form = Form(schema, buttons=(Button('register', _(u'Register')), )) rendered_form = None if 'register' in request.POST: try: appstruct = form.validate(request.POST.items()) except ValidationFailure as e: request.session.flash(_(u"There was an error."), 'error') rendered_form = e.render() else: settings = get_settings() appstruct['groups'] = u'' appstruct['roles'] = u'' register_groups = settings['kotti.register.group'] if register_groups: appstruct['groups'] = [register_groups] register_roles = settings['kotti.register.role'] if register_roles: appstruct['roles'] = {'role:' + register_roles} appstruct['send_email'] = True form = UserAddFormView(context, request) form.add_user_success(appstruct) success_msg = _( 'Congratulations! You are successfully registered. ' 'You should be receiving an email with a link to set your ' 'password. Doing so will activate your account.') request.session.flash(success_msg, 'success') name = appstruct['name'] notify(UserSelfRegistered(get_principals()[name], request)) return HTTPFound(location=request.application_url) if rendered_form is None: rendered_form = form.render(request.params) api = template_api( context, request, page_title=_(u"Register - ${title}", mapping=dict(title=context.title)), ) return { 'api': api, 'form': rendered_form, }
def register(context, request): schema = RegisterSchema().bind(request=request) form = Form(schema, buttons=(Button("register", _("Register")),)) rendered_form = None if "register" in request.POST: try: appstruct = form.validate(request.POST.items()) except ValidationFailure as e: request.session.flash(_("There was an error."), "error") rendered_form = e.render() else: settings = get_settings() appstruct["groups"] = "" appstruct["roles"] = "" register_groups = settings["kotti.register.group"] if register_groups: appstruct["groups"] = [register_groups] register_roles = settings["kotti.register.role"] if register_roles: appstruct["roles"] = {"role:" + register_roles} appstruct["send_email"] = True form = UserAddFormView(context, request) form.add_user_success(appstruct) success_msg = _( "Congratulations! You are successfully registered. " "You should be receiving an email with a link to set your " "password. Doing so will activate your account." ) request.session.flash(success_msg, "success") name = appstruct["name"] notify(UserSelfRegistered(get_principals()[name], request)) return HTTPFound(location=request.application_url) if rendered_form is None: rendered_form = form.render(request.params) api = template_api( context, request, page_title=_("Register - ${title}", mapping=dict(title=context.title)), ) return {"api": api, "form": rendered_form}
def register(context, request): schema = RegisterSchema().bind(request=request) form = Form(schema, buttons=(Button("register", _(u"Register")),)) rendered_form = None if "register" in request.POST: try: appstruct = form.validate(request.POST.items()) except ValidationFailure as e: request.session.flash(_(u"There was an error."), "error") rendered_form = e.render() else: settings = get_settings() appstruct["groups"] = u"" appstruct["roles"] = u"" register_groups = settings["kotti.register.group"] if register_groups: appstruct["groups"] = [register_groups] register_roles = settings["kotti.register.role"] if register_roles: appstruct["roles"] = {"role:" + register_roles} appstruct["send_email"] = True form = UserAddFormView(context, request) form.add_user_success(appstruct) success_msg = _( "Congratulations! You are successfully registered. " "You should be receiving an email with a link to set your " "password. Doing so will activate your account." ) request.session.flash(success_msg, "success") name = appstruct["name"] notify(UserSelfRegistered(get_principals()[name], request)) return HTTPFound(location=request.application_url) if rendered_form is None: rendered_form = form.render(request.params) api = template_api(context, request, page_title=_(u"Register - ${title}", mapping=dict(title=context.title))) return {"api": api, "form": rendered_form}
def user_delete(context, request): principals = get_principals() if "name" in request.params and request.params["name"]: user_or_group = request.params["name"] principal = principals.search(name=user_or_group).first() if principal is None: request.session.flash(_("User was not found."), "error") else: is_group = user_or_group.startswith("group:") principal_type = _("Group") if is_group else _("User") # We already coming from the confirmation page. if "delete" in request.POST: principals.__delitem__(principal.name) notify(UserDeleted(principal, request)) request.session.flash( _( "${principal_type} ${title} was deleted.", mapping=dict(principal_type=principal_type, title=principal.title), ), "info", ) location = f"{request.application_url}/@@setup-users" return HTTPFound(location=location) api = template_api( context, request, page_title=_( "Delete ${principal_type} ${title}", mapping=dict(principal_type=principal_type, title=principal.title), ), principal_type=principal_type, principal=principal, ) return {"api": api} else: request.session.flash(_("No name was given."), "error") return {"api": template_api(context, request)}
def user_delete(context, request): principals = get_principals() if "name" in request.params and request.params["name"]: user_or_group = request.params["name"] principal = principals.search(name=user_or_group).first() if principal is None: request.session.flash(_("User was not found."), "error") else: is_group = user_or_group.startswith("group:") principal_type = _("Group") if is_group else _("User") # We already coming from the confirmation page. if "delete" in request.POST: principals.__delitem__(principal.name) notify(UserDeleted(principal, request)) request.session.flash( _( "${principal_type} ${title} was deleted.", mapping=dict( principal_type=principal_type, title=principal.title ), ), "info", ) location = "{0}/@@setup-users".format(request.application_url) return HTTPFound(location=location) api = template_api( context, request, page_title=_( "Delete ${principal_type} ${title}", mapping=dict(principal_type=principal_type, title=principal.title), ), principal_type=principal_type, principal=principal, ) return {"api": api} else: request.session.flash(_("No name was given."), "error") return {"api": template_api(context, request)}
def register(context, request): schema = RegisterSchema().bind(request=request) form = Form(schema, buttons=(Button('register', _(u'Register')),)) rendered_form = None if 'register' in request.POST: try: appstruct = form.validate(request.POST.items()) except ValidationFailure, e: request.session.flash(_(u"There was an error."), 'error') rendered_form = e.render() else: settings = get_settings() appstruct['groups'] = u'' appstruct['roles'] = u'' register_groups = settings['kotti.register.group'] if register_groups: appstruct['groups'] = [register_groups] register_roles = settings['kotti.register.role'] if register_roles: appstruct['roles'] = set(['role:' + register_roles]) appstruct['send_email'] = True form = UserAddFormView(context, request) form.add_user_success(appstruct) success_msg = _( 'Congratulations! You are successfully registered. ' 'You should receive an email with a link to set your ' 'password momentarily.' ) request.session.flash(success_msg, 'success') name = appstruct['name'] notify(UserSelfRegistered(get_principals()[name], request)) return HTTPFound(location=request.application_url)
def _after_insert(mapper, connection, target): notify(ObjectAfterInsert(target, get_current_request()))
def find_principal(json, user, request): #-- log.debug('find_principal {}'.format(pformat(json))) displayName = None verifiedEmail = None emails = [] if 'profile' in json: profile = json['profile'] if 'emails' in profile: emails = profile['emails'] if emails and isinstance(emails[0], dict): emails = [r['value'] for r in emails] if 'verifiedEmail' in profile: verifiedEmail = profile['verifiedEmail'] elif len(emails) > 0: verifiedEmail = emails[0] if verifiedEmail is None: raise AttributeError(_(u'Provider have not informed any email address')) if 'displayName' in profile: displayName = profile['displayName'] elif 'name' in profile and 'formatted' in profile['name']: displayName = profile['name']['formatted'] else: displayName = verifiedEmail accounts = Accounts() if user is None: try: log.debug('Find Principal for email {}'.format(verifiedEmail)) principal = accounts[verifiedEmail] except Exception as e: log.debug('Exception {}'.format(type(e))) log.debug('Create Principal {} for email {}'.format(displayName, verifiedEmail)) accounts[verifiedEmail] = { 'name' : verifiedEmail, 'title': displayName, 'email': verifiedEmail } # creates a new Principal principal = accounts[verifiedEmail] # assing administration rights to it, ONLY IF needed admins = get_settings().get('kotti.accounts.admins') if admins and verifiedEmail in admins: log.warn('New Principal {} for email {} has got ADMINISTRATIVE RIGHTS !!!'.format( displayName, verifiedEmail)) principal.groups = USER_MANAGEMENT_ROLES # Triggers UserSelfRegistered event in case user is None, i.e: when a true # new user registers, not when a new email is added to an existing account. notify(UserSelfRegistered(principal, request)) else: principal = user log.debug('verifiedEmail is {}'.format(verifiedEmail)) log.debug('principal is {}'.format(principal)) log.debug(type(principal)) try: dummy = accounts[verifiedEmail] except Exception as e: accounts[verifiedEmail] = principal for email in emails: if email != verifiedEmail: log.debug('Create additional Account for email {}'.format(email)) try: dummy = accounts[email] except: accounts[email] = principal principal.last_login_date = datetime.now() return (principal, emails)
def after_kotti_velruse_loggedin(userLoginObject): notify(AfterKottiVelruseLoggedIn(userLoginObject))
def after_kotti_velruse_loggedin(userLoginObject): notify( AfterKottiVelruseLoggedIn(userLoginObject) )