Python flask_login.current_user.id() Examples
The following are 30
code examples of flask_login.current_user.id().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
flask_login.current_user
, or try the search function
.
Example #1
Source File: web.py From calibre-web with GNU General Public License v3.0 | 6 votes |
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 ##################################################################
Example #2
Source File: mailbox.py From app with MIT License | 6 votes |
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, ), )
Example #3
Source File: client_detail.py From app with MIT License | 6 votes |
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 )
Example #4
Source File: index.py From watchdog with Apache License 2.0 | 6 votes |
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
Example #5
Source File: web.py From calibre-web with GNU General Public License v3.0 | 6 votes |
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
Example #6
Source File: web.py From calibre-web with GNU General Public License v3.0 | 6 votes |
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")
Example #7
Source File: web.py From calibre-web with GNU General Public License v3.0 | 6 votes |
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")
Example #8
Source File: mailbox_detail.py From app with MIT License | 6 votes |
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) )
Example #9
Source File: mailbox_detail.py From app with MIT License | 6 votes |
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, ), )
Example #10
Source File: unsubscribe.py From app with MIT License | 6 votes |
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)
Example #11
Source File: recovery_code.py From app with MIT License | 6 votes |
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 )
Example #12
Source File: refused_email.py From app with MIT License | 6 votes |
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())
Example #13
Source File: views.py From Simpleblog with MIT License | 6 votes |
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
Example #14
Source File: routes.py From thewarden with MIT License | 6 votes |
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")
Example #15
Source File: oauth_bb.py From calibre-web with GNU General Public License v3.0 | 5 votes |
def get_oauth_status(): status = [] query = ub.session.query(ub.OAuth).filter_by( user_id=current_user.id, ) try: oauths = query.all() for oauth_entry in oauths: status.append(int(oauth_entry.provider)) return status except NoResultFound: return None
Example #16
Source File: web.py From calibre-web with GNU General Public License v3.0 | 5 votes |
def toggle_read(book_id): if not config.config_read_column: book = ub.session.query(ub.ReadBook).filter(and_(ub.ReadBook.user_id == int(current_user.id), ub.ReadBook.book_id == book_id)).first() if book: if book.read_status == ub.ReadBook.STATUS_FINISHED: book.read_status = ub.ReadBook.STATUS_UNREAD else: book.read_status = ub.ReadBook.STATUS_FINISHED else: readBook = ub.ReadBook(user_id=current_user.id, book_id = book_id) readBook.read_status = ub.ReadBook.STATUS_FINISHED book = readBook if not book.kobo_reading_state: kobo_reading_state = ub.KoboReadingState(user_id=current_user.id, book_id=book_id) kobo_reading_state.current_bookmark = ub.KoboBookmark() kobo_reading_state.statistics = ub.KoboStatistics() book.kobo_reading_state = kobo_reading_state ub.session.merge(book) ub.session.commit() else: try: calibre_db.update_title_sort(config) book = calibre_db.get_filtered_book(book_id) read_status = getattr(book, 'custom_column_' + str(config.config_read_column)) if len(read_status): read_status[0].value = not read_status[0].value calibre_db.session.commit() else: cc_class = db.cc_classes[config.config_read_column] new_cc = cc_class(value=1, book=book_id) calibre_db.session.add(new_cc) calibre_db.session.commit() except (KeyError, AttributeError): log.error(u"Custom Column No.%d is not exisiting in calibre database", config.config_read_column) except OperationalError as e: calibre_db.session.rollback() log.error(u"Read status could not set: %e", e) return ""
Example #17
Source File: oauth_bb.py From calibre-web with GNU General Public License v3.0 | 5 votes |
def register_user_with_oauth(user=None): all_oauth = {} for oauth_key in oauth_check.keys(): if str(oauth_key) + '_oauth_user_id' in session and session[str(oauth_key) + '_oauth_user_id'] != '': all_oauth[oauth_key] = oauth_check[oauth_key] if len(all_oauth.keys()) == 0: return if user is None: flash(_(u"Register with %(provider)s", provider=", ".join(list(all_oauth.values()))), category="success") else: for oauth_key in all_oauth.keys(): # Find this OAuth token in the database, or create it query = ub.session.query(ub.OAuth).filter_by( provider=oauth_key, provider_user_id=session[str(oauth_key) + "_oauth_user_id"], ) try: oauth_key = query.one() oauth_key.user_id = user.id except NoResultFound: # no found, return error return try: ub.session.commit() except Exception as e: log.exception(e) ub.session.rollback()
Example #18
Source File: oauth_bb.py From calibre-web with GNU General Public License v3.0 | 5 votes |
def google_logged_in(blueprint, token): if not token: flash(_(u"Failed to log in with Google."), category="error") return False resp = blueprint.session.get("/oauth2/v2/userinfo") if not resp.ok: flash(_(u"Failed to fetch user info from Google."), category="error") return False google_info = resp.json() google_user_id = str(google_info["id"]) return oauth_update_token(str(oauthblueprints[1]['id']), token, google_user_id)
Example #19
Source File: oauth_bb.py From calibre-web with GNU General Public License v3.0 | 5 votes |
def github_logged_in(blueprint, token): if not token: flash(_(u"Failed to log in with GitHub."), category="error") return False resp = blueprint.session.get("/user") if not resp.ok: flash(_(u"Failed to fetch user info from GitHub."), category="error") return False github_info = resp.json() github_user_id = str(github_info["id"]) return oauth_update_token(str(oauthblueprints[0]['id']), token, github_user_id)
Example #20
Source File: web.py From calibre-web with GNU General Public License v3.0 | 5 votes |
def render_publisher_books(page, book_id, order): publisher = calibre_db.session.query(db.Publishers).filter(db.Publishers.id == book_id).first() if publisher: entries, random, pagination = calibre_db.fill_indexpage(page, db.Books, db.Books.publishers.any(db.Publishers.id == book_id), [db.Series.name, order[0], db.Books.series_index], db.books_series_link, db.Series) return render_title_template('index.html', random=random, entries=entries, pagination=pagination, id=book_id, title=_(u"Publisher: %(name)s", name=publisher.name), page="publisher") else: abort(404)
Example #21
Source File: web.py From calibre-web with GNU General Public License v3.0 | 5 votes |
def before_request(): if current_user.is_authenticated: confirm_login() g.user = current_user g.allow_registration = config.config_public_reg g.allow_anonymous = config.config_anonbrowse g.allow_upload = config.config_uploading g.current_theme = config.config_theme g.config_authors_max = config.config_authors_max g.shelves_access = ub.session.query(ub.Shelf).filter( or_(ub.Shelf.is_public == 1, ub.Shelf.user_id == current_user.id)).order_by(ub.Shelf.name).all() if not config.db_configured and request.endpoint not in ( 'admin.basic_configuration', 'login') and '/static/' not in request.path: return redirect(url_for('admin.basic_configuration'))
Example #22
Source File: web.py From calibre-web with GNU General Public License v3.0 | 5 votes |
def load_user(user_id): return ub.session.query(ub.User).filter(ub.User.id == int(user_id)).first()
Example #23
Source File: main.py From big-album-art with MIT License | 5 votes |
def tick_callback(): log_info = { "user_id": current_user.id, "spotify_id": current_user.spotify_id, "timestamp": datetime.datetime.utcnow().isoformat(), "action": "tick-5m", } app.logger.info(json.dumps(log_info))
Example #24
Source File: main.py From big-album-art with MIT License | 5 votes |
def load_callback(): log_info = { "user_id": current_user.id, "spotify_id": current_user.spotify_id, "timestamp": datetime.datetime.utcnow().isoformat(), "action": "reload", } app.logger.info(json.dumps(log_info))
Example #25
Source File: main.py From big-album-art with MIT License | 5 votes |
def get_data(spotify_token): url = "https://api.spotify.com/v1/me/player/currently-playing" headers = {'Authorization': "Bearer {}".format(spotify_token)} r = requests.get(url, headers=headers) # TODO: the above can return a 204, and I'm not handling that # --> caching previous responses is a good idea? if r.status_code == 204: return { "error": "nothing_playing", "nothing_playing": True } parsed = json.loads(r.text) # check if the token is still valid if parsed.get("item", None) == None: return None img_src = parsed["item"]["album"]["images"][0]["url"] return { "img_src": img_src, "artists": list(map(lambda x: {"name": x["name"], "id": x["id"]}, parsed["item"]["artists"])), "album_name": parsed["item"]["album"]["name"], "track_name": parsed["item"]["name"], "track_ms_total": parsed["item"]["duration_ms"], "track_ms_progress": parsed["progress_ms"], "track_is_playing": parsed["is_playing"], "track_uri": parsed["item"]["uri"], }
Example #26
Source File: main.py From big-album-art with MIT License | 5 votes |
def logout(): if current_user.is_authenticated: log_info = { "user_id": current_user.id, "spotify_id": current_user.spotify_id, "timestamp": datetime.datetime.utcnow().isoformat(), "action": "logout", } app.logger.info(json.dumps(log_info)) logout_user() return redirect("/")
Example #27
Source File: views.py From Simpleblog with MIT License | 5 votes |
def edit(id): post = Post.query.get_or_404(id) if current_user != post.author and \ not current_user.operation(Permission.ADMINISTER): abort(403) form = EditpostForm() if form.validate_on_submit(): post.body = form.body.data if post.draft == True: if 'save_draft' in request.form and form.validate(): db.session.add(post) flash('保存成功!') elif 'submit' in request.form and form.validate(): post.draft = False db.session.add(post) flash('发布成功') return redirect(url_for('user.edit', id=post.id)) else: db.session.add(post) flash('更新成功。') return redirect(url_for('user.post', id=post.id)) form.title.data = post.title form.body.data = post.body return render_template('user/editpost.html', form=form, post=post, title='编辑文章') # 关注路由
Example #28
Source File: views.py From Simpleblog with MIT License | 5 votes |
def delate(id): comment = Comment.query.get_or_404(id) post_id = comment.post_id comment.disabled = True db.session.add(comment) return redirect(url_for('user.post',id=post_id)) # 编辑文章
Example #29
Source File: views.py From Simpleblog with MIT License | 5 votes |
def unlike(id): post = Post.query.get_or_404(id) if post.like_num.filter_by(liker_id=current_user.id).first() is None: flash('你还未点赞。') return redirect(url_for('user.post', id=post.id)) # like = Like(post=post, # user=current_user._get_current_object()) else: f = post.like_num.filter_by(liker_id=current_user.id).first() db.session.delete(f) flash('已取消点赞。') return redirect(url_for('user.post', id=post.id)) # 交互回复评论
Example #30
Source File: views.py From Simpleblog with MIT License | 5 votes |
def like(id): post = Post.query.get_or_404(id) if post.like_num.filter_by(liker_id=current_user.id).first() is not None: flash('你已经点赞。') return redirect(url_for('user.post', id=post.id)) like = Like(post=post, unread=True, user=current_user._get_current_object()) db.session.add(like) flash('点赞成功!') return redirect(url_for('user.post', id=post.id)) # 取消赞