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


Python current_user.id方法代码示例

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


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

示例1: contact

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

示例2: unsubscribe

# 需要导入模块: from flask_login import current_user [as 别名]
# 或者: from flask_login.current_user import id [as 别名]
def unsubscribe(alias_id):
    alias = Alias.get(alias_id)
    if not alias:
        flash("Incorrect link. Redirect you to the home page", "warning")
        return redirect(url_for("dashboard.index"))

    if alias.user_id != current_user.id:
        flash(
            "You don't have access to this page. Redirect you to the home page",
            "warning",
        )
        return redirect(url_for("dashboard.index"))

    # automatic unsubscribe, according to https://tools.ietf.org/html/rfc8058
    if request.method == "POST":
        alias.enabled = False
        flash(f"Alias {alias.email} has been blocked", "success")
        db.session.commit()

        return redirect(url_for("dashboard.index", highlight_alias_id=alias.id))
    else:  # ask user confirmation
        return render_template("dashboard/unsubscribe.html", alias=alias.email) 
开发者ID:simple-login,项目名称:app,代码行数:24,代码来源:unsubscribe.py

示例3: verify_mailbox_change

# 需要导入模块: from flask_login import current_user [as 别名]
# 或者: from flask_login.current_user import id [as 别名]
def verify_mailbox_change(user, mailbox, new_email):
    s = Signer(MAILBOX_SECRET)
    mailbox_id_signed = s.sign(str(mailbox.id)).decode()
    verification_url = (
        URL + "/dashboard/mailbox/confirm_change" + f"?mailbox_id={mailbox_id_signed}"
    )

    send_email(
        new_email,
        f"Confirm mailbox change on SimpleLogin",
        render(
            "transactional/verify-mailbox-change.txt",
            user=user,
            link=verification_url,
            mailbox_email=mailbox.email,
            mailbox_new_email=new_email,
        ),
        render(
            "transactional/verify-mailbox-change.html",
            user=user,
            link=verification_url,
            mailbox_email=mailbox.email,
            mailbox_new_email=new_email,
        ),
    ) 
开发者ID:simple-login,项目名称:app,代码行数:27,代码来源:mailbox_detail.py

示例4: cancel_mailbox_change_route

# 需要导入模块: from flask_login import current_user [as 别名]
# 或者: from flask_login.current_user import id [as 别名]
def cancel_mailbox_change_route(mailbox_id):
    mailbox = Mailbox.get(mailbox_id)
    if not mailbox or mailbox.user_id != current_user.id:
        flash("You cannot see this page", "warning")
        return redirect(url_for("dashboard.index"))

    if mailbox.new_email:
        mailbox.new_email = None
        db.session.commit()
        flash("Your mailbox change is cancelled", "success")
        return redirect(
            url_for("dashboard.mailbox_detail_route", mailbox_id=mailbox_id)
        )
    else:
        flash("You have no pending mailbox change", "warning")
        return redirect(
            url_for("dashboard.mailbox_detail_route", mailbox_id=mailbox_id)
        ) 
开发者ID:simple-login,项目名称:app,代码行数:20,代码来源:mailbox_detail.py

示例5: send_verification_email

# 需要导入模块: from flask_login import current_user [as 别名]
# 或者: from flask_login.current_user import id [as 别名]
def send_verification_email(user, mailbox):
    s = Signer(MAILBOX_SECRET)
    mailbox_id_signed = s.sign(str(mailbox.id)).decode()
    verification_url = (
        URL + "/dashboard/mailbox_verify" + f"?mailbox_id={mailbox_id_signed}"
    )
    send_email(
        mailbox.email,
        f"Please confirm your email {mailbox.email}",
        render(
            "transactional/verify-mailbox.txt",
            user=user,
            link=verification_url,
            mailbox_email=mailbox.email,
        ),
        render(
            "transactional/verify-mailbox.html",
            user=user,
            link=verification_url,
            mailbox_email=mailbox.email,
        ),
    ) 
开发者ID:simple-login,项目名称:app,代码行数:24,代码来源:mailbox.py

示例6: recovery_code_route

# 需要导入模块: from flask_login import current_user [as 别名]
# 或者: from flask_login.current_user import id [as 别名]
def recovery_code_route():
    if not current_user.two_factor_authentication_enabled():
        flash("you need to enable either TOTP or WebAuthn", "warning")
        return redirect(url_for("dashboard.index"))

    recovery_codes = RecoveryCode.query.filter_by(user_id=current_user.id).all()
    if request.method == "GET" and not recovery_codes:
        # user arrives at this page for the first time
        LOG.d("%s has no recovery keys, generate", current_user)
        RecoveryCode.generate(current_user)
        recovery_codes = RecoveryCode.query.filter_by(user_id=current_user.id).all()

    if request.method == "POST":
        RecoveryCode.generate(current_user)
        flash("New recovery codes generated", "success")
        return redirect(url_for("dashboard.recovery_code_route"))

    return render_template(
        "dashboard/recovery_code.html", recovery_codes=recovery_codes
    ) 
