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


Python current_user.username方法代码示例

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


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

示例1: before_request

# 需要导入模块: from flask_login import current_user [as 别名]
# 或者: from flask_login.current_user import username [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: portfolio_main

# 需要导入模块: from flask_login import current_user [as 别名]
# 或者: from flask_login.current_user import username [as 别名]
def portfolio_main():
    transactions = Trades.query.filter_by(user_id=current_user.username)
    if transactions.count() == 0:
        return redirect(url_for("main.get_started"))
    # For now pass only static positions, will update prices and other
    # data through javascript after loaded. This improves load time
    # and refresh speed.
    # Get positions and prepare df for delivery
    df = positions()
    df.set_index('trade_asset_ticker', inplace=True)
    df = df[df['is_currency'] == 0].sort_index(ascending=True)
    df = df.to_dict(orient='index')
    if df is None:
        return redirect(url_for("main.get_started"))
    return render_template("portfolio.html",
                           title="Portfolio Dashboard",
                           portfolio_data=df) 
开发者ID:pxsocs,项目名称:thewarden,代码行数:19,代码来源:routes.py

示例3: aclst

# 需要导入模块: from flask_login import current_user [as 别名]
# 或者: from flask_login.current_user import username [as 别名]
def aclst():
    list = []
    if request.method == "GET":

        tradeaccounts = Trades.query.filter_by(
            user_id=current_user.username).group_by(
            Trades.trade_account)

        accounts = AccountInfo.query.filter_by(
            user_id=current_user.username).group_by(
            AccountInfo.account_longname
        )

        q = request.args.get("term")
        for item in tradeaccounts:
            if q.upper() in item.trade_account.upper():
                list.append(item.trade_account)
        for item in accounts:
            if q.upper() in item.account_longname.upper():
                list.append(item.account_longname)

        list = json.dumps(list)

        return list 
开发者ID:pxsocs,项目名称:thewarden,代码行数:26,代码来源:routes.py

示例4: tradedetails

# 需要导入模块: from flask_login import current_user [as 别名]
# 或者: from flask_login.current_user import username [as 别名]
def tradedetails():
    if request.method == "GET":
        id = request.args.get("id")
        # if tradesonly is true then only look for buy and sells
        tradesonly = request.args.get("trades")
        df = pd.read_sql_table("trades", db.engine)
        # Filter only the trades for current user
        df = df[(df.user_id == current_user.username)]
        df = df[(df.trade_reference_id == id)]
        # Filter only buy and sells, ignore deposit / withdraw
        if tradesonly:
            df = df[(df.trade_operation == "B") | (df.trade_operation == "S")]
        # df['trade_date'] = pd.to_datetime(df['trade_date'])
        df.set_index("trade_reference_id", inplace=True)
        df.drop("user_id", axis=1, inplace=True)
        details = df.to_json()
        return details 
开发者ID:pxsocs,项目名称:thewarden,代码行数:19,代码来源:routes.py

示例5: regenerate_nav

# 需要导入模块: from flask_login import current_user [as 别名]
# 或者: from flask_login.current_user import username [as 别名]
def regenerate_nav():
    # re-generates the NAV on the background - delete First
    # the local NAV file so it's not used.
    # Check if there any trades in the database. If not, skip.
    transactions = Trades.query.filter_by(user_id=current_user.username)
    if transactions.count() == 0:
        return
    print("Regenerating NAV. Please wait...")
    # Delete all pricing history
    filename = os.path.join(current_path(), 'thewarden/pricing_engine/pricing_data/*.*')
    aa_files = glob.glob(filename)
    [os.remove(x) for x in aa_files]
    filename = os.path.join(current_path(), 'thewarden/nav_data/*.*')
    nav_files = glob.glob(filename)
    [os.remove(x) for x in nav_files]
    # Clear cache
    MWT()._caches = {}
    MWT()._timeouts = {}

    generatenav(current_user.username, force=True)
    logging.info("Change to database - generated new NAV") 
开发者ID:pxsocs,项目名称:thewarden,代码行数:23,代码来源:utils.py

