72 lines
1.7 KiB
Python
Executable File
72 lines
1.7 KiB
Python
Executable File
# Calibre-Web Automated – fork of Calibre-Web
|
||
# Copyright (C) 2018-2025 Calibre-Web contributors
|
||
# Copyright (C) 2024-2025 Calibre-Web Automated contributors
|
||
# SPDX-License-Identifier: GPL-3.0-or-later
|
||
# See CONTRIBUTORS for full list of authors.
|
||
|
||
class UserMixin:
|
||
"""
|
||
This provides default implementations for the methods that Flask-Login
|
||
expects user objects to have.
|
||
"""
|
||
|
||
# Python 3 implicitly set __hash__ to None if we override __eq__
|
||
# We set it back to its default implementation
|
||
__hash__ = object.__hash__
|
||
|
||
@property
|
||
def is_active(self):
|
||
return True
|
||
|
||
@property
|
||
def is_authenticated(self):
|
||
return self.is_active
|
||
|
||
@property
|
||
def is_anonymous(self):
|
||
return False
|
||
|
||
def get_id(self):
|
||
try:
|
||
return str(self.id)
|
||
except AttributeError:
|
||
raise NotImplementedError("No `id` attribute - override `get_id`") from None
|
||
|
||
def __eq__(self, other):
|
||
"""
|
||
Checks the equality of two `UserMixin` objects using `get_id`.
|
||
"""
|
||
if isinstance(other, UserMixin):
|
||
return self.get_id() == other.get_id()
|
||
return NotImplemented
|
||
|
||
def __ne__(self, other):
|
||
"""
|
||
Checks the inequality of two `UserMixin` objects using `get_id`.
|
||
"""
|
||
equal = self.__eq__(other)
|
||
if equal is NotImplemented:
|
||
return NotImplemented
|
||
return not equal
|
||
|
||
|
||
class AnonymousUserMixin:
|
||
"""
|
||
This is the default object for representing an anonymous user.
|
||
"""
|
||
|
||
@property
|
||
def is_authenticated(self):
|
||
return False
|
||
|
||
@property
|
||
def is_active(self):
|
||
return False
|
||
|
||
@property
|
||
def is_anonymous(self):
|
||
return True
|
||
|
||
def get_id(self):
|
||
return
|