Python flask_security.current_user.is_authenticated() Examples

The following are 29 code examples of flask_security.current_user.is_authenticated(). 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_security.current_user , or try the search function .
Example #1
Source File: manager.py    From crestify with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
def inject_user_tags():
    if not current_user.is_authenticated:
        return {
            "user_tags": None
        }
    else:
        user_tags = Tag.query.filter(Tag.user == current_user.id,
                                     Tag.count > 0).all()
        user_tags.sort(key=lambda k: k.text.lower())
        user_tags = [{'text': tag.text.encode('utf-8'),
                      'value': tag.text.encode('utf-8'),
                      'count': tag.count} for tag in user_tags if
                     tag.text != '']
        return {
            "user_tags": user_tags
        } 
Example #2
Source File: views.py    From SmartProxyPool with MIT License 5 votes vote down vote up
def _handle_view(self, name, **kwargs):
        if current_user.is_authenticated:
            pass
        else:
            return redirect(url_for('security.login', next=request.url)) 
Example #3
Source File: base.py    From betterlifepsi with MIT License 5 votes vote down vote up
def _handle_view(self, name, **kwargs):
        """
        Override builtin _handle_view in order to redirect users when a view is not accessible.
        """
        if not self.is_accessible():
            if current_user.is_authenticated:
                # permission denied
                abort(403)
            else:
                # login
                return redirect(url_for('security.login', next=request.url)) 
Example #4
Source File: base.py    From betterlifepsi with MIT License 5 votes vote down vote up
def can(self, operation='view'):
        obj_id = get_mdict_item_or_list(request.args, 'id') if has_request_context() else None
        obj = None if obj_id is None else self.get_one(obj_id)
        if obj is None:
            same_org = True
        else:
            if has_organization_field(obj):
                if obj.organization is None:
                    same_org = False
                else:
                    same_org = (obj.organization.id == current_user.organization.id)
            else:
                same_org = True
        role_assigned = same_org and current_user.is_authenticated and (self.role_identify + '_' + operation in get_user_roles())
        return (is_super_admin()) or (role_assigned) 
Example #5
Source File: index.py    From betterlifepsi with MIT License 5 votes vote down vote up
def index(self):
        if not current_user.is_authenticated:
            return redirect(url_for_security('login'))
        return self.render('dashboard.html') 
Example #6
Source File: activities.py    From udata with GNU Affero General Public License v3.0 5 votes vote down vote up
def on_user_updated_organization(organization):
    if current_user and current_user.is_authenticated:
        UserUpdatedOrganization.emit(organization, organization) 
Example #7
Source File: activities.py    From udata with GNU Affero General Public License v3.0 5 votes vote down vote up
def on_user_created_organization(organization):
    if current_user and current_user.is_authenticated:
        UserCreatedOrganization.emit(organization, organization) 
Example #8
Source File: activities.py    From udata with GNU Affero General Public License v3.0 5 votes vote down vote up
def on_user_deleted_reuse(reuse):
    if not reuse.private and current_user and current_user.is_authenticated:
        UserDeletedReuse.emit(reuse, reuse.organization) 
Example #9
Source File: activities.py    From udata with GNU Affero General Public License v3.0 5 votes vote down vote up
def on_user_updated_reuse(reuse):
    if not reuse.private and current_user and current_user.is_authenticated:
        UserUpdatedReuse.emit(reuse, reuse.organization) 
Example #10
Source File: activities.py    From udata with GNU Affero General Public License v3.0 5 votes vote down vote up
def on_user_created_reuse(reuse):
    if not reuse.private and current_user and current_user.is_authenticated:
        UserCreatedReuse.emit(reuse, reuse.organization) 
Example #11
Source File: activities.py    From udata with GNU Affero General Public License v3.0 5 votes vote down vote up
def write_activity_on_discuss(discussion, **kwargs):
    if current_user.is_authenticated:
        if isinstance(discussion.subject, Dataset):
            UserDiscussedDataset.emit(discussion.subject)
        elif isinstance(discussion.subject, Reuse):
            UserDiscussedReuse.emit(discussion.subject) 
Example #12
Source File: activities.py    From udata with GNU Affero General Public License v3.0 5 votes vote down vote up
def write_activity_on_follow(follow, **kwargs):
    if current_user.is_authenticated:
        if isinstance(follow.following, Dataset):
            UserFollowedDataset.emit(follow.following)
        elif isinstance(follow.following, Reuse):
            UserFollowedReuse.emit(follow.following)
        elif isinstance(follow.following, Organization):
            UserFollowedOrganization.emit(follow.following)
        elif isinstance(follow.following, User):
            UserFollowedUser.emit(follow.following) 
Example #13
Source File: views.py    From SmartProxyPool with MIT License 5 votes vote down vote up
def index(self):
        if not current_user.is_authenticated:
            return redirect(url_for('security.login'))
        return super(ProxyPoolAdminIndexView, self).index() 
Example #14
Source File: views.py    From SmartProxyPool with MIT License 5 votes vote down vote up
def is_accessible(self):
        result = None
        if not current_user.is_active or not current_user.is_authenticated:
            result = False

        if current_user.has_role('superuser'):
            result = True

        return result 
Example #15
Source File: views.py    From SmartProxyPool with MIT License 5 votes vote down vote up
def _handle_view(self, name, **kwargs):
        if current_user.is_authenticated:
            pass
        else:
            return redirect(url_for('security.login', next=request.url)) 
Example #16
Source File: views.py    From SmartProxyPool with MIT License 5 votes vote down vote up
def is_accessible(self):
        result = None
        if not current_user.is_active or not current_user.is_authenticated:
            result = False

        if current_user.has_role('superuser'):
            result = True

        return result 
