-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathusers.py
46 lines (40 loc) · 1.46 KB
/
users.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import MySQLdb
import auth_funcs
from models import users
from django.contrib.auth.models import User, Group
class WordpressBackend:
"""
Authenticates against a Wordpress v3.1.4 user database using PHPass
Requires MySQLdb to be installed
"""
supports_object_permissions = False
supports_anonymous_user = False
supports_inactive_user = False
def authenticate(self, username=None, password=None):
wp = users.objects.all()
try:
wp = users.objects.get(user_login=username)
pwd_db = wp.user_pass
login_valid = True
except:
return None
pwd_valid = (pwd_db == auth_funcs.hash(password, pwd_db))
if login_valid and pwd_valid:
try:
user = User.objects.get(username=username)
except User.DoesNotExist:
# Create a new user. Note that we can set password
# to anything, because it won't be checked; the password
# from settings.py will.
user = User(username=username, password='get from wordpress')
user.is_staff = True
#user.is_superuser = True
user.save()
user.groups.add(Group.objects.get(name='inputters'))
return user
return None
def get_user(self, user_id):
try:
return User.objects.get(pk=user_id)
except User.DoesNotExist:
return None