开发者ID:simple-login,项目名称:app,代码行数:22,代码来源:recovery_code.py

示例7: refused_email_route

# 需要导入模块: from flask_login import current_user [as 别名]
# 或者: from flask_login.current_user import id [as 别名]
def refused_email_route():
    # Highlight a refused email
    highlight_id = request.args.get("highlight_id")
    if highlight_id:
        highlight_id = int(highlight_id)

    email_logs: [EmailLog] = EmailLog.query.filter(
        EmailLog.user_id == current_user.id, EmailLog.refused_email_id != None
    ).order_by(EmailLog.id.desc()).all()

    # make sure the highlighted email_log is the first email_log
    highlight_index = None
    for ix, email_log in enumerate(email_logs):
        if email_log.id == highlight_id:
            highlight_index = ix
            break

    if highlight_index:
        email_logs.insert(0, email_logs.pop(highlight_index))

    return render_template("dashboard/refused_email.html", **locals()) 
开发者ID:simple-login,项目名称:app,代码行数:23,代码来源:refused_email.py

示例8: client_detail_advanced

# 需要导入模块: from flask_login import current_user [as 别名]
# 或者: from flask_login.current_user import id [as 别名]
def client_detail_advanced(client_id):
    form = AdvancedForm()
    client = Client.get(client_id)
    if not client:
        flash("no such app", "warning")
        return redirect(url_for("developer.index"))

    if client.user_id != current_user.id:
        flash("you cannot see this app", "warning")
        return redirect(url_for("developer.index"))

    if form.validate_on_submit():
        # delete client
        client_name = client.name
        Client.delete(client.id)
        db.session.commit()
        LOG.d("Remove client %s", client)
        flash(f"{client_name} has been deleted", "success")

        return redirect(url_for("developer.index"))

    return render_template(
        "developer/client_details/advanced.html", form=form, client=client
    ) 
开发者ID:simple-login,项目名称:app,代码行数:26,代码来源:client_detail.py

示例9: markCPEs

# 需要导入模块: from flask_login import current_user [as 别名]
# 或者: from flask_login.current_user import id [as 别名]
def markCPEs(self, cve):
    blacklist = tk.compile(db.getRules('blacklist'))
    whitelist = tk.compile(db.getRules('whitelist'))

    for conf in cve['vulnerable_configuration']:
        conf['list'] = 'none'
        conf['match'] = 'none'
        for w in whitelist:
            if w.match(conf['id']):
                conf['list'] = 'white'
                conf['match'] = w
        for b in blacklist:
            if b.match(conf['id']):
                conf['list'] = 'black'
                conf['match'] = b
    return cve 
开发者ID:flipkart-incubator,项目名称:watchdog,代码行数:18,代码来源:index.py

示例10: reply

# 需要导入模块: from flask_login import current_user [as 别名]
# 或者: from flask_login.current_user import id [as 别名]
def reply(id):
    comment = Comment.query.get_or_404(id)
    post = Post.query.get_or_404(comment.post_id)
    page = request.args.get('page', 1, type=int)
    form = ReplyForm()
    if form.validate_on_submit():
        reply_comment = Comment(body=form.body.data,
                                unread=True,
                                post=post,comment_type='reply',
                                reply_to=comment.author.nickname,
                                author=current_user._get_current_object())
        db.session.add(reply_comment)
        flash('你的回复已经发表。')
        return redirect(url_for('user.post', id=comment.post_id, page=page))
    return render_template('user/reply.html',
                           form=form,
                           comment=comment,
                           title='回复')

# 管理评论
# 恢复评论,即是将Comment模型的disabled的布尔值设为Flase 
开发者ID:Blackyukun,项目名称:Simpleblog,代码行数:23,代码来源:views.py

示例11: bookmark

# 需要导入模块: from flask_login import current_user [as 别名]
# 或者: from flask_login.current_user import id [as 别名]
def bookmark(book_id, book_format):
    bookmark_key = request.form["bookmark"]
    ub.session.query(ub.Bookmark).filter(and_(ub.Bookmark.user_id == int(current_user.id),
                                              ub.Bookmark.book_id == book_id,
                                              ub.Bookmark.format == book_format)).delete()
    if not bookmark_key:
        ub.session.commit()
        return "", 204

    lbookmark = ub.Bookmark(user_id=current_user.id,
                            book_id=book_id,
                            format=book_format,
                            bookmark_key=bookmark_key)
    ub.session.merge(lbookmark)
    ub.session.commit()
    return "", 201 
