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


Python current_user.is_authenticated方法代码示例

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


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

示例1: before_request

# 需要导入模块: from flask_login import current_user [as 别名]
# 或者: from flask_login.current_user import is_authenticated [as 别名]
def before_request():
    # Before any request at main, check if API Keys are set
    # But only if user is logged in.
    exclude_list = ["main.get_started", "main.importcsv", "main.csvtemplate"]
    if request.endpoint not in exclude_list:
        if current_user.is_authenticated:
            from thewarden.pricing_engine.pricing import api_keys_class
            api_keys_json = api_keys_class.loader()
            aa_apikey = api_keys_json['alphavantage']['api_key']
            if aa_apikey is None:
                logging.error("NO AA API KEY FOUND!")
                return render_template("welcome.html", title="Welcome")
            transactions = Trades.query.filter_by(
                user_id=current_user.username)
            if transactions.count() == 0:
                return redirect(url_for("main.get_started")) 
开发者ID:pxsocs,项目名称:thewarden,代码行数:18,代码来源:routes.py

示例2: home

# 需要导入模块: from flask_login import current_user [as 别名]
# 或者: from flask_login.current_user import is_authenticated [as 别名]
def home():
    if current_user.is_authenticated:
        return redirect(url_for("portfolio.portfolio_main"))
    else:
        form = LoginForm()
        if form.validate_on_submit():
            user = User.query.filter_by(email=form.email.data).first()
            if user and check_password_hash(user.password, form.password.data):
                login_user(user, remember=form.remember.data)
                # The get method below is actually very helpful
                # it returns None if empty. Better than using [] for a dictionary.
                next_page = request.args.get("next")  # get the original page
                if next_page:
                    return redirect(next_page)
                else:
                    return redirect(url_for("main.home"))
            else:
                flash("Login failed. Please check e-mail and password",
                      "danger")

        return render_template("index.html", title="Login", form=form) 
开发者ID:pxsocs,项目名称:thewarden,代码行数:23,代码来源:routes.py

示例3: contact

# 需要导入模块: from flask_login import current_user [as 别名]
# 或者: from flask_login.current_user import is_authenticated [as 别名]
def contact():

    form = ContactForm()

    if form.validate_on_submit():
        if current_user.is_authenticated:
            message = Contact(
                user_id=current_user.id,
                email=form.email.data,
                message=form.message.data,
            )
        else:
            message = Contact(user_id=0,
                              email=form.email.data,
                              message=form.message.data)

        db.session.add(message)
        db.session.commit()
        flash(f"Thanks for your message", "success")
        return redirect(url_for("main.home"))

    if current_user.is_authenticated:
        form.email.data = current_user.email
    return render_template("contact.html", form=form, title="Contact Form") 
开发者ID:pxsocs,项目名称:thewarden,代码行数:26,代码来源:routes.py

示例4: reset_request

# 需要导入模块: from flask_login import current_user [as 别名]
# 或者: from flask_login.current_user import is_authenticated [as 别名]
def reset_request():
    if current_user.is_authenticated:
        return redirect(url_for("main.home"))
    form = RequestResetForm()
    if form.validate_on_submit():
        user = User.query.filter_by(email=form.email.data).first()
        send_reset_email(user)
        flash(
            "An email has been sent with instructions to reset your" +
            " password.",
            "info",
        )
        return redirect(url_for("users.login"))
    return render_template("reset_request.html",
                           title="Reset Password",
                           form=form) 
开发者ID:pxsocs,项目名称:thewarden,代码行数:18,代码来源:routes.py

示例5: reset_token

# 需要导入模块: from flask_login import current_user [as 别名]
# 或者: from flask_login.current_user import is_authenticated [as 别名]
def reset_token(token):
    if current_user.is_authenticated:
        return redirect(url_for("main.home"))
    user = User.verify_reset_token(token)
    if user is None:
        flash("That is an invalid or expired token", "warning")
        return redirect(url_for("users.reset_request"))
    form = ResetPasswordForm()
    if form.validate_on_submit():
        hash = generate_password_hash(form.password.data)
        user.password = hash
        db.session.commit()
        flash("Your password has been updated! You are now able to log in",
              "success")
        return redirect(url_for("users.login"))
    return render_template("reset_token.html",
                           title="Reset Password",
                           form=form) 
开发者ID:pxsocs,项目名称:thewarden,代码行数:20,代码来源:routes.py

示例6: index

# 需要导入模块: from flask_login import current_user [as 别名]
# 或者: from flask_login.current_user import is_authenticated [as 别名]
def index():
    form = PostForm()
    if current_user.can(Permission.WRITE_ARTICLES) and \
            form.validate_on_submit():
        post = Post(body=form.body.data,
                    author=current_user._get_current_object())
        db.session.add(post)
        return redirect(url_for('.index'))
    page = request.args.get('page', 1, type=int)
    show_followed = False
    if current_user.is_authenticated:
        show_followed = bool(request.cookies.get('show_followed', ''))
    if show_followed:
        query = current_user.followed_posts
    else:
        query = Post.query
    pagination = query.order_by(Post.timestamp.desc()).paginate(
        page, per_page=current_app.config['CIRCULATE_POSTS_PER_PAGE'],
        error_out=False)
    posts = pagination.items
    return render_template('index.html', form=form, posts=posts,
                           show_followed=show_followed, pagination=pagination) 
开发者ID:CircleCI-Public,项目名称:circleci-demo-python-flask,代码行数:24,代码来源:views.py

示例7: require_api_auth

# 需要导入模块: from flask_login import current_user [as 别名]
# 或者: from flask_login.current_user import is_authenticated [as 别名]
def require_api_auth(f):
    @wraps(f)
    def decorated(*args, **kwargs):
        if current_user.is_authenticated:
            g.user = current_user
        else:
            api_code = request.headers.get("Authentication")
            api_key = ApiKey.get_by(code=api_code)

            if not api_key:
                return jsonify(error="Wrong api key"), 401

            # Update api key stats
            api_key.last_used = arrow.now()
            api_key.times += 1
            db.session.commit()

            g.user = api_key.user

        return f(*args, **kwargs)

    return decorated 
开发者ID:simple-login,项目名称:app,代码行数:24,代码来源:base.py

示例8: generate_full_query

# 需要导入模块: from flask_login import current_user [as 别名]
# 或者: from flask_login.current_user import is_authenticated [as 别名]
def generate_full_query(self, f):
    query = self.generate_minimal_query(f)
    if current_user.is_authenticated():
        if f['blacklistSelect'] == "on":
            regexes = db.getRules('blacklist')
            if len(regexes) != 0:
                exp = "^(?!" + "|".join(regexes) + ")"
                query.append({'$or': [{'vulnerable_configuration': re.compile(exp)},
                                      {'vulnerable_configuration': {'$exists': False}},
                                      {'vulnerable_configuration': []} ]})
        if f['whitelistSelect'] == "hide":
            regexes = db.getRules('whitelist')
            if len(regexes) != 0:
                exp = "^(?!" + "|".join(regexes) + ")"
                query.append({'$or': [{'vulnerable_configuration': re.compile(exp)},
                                      {'vulnerable_configuration': {'$exists': False}},
                                      {'vulnerable_configuration': []} ]})
        if f['unlistedSelect'] == "hide":
            wlregexes = tk.compile(db.getRules('whitelist'))
            blregexes = tk.compile(db.getRules('blacklist'))
            query.append({'$or': [{'vulnerable_configuration': {'$in': wlregexes}},
                                  {'vulnerable_configuration': {'$in': blregexes}}]})
    return query 
开发者ID:flipkart-incubator,项目名称:watchdog,代码行数:25,代码来源:index.py

示例9: admin

# 需要导入模块: from flask_login import current_user [as 别名]
# 或者: from flask_login.current_user import is_authenticated [as 别名]
def admin(self):
    if Configuration.loginRequired():
        if not current_user.is_authenticated():
            return render_template('login.html')
    else:
        person = User.get("_dummy_", self.auth_handler)
        login_user(person)
    output = None
    if os.path.isfile(Configuration.getUpdateLogFile()):
        with open(Configuration.getUpdateLogFile()) as updateFile:
            separator="==========================\n"
            output=updateFile.read().split(separator)[-2:]
            output=separator+separator.join(output)
    return render_template('admin.html', status="default", **self.adminInfo(output))


  # /admin/change_pass 
开发者ID:flipkart-incubator,项目名称:watchdog,代码行数:19,代码来源:index.py

示例10: get_download_link

# 需要导入模块: from flask_login import current_user [as 别名]
# 或者: from flask_login.current_user import is_authenticated [as 别名]
def get_download_link(book_id, book_format, client):
    book_format = book_format.split(".")[0]
    book = calibre_db.get_filtered_book(book_id)
    if book:
        data1 = calibre_db.get_book_format(book.id, book_format.upper())
    else:
        abort(404)
    if data1:
        # collect downloaded books only for registered user and not for anonymous user
        if current_user.is_authenticated:
            ub.update_download(book_id, int(current_user.id))
        file_name = book.title
        if len(book.authors) > 0:
            file_name = book.authors[0].name + '_' + file_name
        file_name = get_valid_filename(file_name)
        headers = Headers()
        headers["Content-Type"] = mimetypes.types_map.get('.' + book_format, "application/octet-stream")
        headers["Content-Disposition"] = "attachment; filename=%s.%s; filename*=UTF-8''%s.%s" % (
            quote(file_name.encode('utf-8')), book_format, quote(file_name.encode('utf-8')), book_format)
        return do_download_file(book, book_format, client, data1, headers)
    else:
        abort(404) 
开发者ID:janeczku,项目名称:calibre-web,代码行数:24,代码来源:helper.py

示例11: _configuration_result

# 需要导入模块: from flask_login import current_user [as 别名]
# 或者: from flask_login.current_user import is_authenticated [as 别名]
def _configuration_result(error_flash=None, gdriveError=None):
    gdrive_authenticate = not is_gdrive_ready()
    gdrivefolders = []
    if gdriveError is None:
        gdriveError = gdriveutils.get_error_text()
    if gdriveError:
        gdriveError = _(gdriveError)
    else:
        # if config.config_use_google_drive and\
        if not gdrive_authenticate and gdrive_support:
            gdrivefolders = gdriveutils.listRootFolders()

    show_back_button = current_user.is_authenticated
    show_login_button = config.db_configured and not current_user.is_authenticated
    if error_flash:
        config.load()
        flash(error_flash, category="error")
        show_login_button = False

    return render_title_template("config_edit.html", config=config, provider=oauthblueprints,
                                 show_back_button=show_back_button, show_login_button=show_login_button,
                                 show_authenticate_google_drive=gdrive_authenticate,
                                 gdriveError=gdriveError, gdrivefolders=gdrivefolders, feature_support=feature_support,
                                 title=_(u"Basic Configuration"), page="config") 
开发者ID:janeczku,项目名称:calibre-web,代码行数:26,代码来源:admin.py

示例12: check_valid_login

# 需要导入模块: from flask_login import current_user [as 别名]
# 或者: from flask_login.current_user import is_authenticated [as 别名]
def check_valid_login():
    user = db.session.query(User).first()

    if any([request.endpoint.startswith('static'),
            current_user.is_authenticated,
            getattr(app.view_functions[request.endpoint],
                    'is_public', False)]):
        return

    elif user is None:
        return redirect(url_for('user_system.register'))

    else:
        return redirect(url_for('user_system.login'))


# this was a fix to make sure images stored in the cache are deleted when
# a new image is uploaded 
开发者ID:rmountjoy92,项目名称:VectorCloud,代码行数:20,代码来源:routes.py

示例13: finish_signup

# 需要导入模块: from flask_login import current_user [as 别名]
# 或者: from flask_login.current_user import is_authenticated [as 别名]
def finish_signup():
    form = UserInfoForm(request.form)
    if form.validate():
        if current_user.is_authenticated:
            current_user.user.username = form.username.data
            return redirect('/')
        else:
            user = User(email=form.email.data, username=form.username.data,
                        is_email_confirmed=True)
            user.save()
            bookmark = Bookmark(user=user,
                                title=u"%s 的收藏夹" % user.username,
                                is_default=True)
            bookmark.save()
            user_mixin = LoginManagerUser(user)
            login_user(user_mixin)
            flash(u"登录成功", category='info')
            if 'email' in session:
                del (session['email'])
            return redirect('/')
    return render_template('users/finish_signup.html',
                           form=form) 
开发者ID:DoubleCiti,项目名称:daimaduan.com,代码行数:24,代码来源:sites.py

示例14: register

# 需要导入模块: from flask_login import current_user [as 别名]
# 或者: from flask_login.current_user import is_authenticated [as 别名]
def register():
    """AUCR auth plugin user register flask blueprint."""
    if current_user.is_authenticated:
        return redirect(url_for('main.index'))
    form = RegistrationForm()
    if request.method == "POST":
        form = RegistrationForm(request.form)
        if form.validate_on_submit():
            user_name = User.__call__(username=form.username.data, email=form.email.data,  website=form.website.data,
                                      affiliation=form.affiliation.data, country=form.country.data)
            user_name.set_password(form.password.data)
            db.session.add(user_name)
            db.session.commit()
            user_group = Group.__call__(groups_id=2, username_id=user_name.id)
            db.session.add(user_group)
            db.session.commit()
            session['username'] = user_name.username
            flash(_('Congratulations, you are now a registered user!'))
            return redirect(url_for('auth.login'))
        else:
            for error in form.errors:
                flash(str(form.errors[error][0]), 'error')
            return redirect(url_for('auth.register'))
    return render_template('register.html', title=_('Register'), form=form) 
开发者ID:AUCR,项目名称:AUCR,代码行数:26,代码来源:routes.py

示例15: reset_password

# 需要导入模块: from flask_login import current_user [as 别名]
# 或者: from flask_login.current_user import is_authenticated [as 别名]
def reset_password(token):
    """User reset password with token AUCR auth plugin blueprint."""
    if current_user.is_authenticated:
        return redirect(url_for('index'))
    user_name = User.verify_reset_password_token(token)
    if not user_name:
        return redirect(url_for('index'))
    form = ResetPasswordForm()
    if form.validate_on_submit():
        user_name.set_password(form.password.data)
        db.session.commit()
        flash(_('Your password has been reset.'))
        return redirect(url_for('auth.login'))
    else:
        for error in form.errors:
            flash(str(form.errors[error][0]), 'error')
        return render_template('reset_password.html', form=form) 
开发者ID:AUCR,项目名称:AUCR,代码行数:19,代码来源:routes.py


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