Python flask.ext.login.current_user.is_anonymous() Examples

The following are 10 code examples of flask.ext.login.current_user.is_anonymous(). 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.ext.login.current_user , or try the search function .
Example #1
Source File: user.py    From cve-portal with GNU Affero General Public License v3.0 6 votes vote down vote up
def password_reset_request():
    if not current_user.is_anonymous():
        return redirect(url_for('main.index'))
    form = form_class.PasswordResetRequestForm()
    if form.validate_on_submit():
        user = models.User.query.filter_by(email=form.email.data).first()
        if user:
            token = user.generate_reset_token()
            send_email(user.email,
                       'CVE-PORTAL -- Reset Password Request',
                       '/emails/password_reset',
                       user=user,
                       token=token,
                       next=request.args.get('next'))
            # syslog.syslog(syslog.LOG_WARNING, "User password reset request is asked: " + current_user.email)
            flash('An email with instructions to reset your password has been sent to you.', 'info')
            return redirect(url_for('user.login'))
    return render_template('auth/reset_password.html', form=form) 
Example #2
Source File: permissions.py    From build-relengapi with Mozilla Public License 2.0 6 votes vote down vote up
def require(*permissions):
        """
        Wrap a view function, verifying that the user hsa all of the specified
        permissions.
        """
        assert permissions, "Must specify at least one permission"
        for perm in permissions:
            if not perm.exists():
                raise RuntimeError(
                    "Cannot require undocumented permission %s" % (perm,))

        @wrapt.decorator
        def req(wrapped, instance, args, kwargs):
            if not can(*permissions):
                # redirect browsers when the user is not logged in, but
                # just return 403 to REST clients
                if util.is_browser() and current_user.is_anonymous:
                    return current_app.login_manager.unauthorized()
                else:
                    abort(403)
            return wrapped(*args, **kwargs)
        return req 
Example #3
Source File: user.py    From cve-portal with GNU Affero General Public License v3.0 5 votes vote down vote up
def register():
    if not current_user.is_anonymous:
        return redirect(url_for('main.index'))

    form = form_class.RegistrationForm()
    if form.validate_on_submit():
        ki = gpg.import_keys(form.pgp.data)
        if not ki.fingerprints:
            fingerp = "--- NO VALID PGP ---"
        else:
            fingerp = ki.fingerprints[0]
        user = models.User(email=escape(form.email.data),
                           name=escape(form.name.data),
                           affiliation=escape(form.affiliation.data),
                           pgp=escape(form.pgp.data),
                           password=form.password.data,
                           fingerprint=fingerp)
        models.db.session.add(user)
        models.db.session.commit()
        syslog.syslog(syslog.LOG_NOTICE, "New user registered: " + form.email.data)
        token = user.generate_confirmation_token()
        send_email(user.email,
                   'CVE-PORTAL -- Account Confirmation',
                   '/emails/confirm',
                   user=user,
                   token=token)
        flash('A confirmation email has been sent to you by email.', 'info')
        return redirect('/login')
    else:
        if form.email.data is not None:
            pass
            # syslog.syslog(syslog.LOG_ERR, "Registering Failed: Email: " + form.email.data + " Name: " + form.name.data + " Affiliation: " + form.affiliation.data)

    return render_template("auth/register.html", form=form) 
Example #4
Source File: user.py    From cve-portal with GNU Affero General Public License v3.0 5 votes vote down vote up
def confirm(token):
    if not current_user.is_anonymous():
        if current_user.confirmed:
            return redirect(url_for('main.index'))
    else:
        if current_user.confirm(token):
            # syslog.syslog(syslog.LOG_INFO, "User Confirmed Account: " + current_user.email)
            flash('You have confirmed your account. Thanks!', 'success')
        else:
            # syslog.syslog(syslog.LOG_ERR, "User Confirmed Failed invalid/expired link: " + current_user.email)
            flash('The confirmation link is invalid or has expired.', 'warning')
        return redirect(url_for('main.index')) 
Example #5
Source File: user.py    From cve-portal with GNU Affero General Public License v3.0 5 votes vote down vote up
def unconfirmed():
    if current_user.is_anonymous() or current_user.confirmed:
        return redirect(url_for('main.index'))
    return render_template('auth/unconfirmed.html') 
