Python flask_login.current_user.email() Examples
The following are 30
code examples of flask_login.current_user.email().
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: routes.py From thewarden with MIT License | 8 votes |
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)
Example #2
Source File: routes.py From thewarden with MIT License | 7 votes |
def login(): if current_user.is_authenticated: return redirect(url_for("main.home")) 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("login.html", title="Login", form=form)
Example #3
Source File: user_logined.py From FF.PyAdmin with BSD 3-Clause "New" or "Revised" License | 6 votes |
def user_logined_handler(sender, **data): """ 用户登录成功事件回调 e.g.:: event_user_logined.send(log_status=res) :param sender: 信号发送者/事件触发者 :param data: 由发送者传递 :return: """ # 日志 LogCharge.to_db({ 'log_status': 1 if data.pop('log_status', 0) else 0, 'log_content': request.remote_addr, }) # 邮件 if current_user.email and current_app.config.get('MAIL_OPEN') and current_app.config.get('MAIL_PASSWORD'): MailCharge( subject='登录成功提醒: {}'.format(current_app.config.get('APP_NAME')), recipients=[current_user.email], extra_headers={'X-Priority': '1'} ).html_template(**data).text_template(**data).send_mail()
Example #4
Source File: routes.py From thewarden with MIT License | 6 votes |
def account(): form = UpdateAccountForm() if form.validate_on_submit(): # Recalculate the NAV current_user.image_file = form.basefx.data current_user.email = form.email.data db.session.commit() regenerate_nav() flash( f"Account updated and NAV recalculated to use " + f"{form.basefx.data} as a base currency", "success") return redirect(url_for("users.account")) elif request.method == "GET": form.email.data = current_user.email # Check if the current value is in list of fx # If not, default to USD fx = fx_list() found = [item for item in fx if current_user.image_file in item] if found != []: form.basefx.data = current_user.image_file else: form.basefx.data = "USD" return render_template("account.html", title="Account", form=form)
Example #5
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 #6
Source File: admin.py From calibre-web with GNU General Public License v3.0 | 6 votes |
def admin(): version = updater_thread.get_current_version_info() if version is False: commit = _(u'Unknown') else: if 'datetime' in version: commit = version['datetime'] tz = timedelta(seconds=time.timezone if (time.localtime().tm_isdst == 0) else time.altzone) form_date = datetime.strptime(commit[:19], "%Y-%m-%dT%H:%M:%S") if len(commit) > 19: # check if string has timezone if commit[19] == '+': form_date -= timedelta(hours=int(commit[20:22]), minutes=int(commit[23:])) elif commit[19] == '-': form_date += timedelta(hours=int(commit[20:22]), minutes=int(commit[23:])) commit = format_datetime(form_date - tz, format='short', locale=get_locale()) else: commit = version['version'] allUser = ub.session.query(ub.User).all() email_settings = config.get_mail_settings() return render_title_template("admin.html", allUser=allUser, email=email_settings, config=config, commit=commit, title=_(u"Admin page"), page="admin")
Example #7
Source File: test_admin.py From arch-security-tracker with MIT License | 6 votes |
def test_create_user(db, client): role = UserRole.security_team resp = client.post(url_for('tracker.create_user'), follow_redirects=True, data=dict(username=USERNAME, password=PASSWORD, email=EMAIL, active=True, role=role.name)) assert resp.status_code == 200 resp = client.post(url_for('tracker.logout'), follow_redirects=True) assert_not_logged_in(resp) resp = client.post(url_for('tracker.login'), follow_redirects=True, data=dict(username=USERNAME, password=PASSWORD)) assert_logged_in(resp) assert USERNAME == current_user.name assert EMAIL == current_user.email assert role == current_user.role
Example #8
Source File: views.py From realms-wiki with GNU General Public License v2.0 | 6 votes |
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())
Example #9
Source File: views.py From scout with BSD 3-Clause "New" or "Revised" License | 6 votes |
def variant_acmg(institute_id, case_name, variant_id): """ACMG classification form.""" if request.method == "GET": data = acmg_controller(store, institute_id, case_name, variant_id) return data criteria = [] criteria_terms = request.form.getlist("criteria") for term in criteria_terms: criteria.append( dict( term=term, comment=request.form.get("comment-{}".format(term)), links=[request.form.get("link-{}".format(term))], ) ) acmg = variant_acmg_post( store, institute_id, case_name, variant_id, current_user.email, criteria ) flash("classified as: {}".format(acmg), "info") return redirect( url_for(".variant", institute_id=institute_id, case_name=case_name, variant_id=variant_id,) )
Example #10
Source File: controllers.py From scout with BSD 3-Clause "New" or "Revised" License | 6 votes |
def activate_case(store, institute_obj, case_obj, current_user): """ Activate case when visited for the first time. Args: store(adapter.MongoAdapter) institute_obj(dict) a scout institutet object case_obj(dict) a scout case object current_user(UserMixin): a scout user """ # update status of case if visited for the first time if case_obj["status"] == "inactive" and not current_user.is_admin: flash("You just activated this case!", "info") user_obj = store.user(current_user.email) case_link = url_for( "cases.case", institute_id=institute_obj["_id"], case_name=case_obj["display_name"], ) store.update_status(institute_obj, case_obj, user_obj, "active", case_link)
Example #11
Source File: views.py From scout with BSD 3-Clause "New" or "Revised" License | 6 votes |
def update_individual(institute_id, case_name): """Update individual data (age and/or Tissue type) for a case""" institute_obj, case_obj = institute_and_case(store, institute_id, case_name) user_obj = store.user(current_user.email) ind_id = request.form.get("update_ind") age = request.form.get("_".join(["age", ind_id])) tissue = request.form.get("_".join(["tissue", ind_id])) controllers.update_individuals( store=store, institute_obj=institute_obj, case_obj=case_obj, user_obj=user_obj, ind=ind_id, age=age, tissue=tissue, ) return redirect(request.referrer)
Example #12
Source File: views.py From scout with BSD 3-Clause "New" or "Revised" License | 6 votes |
def update_cancer_sample(institute_id, case_name): """Update cancer sample-associated data: tumor purity, tissue type, tumor type""" institute_obj, case_obj = institute_and_case(store, institute_id, case_name) user_obj = store.user(current_user.email) ind_id = request.form.get("update_ind") tumor_type = request.form.get(".".join(["tumor_type", ind_id])) tissue_type = request.form.get(".".join(["tissue_type", ind_id])) tumor_purity = request.form.get(".".join(["tumor_purity", ind_id])) controllers.update_cancer_samples( store=store, institute_obj=institute_obj, case_obj=case_obj, user_obj=user_obj, ind=ind_id, tissue=tissue_type, tumor_type=tumor_type, tumor_purity=tumor_purity, ) return redirect(request.referrer)
Example #13
Source File: views.py From scout with BSD 3-Clause "New" or "Revised" License | 6 votes |
def share(institute_id, case_name): """Share a case with a different institute.""" institute_obj, case_obj = institute_and_case(store, institute_id, case_name) user_obj = store.user(current_user.email) collaborator_id = request.form["collaborator"] revoke_access = "revoke" in request.form link = url_for(".case", institute_id=institute_id, case_name=case_name) try: if revoke_access: store.unshare(institute_obj, case_obj, collaborator_id, user_obj, link) else: store.share(institute_obj, case_obj, collaborator_id, user_obj, link) except ValueError as ex: flash(str(ex), "warning") return redirect(request.referrer)
Example #14
Source File: views.py From BhagavadGita with GNU General Public License v3.0 | 6 votes |
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)
Example #15
Source File: controllers.py From scout with BSD 3-Clause "New" or "Revised" License | 5 votes |
def update_clinical_filter_hpo(store, current_user, institute_id, case_name, hpo_clinical_filter): """Update HPO clinical filter use for a case.""" institute_obj, case_obj = institute_and_case(store, institute_id, case_name) user_obj = store.user(current_user.email) link = url_for("cases.case", institute_id=institute_id, case_name=case_name) store.update_clinical_filter_hpo(institute_obj, case_obj, user_obj, link, hpo_clinical_filter)
Example #16
Source File: views.py From scout with BSD 3-Clause "New" or "Revised" License | 5 votes |
def case_synopsis(institute_id, case_name): """Update (PUT) synopsis of a specific case.""" institute_obj, case_obj = institute_and_case(store, institute_id, case_name) user_obj = store.user(current_user.email) new_synopsis = request.form.get("synopsis") controllers.update_synopsis(store, institute_obj, case_obj, user_obj, new_synopsis) return redirect(request.referrer)
Example #17
Source File: forms.py From thewarden with MIT License | 5 votes |
def validate_email(self, email): user = User.query.filter_by(email=email.data).first() if user: raise ValidationError("E-mail already registered. Please Login.")
Example #18
Source File: forms.py From thewarden with MIT License | 5 votes |
def validate_email(self, email): if email.data != current_user.email: user = User.query.filter_by(email=email.data).first() if user: raise ValidationError("\ Email already exists. Use a different one.")
Example #19
Source File: views.py From scout with BSD 3-Clause "New" or "Revised" License | 5 votes |
def matchmaker_match(institute_id, case_name, target): """Starts an internal match or a match against one or all MME external nodes""" institute_obj, case_obj = institute_and_case(store, institute_id, case_name) # check that only authorized users can run matches user_obj = store.user(current_user.email) if "mme_submitter" not in user_obj["roles"]: flash("unauthorized request", "warning") return redirect(request.referrer) # Required params for sending an add request to MME: mme_base_url = current_app.config.get("MME_URL") mme_accepts = current_app.config.get("MME_ACCEPTS") mme_token = current_app.config.get("MME_TOKEN") nodes = current_app.mme_nodes if not mme_base_url or not mme_token or not mme_accepts: flash( "An error occurred reading matchmaker connection parameters. Please check config file!", "danger", ) return redirect(request.referrer) match_results = controllers.mme_match( case_obj, target, mme_base_url, mme_token, nodes, mme_accepts ) ok_responses = 0 for match_results in match_results: if match_results["status_code"] == 200: ok_responses += 1 if ok_responses: flash("Match request sent. Look for eventual matches in 'Matches' page.", "info") else: flash("An error occurred while sending match request.", "danger") return redirect(request.referrer)
Example #20
Source File: forms.py From thewarden with MIT License | 5 votes |
def validate_email(self, email): user = User.query.filter_by(email=email.data).first() if user is None: raise ValidationError("There is no account with that email." + " You must register first.")
Example #21
Source File: views.py From scout with BSD 3-Clause "New" or "Revised" License | 5 votes |
def download_verified(): """Download all verified variants for user's cases""" user_obj = store.user(current_user.email) user_institutes = user_obj.get("institutes") temp_excel_dir = os.path.join(variants_bp.static_folder, "verified_folder") os.makedirs(temp_excel_dir, exist_ok=True) written_files = controllers.verified_excel_file(store, user_institutes, temp_excel_dir) if written_files: today = datetime.datetime.now().strftime("%Y-%m-%d") # zip the files on the fly and serve the archive to the user data = io.BytesIO() with zipfile.ZipFile(data, mode="w") as z: for f_name in pathlib.Path(temp_excel_dir).iterdir(): z.write(f_name, os.path.basename(f_name)) data.seek(0) # remove temp folder with excel files in it shutil.rmtree(temp_excel_dir) return send_file( data, mimetype="application/zip", as_attachment=True, attachment_filename="_".join(["scout", "verified_variants", today]) + ".zip", cache_timeout=0, ) flash("No verified variants could be exported for user's institutes", "warning") return redirect(request.referrer)
Example #22
Source File: test_user.py From docker-cloud-flask-demo with MIT License | 5 votes |
def test_user_registration(self): # Ensure registration behaves correctlys. with self.client: response = self.client.post( '/register', data=dict(email="test@tester.com", password="testing", confirm="testing"), follow_redirects=True ) self.assertIn(b'Welcome', response.data) self.assertTrue(current_user.email == "test@tester.com") self.assertTrue(current_user.is_active()) self.assertEqual(response.status_code, 200)
Example #23
Source File: test_user.py From docker-cloud-flask-demo with MIT License | 5 votes |
def test_validate_invalid_password(self): # Ensure user can't login when the pasword is incorrect. with self.client: response = self.client.post('/login', data=dict( email='ad@min.com', password='foo_bar' ), follow_redirects=True) self.assertIn(b'Invalid email and/or password.', response.data)
Example #24
Source File: test_user.py From docker-cloud-flask-demo with MIT License | 5 votes |
def test_check_password(self): # Ensure given password is correct after unhashing. user = User.query.filter_by(email='ad@min.com').first() self.assertTrue(bcrypt.check_password_hash(user.password, 'admin_user')) self.assertFalse(bcrypt.check_password_hash(user.password, 'foobar'))
Example #25
Source File: test_user.py From docker-cloud-flask-demo with MIT License | 5 votes |
def test_get_by_id(self): # Ensure id is correct for the current/logged in user. with self.client: self.client.post('/login', data=dict( email='ad@min.com', password='admin_user' ), follow_redirects=True) self.assertTrue(current_user.id == 1)
Example #26
Source File: test_user.py From docker-cloud-flask-demo with MIT License | 5 votes |
def test_validate_invalid_email_format(self): # Ensure invalid email format throws error. form = LoginForm(email='unknown', password='example') self.assertFalse(form.validate())
Example #27
Source File: web.py From calibre-web with GNU General Public License v3.0 | 5 votes |
def get_tasks_status(): # if current user admin, show all email, otherwise only own emails tasks = worker.get_taskstatus() answer = render_task_status(tasks) return render_title_template('tasks.html', entries=answer, title=_(u"Tasks"), page="tasks")
Example #28
Source File: test_user.py From docker-cloud-flask-demo with MIT License | 5 votes |
def test_logout_behaves_correctly(self): # Ensure logout behaves correctly - regarding the session. with self.client: self.client.post( '/login', data=dict(email="ad@min.com", password="admin_user"), follow_redirects=True ) response = self.client.get('/logout', follow_redirects=True) self.assertIn(b'You were logged out. Bye!', response.data) self.assertFalse(current_user.is_active)
Example #29
Source File: test_user.py From docker-cloud-flask-demo with MIT License | 5 votes |
def test_correct_login(self): # Ensure login behaves correctly with correct credentials. with self.client: response = self.client.post( '/login', data=dict(email="ad@min.com", password="admin_user"), follow_redirects=True ) self.assertIn(b'Welcome', response.data) self.assertIn(b'Logout', response.data) self.assertIn(b'Members', response.data) self.assertTrue(current_user.email == "ad@min.com") self.assertTrue(current_user.is_active()) self.assertEqual(response.status_code, 200)
Example #30
Source File: views.py From scout with BSD 3-Clause "New" or "Revised" License | 5 votes |
def events(institute_id, case_name, event_id=None): """Handle events.""" institute_obj, case_obj = institute_and_case(store, institute_id, case_name) link = request.form.get("link") content = request.form.get("content") variant_id = request.args.get("variant_id") user_obj = store.user(current_user.email) if event_id: # delete the event store.delete_event(event_id) else: if variant_id: # create a variant comment variant_obj = store.variant(variant_id) level = request.form.get("level", "specific") store.comment( institute_obj, case_obj, user_obj, link, variant=variant_obj, content=content, comment_level=level, ) else: # create a case comment store.comment(institute_obj, case_obj, user_obj, link, content=content) return redirect(request.referrer)