开发者ID:janeczku,项目名称:calibre-web,代码行数:18,代码来源:web.py

示例12: render_author_books

# 需要导入模块: from flask_login import current_user [as 别名]
# 或者: from flask_login.current_user import id [as 别名]
def render_author_books(page, author_id, order):
    entries, __, pagination = calibre_db.fill_indexpage(page,
                                                        db.Books,
                                                        db.Books.authors.any(db.Authors.id == author_id),
                                                        [order[0], db.Series.name, db.Books.series_index],
                                                        db.books_series_link,
                                                        db.Series)
    if entries is None or not len(entries):
        flash(_(u"Oops! Selected book title is unavailable. File does not exist or is not accessible"),
              category="error")
        return redirect(url_for("web.index"))

    author = calibre_db.session.query(db.Authors).get(author_id)
    author_name = author.name.replace('|', ',')

    author_info = None
    other_books = []
    if services.goodreads_support and config.config_use_goodreads:
        author_info = services.goodreads_support.get_author_info(author_name)
        other_books = services.goodreads_support.get_other_books(author_info, entries)

    return render_title_template('author.html', entries=entries, pagination=pagination, id=author_id,
                                 title=_(u"Author: %(name)s", name=author_name), author=author_info,
                                 other_books=other_books, page="author") 
开发者ID:janeczku,项目名称:calibre-web,代码行数:26,代码来源:web.py

示例13: search

# 需要导入模块: from flask_login import current_user [as 别名]
# 或者: from flask_login.current_user import id [as 别名]
def search():
    term = request.args.get("query")
    if term:
        entries = calibre_db.get_search_results(term)
        ids = list()
        for element in entries:
            ids.append(element.id)
        searched_ids[current_user.id] = ids
        return render_title_template('search.html',
                                     searchterm=term,
                                     adv_searchterm=term,
                                     entries=entries,
                                     title=_(u"Search"),
                                     page="search")
    else:
        return render_title_template('search.html',
                                     searchterm="",
                                     title=_(u"Search"),
                                     page="search") 
开发者ID:janeczku,项目名称:calibre-web,代码行数:21,代码来源:web.py

示例14: send_to_kindle

# 需要导入模块: from flask_login import current_user [as 别名]
# 或者: from flask_login.current_user import id [as 别名]
def send_to_kindle(book_id, book_format, convert):
    if not config.get_mail_server_configured():
        flash(_(u"Please configure the SMTP mail settings first..."), category="error")
    elif current_user.kindle_mail:
        result = send_mail(book_id, book_format, convert, current_user.kindle_mail, config.config_calibre_dir,
                           current_user.nickname)
        if result is None:
            flash(_(u"Book successfully queued for sending to %(kindlemail)s", kindlemail=current_user.kindle_mail),
                  category="success")
            ub.update_download(book_id, int(current_user.id))
        else:
            flash(_(u"Oops! There was an error sending this book: %(res)s", res=result), category="error")
    else:
        flash(_(u"Please update your profile with a valid Send to Kindle E-mail Address."), category="error")
    if "HTTP_REFERER" in request.environ:
        return redirect(request.environ["HTTP_REFERER"])
    else:
        return redirect(url_for('web.index'))


# ################################### Login Logout ################################################################## 
开发者ID:janeczku,项目名称:calibre-web,代码行数:23,代码来源:web.py

示例15: schedule_sync_mirror

# 需要导入模块: from flask_login import current_user [as 别名]
# 或者: from flask_login.current_user import id [as 别名]
def schedule_sync_mirror(mirror_id: int):
    # Check if mirror exists or throw 404
    found_mirror = PushMirror.query.filter_by(id=mirror_id, user=current_user).first_or_404()
    if not found_mirror.project_id:
        flask.flash('Project mirror is not created, cannot be synced', 'danger')
        return flask.redirect(flask.url_for('push_mirror.index.get_mirror'))
    task = sync_push_mirror.delay(mirror_id)
    log_task_pending(task, found_mirror, sync_push_mirror, InvokedByEnum.MANUAL)

    flask.flash('Sync has been started with UUID: {}'.format(task.id), 'success')
    return flask.redirect(flask.url_for('push_mirror.index.get_mirror')) 
开发者ID:Salamek,项目名称:gitlab-tools,代码行数:13,代码来源:index.py


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