Presents the user with a selection of applicable tokens for the requested view.
349316
def select_token(request, scopes='', new=False):
    

    @tokens_required(scopes=scopes, new=new)
    def _token_list(r, tokens):
        context = {
            'tokens': tokens,
            'base_template': app_settings.ESI_BASE_TEMPLATE,
        }
        return render(r, 'esi/select_token.html', context=context)

    return _token_list(request)
55680
def populate_token_attributes(self, response):
        """"""

        if 'access_token' in response:
            self.access_token = response.get('access_token')

        if 'refresh_token' in response:
            self.refresh_token = response.get('refresh_token')

        if 'token_type' in response:
            self.token_type = response.get('token_type')

        if 'expires_in' in response:
            self.expires_in = response.get('expires_in')
            self._expires_at = time.time() + int(self.expires_in)

        if 'expires_at' in response:
            self._expires_at = int(response.get('expires_at'))

        if 'mac_key' in response:
            self.mac_key = response.get('mac_key')

        if 'mac_algorithm' in response:
            self.mac_algorithm = response.get('mac_algorithm')
800670
def _validate_token(self, token, scopes_required=None):
        """"""
        if scopes_required is None:
            scopes_required = []
        scopes_required = set(scopes_required)

        token_info = None
        valid_token = False
        has_required_scopes = False
        if token:
            try:
                token_info = self._get_token_info(token)
            except Exception as ex:
                token_info = {'active': False}
                logger.error('ERROR: Unable to get token info')
                logger.error(str(ex))

            valid_token = token_info.get('active', False)

            if 'aud' in token_info and \
                    current_app.config['OIDC_RESOURCE_CHECK_AUD']:
                valid_audience = False
                aud = token_info['aud']
                clid = self.client_secrets['client_id']
                if isinstance(aud, list):
                    valid_audience = clid in aud
                else:
                    valid_audience = clid == aud

                if not valid_audience:
                    logger.error('Refused token because of invalid '
                                 'audience')
                    valid_token = False

            if valid_token:
                token_scopes = token_info.get('scope', '').split(' ')
            else:
                token_scopes = []
            has_required_scopes = scopes_required.issubset(
                set(token_scopes))

            if not has_required_scopes:
                logger.debug('Token missed required scopes')

        if (valid_token and has_required_scopes):
            g.oidc_token_info = token_info
            return True

        if not valid_token:
            return 'Token required but invalid'
        elif not has_required_scopes:
            return 'Token does not have required scopes'
        else:
            return 'Something went wrong checking your token'
950086
def chrome_setup_view(request):
    
    logger.debug(request.POST)
    token = None
    if request.method == "POST":
        if "token" in request.POST:
            token = request.POST.get("token")

    if not token:
        return HttpResponse('{"error":"Invalid data."}', content_type="text/json")
    ncfg, _ = NotificationConfig.objects.get_or_create(user=request.user)
    ncfg.gcm_token = token
    ncfg.save()
    return HttpResponse('{"success":"Now registered."}', content_type="text/json")
370486
def registeredViews(location='Central'):
        
        return [view for view in XView._registry.get(nativestring(location), {}).values() if not view.isViewAbstract()]