Example #6
Source File: user.py    From cve-portal with GNU Affero General Public License v3.0 5 votes vote down vote up
def password_reset(token):
    if not current_user.is_anonymous():
        return redirect(url_for('main.index'))
    form = form_class.PasswordResetForm()
    if form.validate_on_submit():
        user = models.User.query.filter_by(email=form.email.data).first()
        if user is None:
            return redirect(url_for('main.index'))
        if user.reset_password(token, form.password.data):
            flash('Your password has been updated.', 'success')
            return redirect(url_for('user.login'))
        else:
            return redirect(url_for('main.index'))
    return render_template('auth/reset_password.html', form=form) 
Example #7
Source File: __init__.py    From OctoPrint-Pushbullet with GNU Affero General Public License v3.0 5 votes vote down vote up
def on_settings_load(self):
		data = octoprint.plugin.SettingsPlugin.on_settings_load(self)

		# only return our restricted settings to admin users - this is only needed for OctoPrint <= 1.2.16
		restricted = ("access_token", "push_channel")
		for r in restricted:
			if r in data and (current_user is None or current_user.is_anonymous() or not current_user.is_admin()):
				data[r] = None

		return data 
Example #8
Source File: views.py    From WatchPeopleCode with MIT License 5 votes vote down vote up
def _subscribe_to_streamer():
    if ('email' not in request.form and not current_user.is_authenticated()) or\
            'streamer_id' not in request.form:
        abort(400)
    streamer_id = request.form['streamer_id']
    if current_user.is_anonymous() or not current_user.as_subscriber:
        email = request.form['email']
    else:
        email = current_user.as_subscriber.email

    streamer = Streamer.query.get_or_404(streamer_id)

    subscriber = get_or_create(Subscriber, email=email)
    if current_user.is_authenticated():
        current_user.as_subscriber = subscriber

    if request.method == "PUT":
        if subscriber not in streamer.subscribers:
            streamer.subscribers.append(subscriber)
    else:
        if subscriber in streamer.subscribers:
            streamer.subscribers.remove(subscriber)

    db.session.commit()
    response = app.make_response(jsonify(result="OK"))
    response.set_cookie("email", value=email)
    return response 
Example #9
Source File: views.py    From WatchPeopleCode with MIT License 5 votes vote down vote up
def chat_message(message_text, streamer_username):
    streamer = check_chat_access_and_get_streamer(streamer_username)
    if len(message_text) > 2048:
        message_text = u"{}... <message is too big>".format(message_text[:2048])
    message = {"sender": session['username'],
               "text": nl2br_py(message_text)}
    if current_user.is_anonymous() and\
            streamer.streams.filter_by(type='wpc_stream').one().chat_anon_forbidden:
        emit("forbidden")
    elif current_user.is_authenticated() and current_user.is_banned:
        emit("message", message)
    else:
        if message_text.startswith("/clear"):
            if current_user.is_authenticated() and current_user.reddit_username == streamer.reddit_username:
                emit("clear", room=streamer.reddit_username)  # Clear for all viewers
                clear_message = ChatMessage(streamer=streamer, text="/clear", sender=session["username"])
                db.session.add(clear_message)
                db.session.commit()
            else:
                emit("clear")  # Clear for one user
        else:
            # Normal chat message
            cm = ChatMessage(streamer=streamer, text=message_text, sender=session['username'])
            db.session.add(cm)
            db.session.commit()
            emit("message", message, room=streamer.reddit_username)
    db.session.close()
    return True 
Example #10
Source File: __init__.py    From OctoPrint-EmailNotifier with GNU Affero General Public License v3.0 5 votes vote down vote up
def on_settings_load(self):
		data = octoprint.plugin.SettingsPlugin.on_settings_load(self)

		# only return our restricted settings to admin users - this is only needed for OctoPrint <= 1.2.16
		restricted = ("mail_server", "mail_port", "mail_tls", "mail_ssl","mail_username", "recipient_address", "mail_useralias")
		for r in restricted:
			if r in data and (current_user is None or current_user.is_anonymous() or not current_user.is_admin()):
				data[r] = None

		return data