def verify(token, org_slug=None): try: user_id = validate_token(token) org = current_org._get_current_object() user = models.User.get_by_id_and_org(user_id, org) except (BadSignature, NoResultFound): logger.exception( "Failed to verify email verification token: %s, org=%s", token, org_slug ) return ( render_template( "error.html", error_message="Your verification link is invalid. Please ask for a new one.", ), 400, ) user.is_email_verified = True models.db.session.add(user) models.db.session.commit() template_context = {"org_slug": org_slug} if settings.MULTI_ORG else {} next_url = url_for("redash.index", **template_context) return render_template("verify.html", next_url=next_url)
def render_token_login_page(template, org_slug, token): try: user_id = validate_token(token) org = current_org._get_current_object() user = models.User.get_by_id_and_org(user_id, org) except NoResultFound: logger.exception("Bad user id in token. Token= , User id= %s, Org=%s", user_id, token, org_slug) return render_template("error.html", error_message="Invalid invite link. Please ask for a new one."), 400 except (SignatureExpired, BadSignature): logger.exception("Failed to verify invite token: %s, org=%s", token, org_slug) return render_template("error.html", error_message="Your invite link has expired. Please ask for a new one."), 400 status_code = 200 if request.method == 'POST': if 'password' not in request.form: flash('Bad Request') status_code = 400 elif not request.form['password']: flash('Cannot use empty password.') status_code = 400 elif len(request.form['password']) < 6: flash('Password length is too short (<6).') status_code = 400 else: # TODO: set active flag user.hash_password(request.form['password']) models.db.session.add(user) login_user(user) models.db.session.commit() return redirect(url_for('redash.index', org_slug=org_slug)) if settings.GOOGLE_OAUTH_ENABLED: google_auth_url = get_google_auth_url(url_for('redash.index', org_slug=org_slug)) else: google_auth_url = '' return render_template(template, google_auth_url=google_auth_url, user=user), status_code
def render_token_login_page(template, org_slug, token, invite): try: user_id = validate_token(token) org = current_org._get_current_object() user = models.User.get_by_id_and_org(user_id, org) except NoResultFound: logger.exception("Bad user id in token. Token= , User id= %s, Org=%s", user_id, token, org_slug) return render_template( "error.html", error_message="Invalid invite link. Please ask for a new one." ), 400 except (SignatureExpired, BadSignature): logger.exception("Failed to verify invite token: %s, org=%s", token, org_slug) return render_template( "error.html", error_message= "Your invite link has expired. Please ask for a new one."), 400 if invite and user.details.get('is_invitation_pending') is False: return render_template( "error.html", error_message=("This invitation has already been accepted. " "Please try resetting your password instead.")), 400 status_code = 200 if request.method == 'POST': if 'password' not in request.form: flash('Bad Request') status_code = 400 elif not request.form['password']: flash('Cannot use empty password.') status_code = 400 elif len(request.form['password']) < 6: flash('Password length is too short (<6).') status_code = 400 else: if invite: user.is_invitation_pending = False user.hash_password(request.form['password']) models.db.session.add(user) login_user(user) models.db.session.commit() return redirect(url_for('redash.index', org_slug=org_slug)) google_auth_url = get_google_auth_url( url_for('redash.index', org_slug=org_slug)) return render_template( template, show_google_openid=settings.GOOGLE_OAUTH_ENABLED, google_auth_url=google_auth_url, show_saml_login=current_org.get_setting('auth_saml_enabled'), show_remote_user_login=settings.REMOTE_USER_LOGIN_ENABLED, show_ldap_login=settings.LDAP_LOGIN_ENABLED, org_slug=org_slug, user=user), status_code
def verify(token, org_slug=None): try: user_id = validate_token(token) org = current_org._get_current_object() user = models.User.get_by_id_and_org(user_id, org) except (BadSignature, NoResultFound): logger.exception("Failed to verify email verification token: %s, org=%s", token, org_slug) return render_template("error.html", error_message="Your verification link is invalid. Please ask for a new one."), 400 user.is_email_verified = True models.db.session.add(user) models.db.session.commit() return render_template("verify.html", org_slug=org_slug)
def render_token_login_page(template, org_slug, token, invite=True): try: user_id = validate_token(token) org = current_org._get_current_object() user = models.User.get_by_id_and_org(user_id, org) except NoResultFound: logger.exception("Bad user id in token. Token= , User id= %s, Org=%s", user_id, token, org_slug) return render_template("error.html", error_message="Invalid invite link. Please ask for a new one."), 400 except (SignatureExpired, BadSignature): logger.exception("Failed to verify invite token: %s, org=%s", token, org_slug) return render_template("error.html", error_message="Your invite link has expired. Please ask for a new one."), 400 if invite and user.details.get('is_invitation_pending') is False: return render_template("error.html", error_message=("This invitation has already been accepted. " "Please try resetting your password instead.")), 400 status_code = 200 if request.method == 'POST': if 'password' not in request.form: flash('Bad Request') status_code = 400 elif not request.form['password']: flash('Cannot use empty password.') status_code = 400 elif len(request.form['password']) < 6: flash('Password length is too short (<6).') status_code = 400 else: if invite: user.is_invitation_pending = False user.hash_password(request.form['password']) models.db.session.add(user) login_user(user) models.db.session.commit() return redirect(url_for('redash.index', org_slug=org_slug)) google_auth_url = get_google_auth_url(url_for('redash.index', org_slug=org_slug)) return render_template(template, show_google_openid=settings.GOOGLE_OAUTH_ENABLED, google_auth_url=google_auth_url, show_saml_login=current_org.get_setting('auth_saml_enabled'), show_remote_user_login=settings.REMOTE_USER_LOGIN_ENABLED, show_ldap_login=settings.LDAP_LOGIN_ENABLED, org_slug=org_slug, user=user), status_code
def verify(token, org_slug=None): try: user_id = validate_token(token) org = current_org._get_current_object() user = models.User.get_by_id_and_org(user_id, org) except (BadSignature, NoResultFound): logger.exception("Failed to verify email verification token: %s, org=%s", token, org_slug) return render_template("error.html", error_message="Your verification link is invalid. Please ask for a new one."), 400 user.is_email_verified = True models.db.session.add(user) models.db.session.commit() template_context = { "org_slug": org_slug } if settings.MULTI_ORG else {} next_url = url_for('redash.index', **template_context) return render_template("verify.html", next_url=next_url)