1261210
public function render(array $tokens, $view, array $partials = null)
    {
        // Do some pre-initialization of variables used later in the routine
        $renderer = $this;
        $inLoop   = false;

        if (is_scalar($view)) {
            // Iteration over lists will sometimes involve scalars
            $inLoop = true;
        }

        if (null === $partials) {
            $partials = [];
        }

        $rendered = '';
        foreach ($tokens as $token) {
            list($type, $data) = $token;
            if ($value = $this->handlePragmas($token, $view)) {
                $rendered .= $value;
                continue;
            }
            switch ($type) {
                case Lexer::TOKEN_CONTENT:
                    $rendered .= $data;
                    break;
                case Lexer::TOKEN_VARIABLE:
                    $value = $this->getValue($data, $view);
                    if (is_scalar($value)) {
                        if ($test = $this->handlePragmas($token, $value)) {
                            $rendered .= $test;
                            break;
                        }

                        $rendered .= ('' === $value) ? '' : $this->escape($value);
                        break;
                    }

                    $pragmaView = [$data => $value];
                    if ($test = $this->handlePragmas($token, $pragmaView)) {
                        $rendered .= $test;
                        break;
                    }

                    $rendered .= (string) $value;
                    break;
                case Lexer::TOKEN_VARIABLE_RAW:
                    $value = $this->getValue($data, $view);
                    $rendered .= $value;
                    break;
                case Lexer::TOKEN_SECTION:
                    if ($inLoop) {
                        // In a loop, with scalar values; skip
                        break;
                    }
                    $section = $this->getValue($data['name'], $view);
                    if (! $section) {
                        // Section is not a true value; skip
                        break;
                    }

                    // Build the section view
                    $sectionView = $section;
                    if (is_bool($section)) {
                        // For a boolean true, pass the current view
                        $sectionView = $view;
                    }
                    if (is_array($section) || $section instanceof Traversable) {
                        if (is_array($section) && $this->isAssocArray($section)) {
                            // Nested view; pass it as the view
                            $sectionView = $section;
                        } else {
                            // Iteration
                            $renderedSection = '';
                            foreach ($section as $sectionView) {
                                $renderedSection .= $this->render($data['content'], $sectionView);
                            }
                            $rendered .= $renderedSection;
                            break;
                        }
                    } elseif (is_callable($section) && $this->isValidCallback($section)) {
                        // Higher order section
                        // Execute the callback, passing it the section's template
                        // string, as well as a renderer lambda.
                        $mustache       = $this->mustache;
                        $invokedPragmas = $this->invokedPragmas;
                        $rendered .= call_user_func(
                            $section,
                            $data['template'],
                            function ($text) use ($renderer, $mustache, $view, $partials) {
                                $tokens = $mustache->tokenize($text);
                                return $renderer->render($tokens, $view, $partials);
                            }
                        );
                        $this->registerPragmas($invokedPragmas);
                        break;
                    } elseif (is_object($section)) {
                        // In this case, the child object is the view.
                        $sectionView = $section;
                    } else {
                        // All other types, simply pass the current view
                        $sectionView = $view;
                    }

                    // Render the section
                    $invokedPragmas = $this->invokedPragmas;
                    $rendered .= $this->render($data['content'], $sectionView);
                    $this->registerPragmas($invokedPragmas);
                    break;
                case Lexer::TOKEN_SECTION_INVERT:
                    if ($inLoop) {
                        // In a loop, with scalar values; skip
                        break;
                    }
                    $section = $this->getValue($data['name'], $view);
                    if ($section) {
                        // If a value exists for the section, we skip it
                        $rendered .= '';
                        break;
                    }

                    // Otherwise, we render it
                    $invokedPragmas = $this->invokedPragmas;
                    $rendered .= $this->render($data['content'], $view);
                    $this->registerPragmas($invokedPragmas);
                    break;
                case Lexer::TOKEN_PLACEHOLDER:
                    if ($inLoop) {
                        // In a loop, with scalar values; skip
                        break;
                    }
                    $rendered .= $this->render($data['content'], $view);
                    break;
                case Lexer::TOKEN_PARTIAL:
                    if ($inLoop) {
                        // In a loop, with scalar values; skip
                        break;
                    }
                    $invokedPragmas = $this->invokedPragmas;
                    $this->clearInvokedPragmas();
                    if (! isset($data['tokens'])) {
                        $name = $data['partial'];
                        if (isset($partials[$data['partial']])) {
                            // Partial invoked is an aliased partial
                            $rendered .= $this->render($partials[$data['partial']], $view);
                        } else {
                            $partialTokens = $this->mustache->tokenize($data['partial']);
                            $rendered .= $this->render($partialTokens, $view);
                        }
                        $this->registerPragmas($invokedPragmas);
                        break;
                    }
                    $rendered .= $this->render($data['tokens'], $view);
                    $this->registerPragmas($invokedPragmas);
                    break;
                case Lexer::TOKEN_PRAGMA:
                    $this->registerPragma($data);
                    break;
                case Lexer::TOKEN_DELIM_SET:
                case Lexer::TOKEN_COMMENT:
                default:
                    // do nothing; only necessary for tokenization/parsing
                    break;
            }
        }
        return $rendered;
    }
246025
def request(self, account, amount):
        
        return self._keeper.dispenser.request_tokens(amount, account)
1360593
def can_view(self, user):
        """"""
        return user in self.group.users or self.project.can_view(user)
769484
public function showAction()
    {
        $this->showParameters = $this->showParameters + $this->defaultTokenParameters;
        $this->showSnippets   = $this->getToken()->getShowSnippetNames();

        parent::showAction();
    }
659709
def terms_required(view_func):
    

    @wraps(view_func, assigned=available_attrs(view_func))
    def _wrapped_view(request, *args, **kwargs):
        """Method to wrap the view passed in"""
        # If user has not logged in, or if they have logged in and already agreed to the terms, let the view through
        if DJANGO_VERSION <= (2, 0, 0):
            user_authenticated = request.user.is_authenticated()
        else:
            user_authenticated = request.user.is_authenticated

        if not user_authenticated or not TermsAndConditions.get_active_terms_not_agreed_to(request.user):
            return view_func(request, *args, **kwargs)

        # Otherwise, redirect to terms accept
        current_path = request.path
        login_url_parts = list(urlparse(ACCEPT_TERMS_PATH))
        querystring = QueryDict(login_url_parts[4], mutable=True)
        querystring['returnTo'] = current_path
        login_url_parts[4] = querystring.urlencode(safe='/')
        return HttpResponseRedirect(urlunparse(login_url_parts))

    return _wrapped_view
753263
def render_view(parser, token):
    
    bits = token.split_contents()

    n = len(bits)
    if n < 2:
        raise TemplateSyntaxError("'%s' takes at least one view as argument")

    viewname = bits[1]

    kwargs = {}
    if n > 2:
        for bit in bits[2:]:
            match = kwarg_re.match(bit)
            if not match:
                raise TemplateSyntaxError("Malformed arguments to render_view tag")
            name, value = match.groups()
            if name:
                kwargs[name] = parser.compile_filter(value)

    return StringNode(viewname, kwargs)
56016
def show
      @user_collections = user_collections

      respond_to do |wants|
        wants.html { presenter && parent_presenter }
        wants.json do
          # load and authorize @curation_concern manually because it's skipped for html
          @curation_concern = _curation_concern_type.find(params[:id]) unless curation_concern
          authorize! :show, @curation_concern
          render :show, status: :ok
        end
        additional_response_formats(wants)
        wants.ttl do
          render body: presenter.export_as_ttl, content_type: 'text/turtle'
        end
        wants.jsonld do
          render body: presenter.export_as_jsonld, content_type: 'application/ld+json'
        end
        wants.nt do
          render body: presenter.export_as_nt, content_type: 'application/n-triples'
        end
      end
    end
401946
public function showCreditsView()
    {
        $this->subMenu['credits']['active'] = true;

        $credits = app(Credits::class)->latest();

        $backers = $credits['backers'];
        $contributors = $credits['contributors'];

        shuffle($backers);
        shuffle($contributors);

        return View::make('dashboard.settings.credits')
            ->withPageTitle(trans('dashboard.settings.credits.credits').' - '.trans('dashboard.dashboard'))
            ->withBackers($backers)
            ->withContributors($contributors)
            ->withSubMenu($this->subMenu);
    }
761164
def index():
    """"""
    identity = g.identity
    actions = {}
    for action in access.actions.values():
        actions[action.value] = DynamicPermission(action).allows(identity)

    if current_user.is_anonymous:
        return render_template("invenio_access/open.html",
                               actions=actions,
                               identity=identity)
    else:
        return render_template("invenio_access/limited.html",
                               message='',
                               actions=actions,
                               identity=identity)
948231
def initmobile_view(request):
    
    if 'username' in request.GET and 'password' in request.GET:
        username = request.GET['username']
        password = request.GET['password']
        user = auth.authenticate(username=username, password=password)
        if user is not None:
            if user.is_active:
                login(request, user)
    else:
        user = request.user
    response = {
        'username': user.username,
        'csrftoken': get_token(request),
    }
    if not user.has_usable_password():
        password = User.objects.make_random_password()
        user.set_password(password)
        user.save()
        response['password'] = password
    return HttpResponse(json.dumps(response))
209368
def require_user(self, *users, user=None):
        """"""

        # accept old-style single user keyword-argument as well
        if user:
            users = (*users, user)

        def _require_auth(view_func):
            @wraps(view_func)
            def wrapper(*args, **kwargs):
                """ Effective wrapper """
                username, out_token = self.authenticate()
                if username and out_token:
                    b64_token = base64.b64encode(out_token).decode('utf-8')
                    auth_data = 'Negotiate {0}'.format(b64_token)
                    if not users or username in users:
                        response = make_response(view_func(*args,
                                                           username=username,
                                                           **kwargs))
                    else:
                        response = Response(status=403)
                    response.headers['WWW-Authenticate'] = auth_data
                    return response
                return Response(
                    status=401,
                    headers={'WWW-Authenticate': 'Negotiate'},
                )

            return wrapper
        return _require_auth
1221318
def _FormatIPCPermToken(self, token_data):
    
    return {
        'user_id': token_data.user_identifier,
        'group_id': token_data.group_identifier,
        'creator_user_id': token_data.creator_user_identifier,
        'creator_group_id': token_data.creator_group_identifier,
        'access': token_data.access_mode}