cache query result of podcast lists only if non-empty
[mygpo.git] / mygpo / web / auth.py
blob792158df3bc15bb4b5a6aecceb7a9d518f11071a
2 # This file is part of my.gpodder.org.
4 # my.gpodder.org is free software: you can redistribute it and/or modify it
5 # under the terms of the GNU Affero General Public License as published by
6 # the Free Software Foundation, either version 3 of the License, or (at your
7 # option) any later version.
9 # my.gpodder.org is distributed in the hope that it will be useful, but
10 # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
11 # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public
12 # License for more details.
14 # You should have received a copy of the GNU Affero General Public License
15 # along with my.gpodder.org. If not, see <http://www.gnu.org/licenses/>.
18 from django.contrib.auth.backends import ModelBackend
20 from mygpo.users.models import User
22 try:
23 from django.forms.fields import email_re
24 except ImportError:
25 from django.core.validators import email_re
28 class EmailAuthenticationBackend(ModelBackend):
29 def authenticate(self, username=None, password=None):
30 if email_re.search(username):
31 user = User.get_user_by_email(username)
32 if not user:
33 return None
35 return user if user.check_password(password) else None
36 return None
38 def get_user(self, username):
39 return User.get_user(username)