示例6: delalltrades

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

    transactions = Trades.query.filter_by(
        user_id=current_user.username).order_by(Trades.trade_date)

    if transactions.count() == 0:
        return render_template("empty.html")

    if request.method == "GET":
        Trades.query.filter_by(user_id=current_user.username).delete()
        db.session.commit()
        regenerate_nav()
        flash("ALL TRANSACTIONS WERE DELETED", "danger")
        return redirect(url_for("main.home"))

    else:
        return redirect(url_for("main.home")) 
开发者ID:pxsocs,项目名称:thewarden,代码行数:19,代码来源:routes.py

示例7: delete_baccount

# 需要导入模块: from flask_login import current_user [as 别名]
# 或者: from flask_login.current_user import username [as 别名]
def delete_baccount(id):
    # type = account or address
    account = None
    type = request.args.get("type")
    if type == "account":
        account = AccountInfo.query.filter_by(
            user_id=current_user.username).filter_by(account_id=id)
    if type == "address":
        account = BitcoinAddresses.query.filter_by(
            user_id=current_user.username).filter_by(address_id=id)

    if (account is None) or (account.count() == 0):
        flash(f"{type.capitalize()} id: {id} not found. Nothing done.",
              "warning")
        return redirect(url_for("node.bitcoin_monitor"))
    if account.first().user_id != current_user.username:
        abort(403)

    account.delete()
    db.session.commit()
    flash(f"{type.capitalize()} deleted", "danger")
    return redirect(url_for("node.bitcoin_monitor")) 
开发者ID:pxsocs,项目名称:thewarden,代码行数:24,代码来源:routes.py

示例8: validate_account

# 需要导入模块: from flask_login import current_user [as 别名]
# 或者: from flask_login.current_user import username [as 别名]
def validate_account(self, account):
        # Only accept accounts already registered in trades or accountinfo
        found = False
        tradeaccounts = Trades.query.filter_by(user_id=current_user.username).group_by(
            Trades.trade_account
        )

        accounts = AccountInfo.query.filter_by(user_id=current_user.username).group_by(
            AccountInfo.account_longname
        )

        for item in tradeaccounts:
            if account.data.upper() in item.trade_account.upper():
                found = True
        for item in accounts:
            if account.data.upper() in item.account_longname.upper():
                found = True

        if not found:
            raise ValidationError(
                "Choose an existing account. If account is not registered, include first."
            ) 
开发者ID:pxsocs,项目名称:thewarden,代码行数:24,代码来源:forms.py

示例9: edit_profile_admin

# 需要导入模块: from flask_login import current_user [as 别名]
# 或者: from flask_login.current_user import username [as 别名]
def edit_profile_admin(id):
    user = User.query.get_or_404(id)
    form = EditProfileAdminForm(user=user)
    if form.validate_on_submit():
        user.email = form.email.data
        user.username = form.username.data
        user.confirmed = form.confirmed.data
        user.role = Role.query.get(form.role.data)
        user.name = form.name.data
        user.location = form.location.data
        user.about_me = form.about_me.data
        db.session.add(user)
        flash('The profile has been updated.')
        return redirect(url_for('.user', username=user.username))
    form.email.data = user.email
    form.username.data = user.username
    form.confirmed.data = user.confirmed
    form.role.data = user.role_id
    form.name.data = user.name
    form.location.data = user.location
    form.about_me.data = user.about_me
    return render_template('edit_profile.html', form=form, user=user) 
开发者ID:CircleCI-Public,项目名称:circleci-demo-python-flask,代码行数:24,代码来源:views.py

示例10: send_message

# 需要导入模块: from flask_login import current_user [as 别名]
# 或者: from flask_login.current_user import username [as 别名]
def send_message(recipient):
    """AUCR auth plugin function sends a message to an input recipient."""
    recipient_user = User.query.filter_by(username=recipient).first_or_404()
    form = MessageForm()
    if form.validate_on_submit():
        msg = Message(author=current_user, recipient=recipient_user, body=form.message.data)
        db.session.add(msg)
        db.session.commit()
        recipient_user.add_notification('unread_message_count', recipient_user.new_messages())
        db.session.commit()
        flash(_('Your message has been sent.'))
        return redirect(url_for('auth.user', username=recipient))
    else:
        for error in form.errors:
            flash(str(form.errors[error][0]), 'error')
    return render_template('send_message.html', form=form, recipient=recipient) 
