# Path: reformedacademy/models.py
# class User(AbstractUser):
#     biography = models.TextField(blank=True)
#     profile_image = models.ImageField(upload_to='profile_images', blank=True)
# 
#     def __str__(self):
#         return '{} {}'.format(self.first_name, self.last_name)
# 
#     # def progress_for_course(self, course):
#     #     """Gets the progress for a course."""
#     #     return self.courseprogress_set.filter(course=course).first()


from reformedacademy.models import User
(at your option) any later version.

Reformed Academy is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with Reformed Academy.  If not, see <http://www.gnu.org/licenses/>.

"""
# http://cramer.io/2008/08/23/logging-in-with-email-addresses-in-django/


class EmailOrUsernameModelBackend(object):
    def authenticate(self, username=None, password=None):
        if '@' in username:
            kwargs = {'email': username}
        else:
            kwargs = {'username': username}
        try:
            user = User.objects.get(**kwargs)
            if user.check_password(password):
                return user
        except User.DoesNotExist:
            return None

    def get_user(self, user_id):
        try:
            return User.objects.get(pk=user_id)

# Path: reformedacademy/models.py
# class User(AbstractUser):
#     biography = models.TextField(blank=True)
#     profile_image = models.ImageField(upload_to='profile_images', blank=True)
# 
#     def __str__(self):
#         return '{} {}'.format(self.first_name, self.last_name)
# 
#     # def progress_for_course(self, course):
#     #     """Gets the progress for a course."""
#     #     return self.courseprogress_set.filter(course=course).first()


# Path: reformedacademy/accounts/backends.py
from reformedacademy.models import User

(at your option) any later version.

Reformed Academy is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with Reformed Academy.  If not, see <http://www.gnu.org/licenses/>.

"""
# http://cramer.io/2008/08/23/logging-in-with-email-addresses-in-django/


class EmailOrUsernameModelBackend(object):
    def authenticate(self, username=None, password=None):
        if '@' in username:
            kwargs = {'email': username}
        else:
            kwargs = {'username': username}
        try:
            user = User.objects.get(**kwargs)
            if user.check_password(password):
                return user
        except User.DoesNotExist:
            return None

    def get_user(self, user_id):
        try:
            return User.objects.get(pk=user_id)

        except User.DoesNotExist: