当前位置: 首页>>代码示例>>Python>>正文


Python current_user.is_anonymous方法代码示例

本文整理汇总了Python中flask_login.current_user.is_anonymous方法的典型用法代码示例。如果您正苦于以下问题:Python current_user.is_anonymous方法的具体用法?Python current_user.is_anonymous怎么用?Python current_user.is_anonymous使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在flask_login.current_user的用法示例。


在下文中一共展示了current_user.is_anonymous方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: feed_shelf

# 需要导入模块: from flask_login import current_user [as 别名]
# 或者: from flask_login.current_user import is_anonymous [as 别名]
def feed_shelf(book_id):
    off = request.args.get("offset") or 0
    if current_user.is_anonymous:
        shelf = ub.session.query(ub.Shelf).filter(ub.Shelf.is_public == 1,
                                                  ub.Shelf.id == book_id).first()
    else:
        shelf = ub.session.query(ub.Shelf).filter(or_(and_(ub.Shelf.user_id == int(current_user.id),
                                                           ub.Shelf.id == book_id),
                                                      and_(ub.Shelf.is_public == 1,
                                                           ub.Shelf.id == book_id))).first()
    result = list()
    # user is allowed to access shelf
    if shelf:
        books_in_shelf = ub.session.query(ub.BookShelf).filter(ub.BookShelf.shelf == book_id).order_by(
            ub.BookShelf.order.asc()).all()
        for book in books_in_shelf:
            cur_book = calibre_db.get_book(book.book_id)
            result.append(cur_book)
    pagination = Pagination((int(off) / (int(config.config_books_per_page)) + 1), config.config_books_per_page,
                            len(result))
    return render_xml_template('feed.xml', entries=result, pagination=pagination) 
开发者ID:janeczku,项目名称:calibre-web,代码行数:23,代码来源:opds.py

示例2: on_api_command

# 需要导入模块: from flask_login import current_user [as 别名]
# 或者: from flask_login.current_user import is_anonymous [as 别名]
def on_api_command(self, command, data):
        """Route API requests to their implementations."""
        if current_user.is_anonymous():
            return "Insufficient rights", 403

        self._logger.debug("API command received: %s", data)

        if (command == "deleteExcludeRegion"):
            return self._handleDeleteExcludeRegion(data.get("id"))
        else:
            regionType = data.get("type")

            if (regionType == "RectangularRegion"):
                region = RectangularRegion(**data)
            elif (regionType == "CircularRegion"):
                region = CircularRegion(**data)
            else:
                return "Invalid type", 400

            if (command == "addExcludeRegion"):
                return self._handleAddExcludeRegion(region)
            elif (command == "updateExcludeRegion"):
                return self._handleUpdateExcludeRegion(region)

            return "Invalid command", 400 
开发者ID:bradcfisher,项目名称:OctoPrint-ExcludeRegionPlugin,代码行数:27,代码来源:__init__.py

示例3: session

# 需要导入模块: from flask_login import current_user [as 别名]
# 或者: from flask_login.current_user import is_anonymous [as 别名]
def session(self):
        if not hasattr(self, '_oauth_session'):
            if not current_user.is_anonymous:
                kwargs = {
                    'token': current_user.token,
                }
                if self.refresh_url is not None:
                    kwargs['auto_refresh_url'] = self.refresh_url
                    kwargs['token_updater'] = token_saver
                    kwargs['auto_refresh_kwargs'] = {
                        'client_id': self.client_id,
                        'client_secret': self.client_secret,
                    }
                current_app.logger.debug(u"Creating a new OAuth2Session for "
                                         u"'{}'".format(current_user))
                self._oauth_session = OAuth2Session(self.client_id, **kwargs)
        return self._oauth_session 
开发者ID:paxswill,项目名称:evesrp,代码行数:19,代码来源:oauth.py

示例4: project_edit

# 需要导入模块: from flask_login import current_user [as 别名]
# 或者: from flask_login.current_user import is_anonymous [as 别名]
def project_edit(project_id):
    project = Project.query.filter_by(id=project_id).first_or_404()
    event = project.event
    starred = IsProjectStarred(project, current_user)
    allow_edit = starred or (not current_user.is_anonymous and current_user.is_admin)
    if not allow_edit:
        flash('You do not have access to edit this project.', 'warning')
        return project_action(project_id, None)
    form = ProjectForm(obj=project, next=request.args.get('next'))
    form.category_id.choices = [(c.id, c.name) for c in project.categories_all()]
    form.category_id.choices.insert(0, (-1, ''))
    if form.validate_on_submit():
        del form.id
        form.populate_obj(project)
        project.update()
        db.session.add(project)
        db.session.commit()
        cache.clear()
        flash('Project updated.', 'success')
        project_action(project_id, 'update', False)
        return redirect(url_for('public.project', project_id=project.id))
    return render_template('public/projectedit.html', current_event=event, project=project, form=form) 
开发者ID:hackathons-ftw,项目名称:dribdat,代码行数:24,代码来源:views.py

示例5: project_post

# 需要导入模块: from flask_login import current_user [as 别名]
# 或者: from flask_login.current_user import is_anonymous [as 别名]
def project_post(project_id):
    project = Project.query.filter_by(id=project_id).first_or_404()
    event = project.event
    starred = IsProjectStarred(project, current_user)
    allow_edit = starred or (not current_user.is_anonymous and current_user.is_admin)
    if not allow_edit:
        flash('You do not have access to edit this project.', 'warning')
        return project_action(project_id, None)
    form = ProjectPost(obj=project, next=request.args.get('next'))
    form.progress.choices = projectProgressList(event.has_started or event.has_finished)
    if not form.note.data:
        form.note.data = "---\n`%s` " % datetime.utcnow().strftime("%d.%m.%Y %H:%M")
    if form.validate_on_submit():
        del form.id
        form.populate_obj(project)
        project.longtext += "\n\n" + form.note.data
        project.update()
        db.session.add(project)
        db.session.commit()
        cache.clear()
        flash('Project updated.', 'success')
        project_action(project_id, 'update', False)
        return redirect(url_for('public.project', project_id=project.id))
    return render_template('public/projectpost.html', current_event=event, project=project, form=form) 
开发者ID:hackathons-ftw,项目名称:dribdat,代码行数:26,代码来源:views.py

示例6: project_action

# 需要导入模块: from flask_login import current_user [as 别名]
# 或者: from flask_login.current_user import is_anonymous [as 别名]
def project_action(project_id, of_type, as_view=True, then_redirect=False):
    project = Project.query.filter_by(id=project_id).first_or_404()
    event = project.event
    if of_type is not None:
        ProjectActivity(project, of_type, current_user)
    if not as_view:
        return True
    starred = IsProjectStarred(project, current_user)
    allow_edit = starred or (not current_user.is_anonymous and current_user.is_admin)
    allow_edit = allow_edit and not event.lock_editing
    project_stars = GetProjectTeam(project)
    latest_activity = project.latest_activity()
    if then_redirect:
        return redirect(url_for('public.project', project_id=project.id))
    return render_template('public/project.html', current_event=event, project=project,
        project_starred=starred, project_stars=project_stars,
        allow_edit=allow_edit, latest_activity=latest_activity) 
开发者ID:hackathons-ftw,项目名称:dribdat,代码行数:19,代码来源:views.py

示例7: getWsToken

# 需要导入模块: from flask_login import current_user [as 别名]
# 或者: from flask_login.current_user import is_anonymous [as 别名]
def getWsToken():
	publicKey = None
	userLogged = settings().get(["cloudSlicer", "loggedUser"])

	if userLogged:
		if current_user.is_anonymous or current_user.get_name() != userLogged:
			abort(401, "Unauthorized Access")

		user = userManager.findUser(userLogged)
		if user:
			publicKey = user.publicKey
		else:
			abort(403, 'Invalid Logged User')

	return Response(
		json.dumps({
		'ws_token': create_ws_token(publicKey)
		}),
		headers= {
			'Access-Control-Allow-Origin': '*'
		} if settings().getBoolean(['api', 'allowCrossOrigin']) else None
	) 
开发者ID:AstroPrint,项目名称:AstroBox,代码行数:24,代码来源:__init__.py

示例8: get

# 需要导入模块: from flask_login import current_user [as 别名]
# 或者: from flask_login.current_user import is_anonymous [as 别名]
def get(self, server=None, name=None):
        """Tells if a 'backup' file is present

        **GET** method provided by the webservice.

        :param server: Which server to collect data from when in multi-agent
                       mode
        :type server: str

        :param name: The client we are working on
        :type name: str

        :returns: True if the file is found
        """
        if not name:
            self.abort(400, 'Missing options')
        # Manage ACL
        if not current_user.is_anonymous and \
                not current_user.acl.is_admin() and \
                not current_user.acl.is_client_allowed(name, server):
            self.abort(403, 'You are not allowed to access this client')
        try:
            return {'is_server_backup': bui.client.is_server_backup(name, server)}
        except BUIserverException as e:
            self.abort(500, str(e)) 
开发者ID:ziirish,项目名称:burp-ui,代码行数:27,代码来源:backup.py

示例9: check_acl

# 需要导入模块: from flask_login import current_user [as 别名]
# 或者: from flask_login.current_user import is_anonymous [as 别名]
def check_acl(func):
    """Custom decorator to check if the ACL are in use or not"""
    @wraps(func)
    def decorated_view(*args, **kwargs):
        if request.method in EXEMPT_METHODS:  # pragma: no cover
            return func(*args, **kwargs)
        # 'func' is a Flask.view.MethodView so we have access to some special
        # params
        cls = func.view_class
        login_required = getattr(cls, 'login_required', True)
        if (bui.auth != 'none' and
                login_required and
                not bui.config.get('LOGIN_DISABLED', False)):
            if current_user.is_anonymous:
                abort(403)
        return func(*args, **kwargs)
    return decorated_view 
开发者ID:ziirish,项目名称:burp-ui,代码行数:19,代码来源:__init__.py

示例10: delete

# 需要导入模块: from flask_login import current_user [as 别名]
# 或者: from flask_login.current_user import is_anonymous [as 别名]
def delete(self):
        """Make a client/server visible again

        **DELETE** method provided by the webservice.
        """
        args = self.parser.parse_args()
        if bui.config['WITH_SQL'] and not bui.config['BUI_DEMO'] and not current_user.is_anonymous:
            from ..ext.sql import db
            from ..models import Hidden
            hide = Hidden.query.filter_by(client=(args.get('client') or None), server=(args.get('server') or None), user=current_user.name).first()
            if hide:
                db.session.delete(hide)
                try:
                    db.session.commit()
                except:  # pragma: no cover
                    db.session.rollback()
                    self.abort(500, 'Internal server error')
        return None, 204 
开发者ID:ziirish,项目名称:burp-ui,代码行数:20,代码来源:prefs.py

示例11: post

# 需要导入模块: from flask_login import current_user [as 别名]
# 或者: from flask_login.current_user import is_anonymous [as 别名]
def post(self, server=None, client=None, conf=None):
        """Saves a given client configuration"""
        if not current_user.is_anonymous and \
                current_user.acl.is_moderator() and \
                not current_user.acl.is_client_rw(client, server):
            self.abort(403, 'You don\'t have rights on this server')

        args = self.parser_post.parse_args()
        template = args.get('template', False)
        statictemplate = args.get('statictemplate', False)
        noti = bui.client.store_conf_cli(request.form, client, conf, template, statictemplate, server)
        # clear cache
        cache.clear()
        # clear client-side cache through the _extra META variable
        try:
            _extra = session.get('_extra', g.now)
            _extra = int(_extra)
        except ValueError:
            _extra = 0
        session['_extra'] = '{}'.format(_extra + 1)

        bui.audit.logger.info(f'updated client configuration {client} ({conf})', server=server)
        return {'notif': noti} 
开发者ID:ziirish,项目名称:burp-ui,代码行数:25,代码来源:settings.py

示例12: settings

# 需要导入模块: from flask_login import current_user [as 别名]
# 或者: from flask_login.current_user import is_anonymous [as 别名]
def settings(server=None, conf=None):
    # Only the admin can edit the configuration
    if not current_user.is_anonymous and not current_user.acl.is_admin() and \
            not current_user.acl.is_moderator():
        abort(403)
    if not conf:
        try:
            conf = quote(request.args.get('conf'), safe='')
            if conf:
                return redirect(url_for('.settings', server=server, conf=conf))
        except:
            pass
    server = server or request.args.get('serverName')
    return render_template(
        'settings.html',
        settings=True,
        is_admin=current_user.acl.is_admin(),
        is_moderator=current_user.acl.is_moderator(),
        server=server,
        conf=conf,
        ng_controller='ConfigCtrl'
    ) 
开发者ID:ziirish,项目名称:burp-ui,代码行数:24,代码来源:routes.py

示例13: revert

# 需要导入模块: from flask_login import current_user [as 别名]
# 或者: from flask_login.current_user import is_anonymous [as 别名]
def revert():
    cname = to_canonical(request.form.get('name'))
    commit = request.form.get('commit')
    message = request.form.get('message', "Reverting %s" % cname)

    if not current_app.config.get('ALLOW_ANON') and current_user.is_anonymous:
        return dict(error=True, message="Anonymous posting not allowed"), 403

    if cname in current_app.config.get('WIKI_LOCKED_PAGES'):
        return dict(error=True, message="Page is locked"), 403

    try:
        sha = g.current_wiki.get_page(cname).revert(commit,
                                                    message=message,
                                                    username=current_user.username,
                                                    email=current_user.email)
    except PageNotFound as e:
        return dict(error=True, message=e.message), 404

    if sha:
        flash("Page reverted")

    return dict(sha=sha.decode()) 
开发者ID:scragg0x,项目名称:realms-wiki,代码行数:25,代码来源:views.py

示例14: reset_password_request

# 需要导入模块: from flask_login import current_user [as 别名]
# 或者: from flask_login.current_user import is_anonymous [as 别名]
def reset_password_request():
    """Respond to existing user's request to reset their password."""
    badge_list = []
    if not current_user.is_anonymous:
        return redirect(url_for('main.index'))
    form = RequestResetPasswordForm()
    if form.validate_on_submit():
        user = User.query.filter_by(email=form.email.data).first()
        if user:
            token = user.generate_password_reset_token()
            reset_link = url_for(
                'account.reset_password', token=token, _external=True)
            send_email(
                recipient=user.email,
                subject='Reset Your Password',
                template='account/email/reset_password',
                user=user,
                reset_link=reset_link,
                next=request.args.get('next'))
        flash(
            'A password reset link has been sent to {}.'.format(
                form.email.data), 'warning')
        return redirect(url_for('account.login'))
    return render_template(
        'account/reset_password.html', form=form, badge_list=badge_list) 
开发者ID:gita,项目名称:BhagavadGita,代码行数:27,代码来源:views.py

示例15: reset_password

# 需要导入模块: from flask_login import current_user [as 别名]
# 或者: from flask_login.current_user import is_anonymous [as 别名]
def reset_password(token):
    """Reset an existing user's password."""
    badge_list = []
    if not current_user.is_anonymous:
        return redirect(url_for('main.index'))
    form = ResetPasswordForm()
    if form.validate_on_submit():
        user = User.query.filter_by(email=form.email.data).first()
        if user is None:
            flash('Invalid email address.', 'form-error')
            return redirect(url_for('main.index'))
        if user.reset_password(token, form.new_password.data):
            flash('Your password has been updated.', 'form-success')
            return redirect(url_for('account.login'))
        else:
            flash('The password reset link is invalid or has expired.',
                  'form-error')
            return redirect(url_for('main.index'))
    return render_template(
        'account/reset_password.html', form=form, badge_list=badge_list) 
开发者ID:gita,项目名称:BhagavadGita,代码行数:22,代码来源:views.py


注:本文中的flask_login.current_user.is_anonymous方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。