def login(context, request): login_url = request.mgmt_path(request.context, 'login') referrer = request.url if login_url in referrer: # pragma: no cover # never use the login form itself as came_from referrer = request.mgmt_path(request.root) came_from = request.session.setdefault('came_from', referrer) login = '' password = '' if 'form.submitted' in request.params: try: check_csrf_token(request) except: request.session.flash('Failed login (CSRF)', 'error') else: login = request.params['login'] password = request.params['password'] principals = find_service(context, 'principals') users = principals['users'] user = users.get(login) if user is not None and user.check_password(password): headers = remember(request, oid_of(user)) request.session.flash('Welcome!', 'success') return HTTPFound(location=came_from, headers=headers) request.session.flash('Failed login', 'error') return dict( url=request.mgmt_path(request.root, 'login'), came_from=came_from, login=login, password=password, login_url=velruse_login_url, providers=request.registry.settings['substanced.login_providers'] )
def main(): parser = OptionParser(description=__doc__) parser.add_option('-d', '--dry-run', dest='dry_run', action="store_true", default=False, help="Don't commit the transactions") parser.add_option('-i', '--interval', dest='commit_interval', action="store", default=200, help="Commit every N transactions") parser.add_option('-p', '--path', dest='path', action="store", default=None, metavar='EXPR', help="Reindex only objects whose path matches a regular expression") parser.add_option('-n', '--index', dest='indexes', action="append", help="Reindex only the given index (can be repeated)") parser.add_option('-s', '--site', dest='site', action="store", default=None, metavar='PATH') options, args = parser.parse_args() if args: config_uri = args[0] else: parser.error("Requires a config_uri as an argument") commit_interval = int(options.commit_interval) if options.path: path_re = re.compile(options.path) else: path_re = None kw = {} if options.indexes: kw['indexes'] = options.indexes setup_logging(config_uri) env = bootstrap(config_uri) site = env['root'] if options.site: site = traverse(site, options.site) catalog = find_service(site, 'catalog') if catalog is None: raise KeyError('No catalog service found at ' % resource_path(site)) catalog.reindex(path_re=path_re, commit_interval=commit_interval, dry_run=options.dry_run, **kw)
def external_login_complete(request): profile = request.context.profile email = '' if 'verifiedEmail' in profile: email = profile['verifiedEmail'] if 'emails' in profile: emails = profile['emails'] email = emails[0]['value'] came_from = request.session.get('came_from', request.application_url) connection = get_connection(request) site_root = connection.root()['app_root'] principals = find_service(site_root, 'principals') users = principals['users'] user = [user for user in users.values() if user.email == email] if not user or not email: return external_login_denied(request) headers = remember(request, oid_of(user[0])) request.session.flash('Welcome!', 'success') return HTTPFound(location=came_from, headers=headers)