Example #17
Source File: admin_model_view.py    From beavy with Mozilla Public License 2.0 5 votes vote down vote up
def is_accessible(self):
        if not current_user.is_active or not current_user.is_authenticated:
            return False

        if current_user.has_role('admin'):
            return True

        return False 
Example #18
Source File: views.py    From SmartProxyPool with MIT License 5 votes vote down vote up
def is_accessible(self):
        if not current_user.is_active or not current_user.is_authenticated:
            return False

        if current_user.has_role('superuser'):
            return True

        return False 
Example #19
Source File: map.py    From contextualise with MIT License 5 votes vote down vote up
def view(map_identifier):
    topic_store = get_topic_store()

    collaboration_mode = None
    if current_user.is_authenticated:  # User is logged in
        is_map_owner = topic_store.is_topic_map_owner(map_identifier, current_user.id)
        if is_map_owner:
            topic_map = topic_store.get_topic_map(map_identifier, current_user.id)
        else:
            topic_map = topic_store.get_topic_map(map_identifier)
        if topic_map is None:
            abort(404)
        collaboration_mode = topic_store.get_collaboration_mode(map_identifier, current_user.id)
        # The map is private and doesn't belong to the user who is trying to
        # access it
        if not topic_map.published and not is_map_owner:
            if not collaboration_mode:  # The user is not collaborating on the map
                abort(403)
    else:  # User is not logged in
        topic_map = topic_store.get_topic_map(map_identifier)
        if topic_map is None:
            abort(404)
        if not topic_map.published:  # User is not logged in and the map is not published
            abort(403)

    return render_template("map/view.html", topic_map=topic_map) 
Example #20
Source File: manager.py    From crestify with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def inject_bmark_count():
    if current_user.is_authenticated:
        bookmark_count = Bookmark.query.filter_by(user=current_user.id, deleted=False).count()
        return dict(bookmark_count=bookmark_count)
    return dict(bookmark_count=0) 
Example #21
Source File: admin.py    From spkrepo with MIT License 5 votes vote down vote up
def index(self):
        if not current_user.is_authenticated:
            return redirect(url_for("security.login"))
        if not any(map(current_user.has_role, ("developer", "package_admin", "admin"))):
            abort(403)
        return super(IndexView, self).index() 
Example #22
Source File: admin.py    From spkrepo with MIT License 5 votes vote down vote up
def is_accessible(self):
        return current_user.is_authenticated and any(
            map(current_user.has_role, ("developer", "package_admin"))
        ) 
Example #23
Source File: admin.py    From spkrepo with MIT License 5 votes vote down vote up
def is_accessible(self):
        return current_user.is_authenticated and current_user.has_role("package_admin") 
Example #24
Source File: admin.py    From spkrepo with MIT License 5 votes vote down vote up
def is_accessible(self):
        return current_user.is_authenticated and current_user.has_role("package_admin")

    # View 
Example #25
Source File: admin.py    From spkrepo with MIT License 5 votes vote down vote up
def is_accessible(self):
        return current_user.is_authenticated and current_user.has_role("package_admin") 
Example #26
Source File: admin.py    From spkrepo with MIT License 5 votes vote down vote up
def is_accessible(self):
        return current_user.is_authenticated and current_user.has_role("package_admin") 
Example #27
Source File: admin.py    From spkrepo with MIT License 5 votes vote down vote up
def is_accessible(self):
        return current_user.is_authenticated and current_user.has_role("admin") 
Example #28
Source File: admin_model_view.py    From beavy with Mozilla Public License 2.0 5 votes vote down vote up
def _handle_view(self, name, **kwargs):
        """
        Override builtin _handle_view in order to redirect users when a
        view is not accessible.
        """
        if not self.is_accessible():
            if current_user.is_authenticated:
                # permission denied
                abort(403)
            else:
                # login
                return redirect(url_for('security.login', next=request.url)) 
Example #29
Source File: note.py    From contextualise with MIT License 4 votes vote down vote up
def index(map_identifier):
    topic_store = get_topic_store()

    if current_user.is_authenticated:  # User is logged in
        is_map_owner = topic_store.is_topic_map_owner(map_identifier, current_user.id)
        if is_map_owner:
            topic_map = topic_store.get_topic_map(map_identifier, current_user.id)
        else:
            topic_map = topic_store.get_topic_map(map_identifier)
        if topic_map is None:
            abort(404)
        collaboration_mode = topic_store.get_collaboration_mode(map_identifier, current_user.id)
        # The map is private and doesn't belong to the user who is trying to
        # access it
        if not topic_map.published and not is_map_owner:
            if not collaboration_mode:  # The user is not collaborating on the map
                abort(403)
    else:  # User is not logged in
        topic_map = topic_store.get_topic_map(map_identifier)
        if topic_map is None:
            abort(404)
        if not topic_map.published:  # User is not logged in and the map is not published
            abort(403)

    topic = topic_store.get_topic(map_identifier, "notes")
    if topic is None:
        abort(404)

    note_occurrences = topic_store.get_topic_occurrences(
        map_identifier,
        "notes",
        "note",
        inline_resource_data=RetrievalMode.INLINE_RESOURCE_DATA,
        resolve_attributes=RetrievalMode.RESOLVE_ATTRIBUTES,
    )
    notes = []
    for note_occurrence in note_occurrences:
        notes.append(
            {
                "identifier": note_occurrence.identifier,
                "title": note_occurrence.get_attribute_by_name("title").value,
                "timestamp": maya.parse(note_occurrence.get_attribute_by_name("modification-timestamp").value),
                "text": mistune.html(note_occurrence.resource_data.decode()),
            }
        )

    return render_template("note/index.html", topic_map=topic_map, topic=topic, notes=notes)