开发者ID:AUCR,项目名称:AUCR,代码行数:18,代码来源:routes.py

示例11: register

# 需要导入模块: from flask_login import current_user [as 别名]
# 或者: from flask_login.current_user import username [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

示例12: qrcode

# 需要导入模块: from flask_login import current_user [as 别名]
# 或者: from flask_login.current_user import username [as 别名]
def qrcode():
    """Two factor auth qrcode page route."""
    user_name = User.query.filter_by(username=current_user.username).first()
    if user_name is None:
        render_error_page_template(404)

    # for added security, remove username from session
    # render qrcode for FreeTOTP
    url = pyqrcode.create(user_name.get_totp_uri())
    stream = BytesIO()
    url.svg(stream, scale=3)
    flash(user_name.otp_secret)
    return stream.getvalue(), 200, {
        'Content-Type': 'image/svg+xml',
        'Cache-Control': 'no-cache, no-store, must-revalidate',
        'Pragma': 'no-cache',
        'Expires': '0'} 
开发者ID:AUCR,项目名称:AUCR,代码行数:19,代码来源:routes.py

示例13: add_acl_subnet

# 需要导入模块: from flask_login import current_user [as 别名]
# 或者: from flask_login.current_user import username [as 别名]
def add_acl_subnet(subnet, acl, username):
        if not ViewIsps.query.filter_by(acl_name=acl).first():
            raise BadParam('acl not in database: %s' % acl, msg_ch=u'ACL在dnsdb中无记录')

        subnet, is_ipv6, start_ip, end_ip = format_subnet(subnet)

        q1 = (ViewAclSubnet.query.filter_by(origin_acl=acl, is_ipv6=is_ipv6).
              filter(ViewAclSubnet.start_ip <= start_ip).filter(ViewAclSubnet.end_ip >= start_ip).first())
        q2 = (ViewAclSubnet.query.filter_by(origin_acl=acl).
              filter(ViewAclSubnet.start_ip <= end_ip).filter(ViewAclSubnet.end_ip >= end_ip).first())
        if q1 or q2:
            raise BadParam('subnet overlap with subnet in this acl', msg_ch=u'与运营商中已有网段交叉')
        with db.session.begin(subtransactions=True):
            db.session.add(ViewAclSubnet(
                subnet=subnet,
                start_ip=start_ip,
                end_ip=end_ip,
                origin_acl=acl,
                now_acl=acl,
                update_user=username,
                is_ipv6=is_ipv6
            ))
        start_acl_deploy_job(username, [acl]) 
开发者ID:qunarcorp,项目名称:open_dnsdb,代码行数:25,代码来源:view_isp_acl.py

示例14: predicate_params

# 需要导入模块: from flask_login import current_user [as 别名]
# 或者: from flask_login.current_user import username [as 别名]
def predicate_params(param_meta=None, need_username=False):
    _param_meta = [] if param_meta is None else param_meta

    def _inner(func):
        @wraps(func)
        def _wrapper(*args, **kwargs):
            params = ParamValidator(_param_meta)

            kwargs.update(params)
            if need_username:
                kwargs['username'] = current_user.username
            return func(*args, **kwargs)

        return _wrapper

    return _inner 
开发者ID:qunarcorp,项目名称:open_dnsdb,代码行数:18,代码来源:decorators.py

示例15: add_web_opration_log

# 需要导入模块: from flask_login import current_user [as 别名]
# 或者: from flask_login.current_user import username [as 别名]
def add_web_opration_log(op_type, get_op_info):
    def _inner(func):
        @wraps(func)
        def _wrapper(*args, **kwargs):
            rtx_id = current_user.username
            try:
                ret = func(*args, **kwargs)
                op_domain, op_before, op_after = get_op_info(result=ret, *args, **kwargs)
                if op_domain is None:
                    op_domain = op_type
                OperationLogDal.insert_operation_log_with_dict(rtx_id, op_domain, op_type,
                                                               op_before,
                                                               op_after, 'ok')
            except Exception as ex:
                raise
            return ret

        return _wrapper

    return _inner 
开发者ID:qunarcorp,项目名称:open_dnsdb,代码行数:22,代码来源:decorators.py


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