summaryrefslogtreecommitdiffstats
path: root/src/lib/Bcfg2/Server/Hostbase/backends.py
blob: cfa9e1e16145565ac768f5310ad8e89a736e13e3 (plain)
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
from django.contrib.auth.models import User
#from ldapauth import *
from nisauth import *

## class LDAPBackend(object):

##     def authenticate(self,username=None,password=None):
##         try:

##             l = ldapauth(username,password)
##             temp_pass = User.objects.make_random_password(100)
##             ldap_user = dict(username=l.sAMAccountName,
##                              )
##             user_session_obj = dict(
##                 email=l.email,
##                 first_name=l.name_f,
##                 last_name=l.name_l,
##                 uid=l.badge_no
##                 )
##             #fixme: need to add this user session obj to session
##             user,created = User.objects.get_or_create(username=username)
##             return user

##         except LDAPAUTHError,e:
##             return None

##     def get_user(self,user_id):
##         try:
##             return User.objects.get(pk=user_id)
##         except User.DoesNotExist, e:
##             return None


class NISBackend(object):

    def authenticate(self, username=None, password=None):
        try:
            n = nisauth(username, password)
            temp_pass = User.objects.make_random_password(100)
            nis_user = dict(username=username,
                            )

            user_session_obj = dict(
                email = username + "@mcs.anl.gov",
                first_name = None,
                last_name = None,
                uid = n.uid
                )
            user, created = User.objects.get_or_create(username=username)

            return user

        except NISAUTHError:
            e = sys.exc_info()[1]
            return None


    def get_user(self, user_id):
        try:
            return User.objects.get(pk=user_id)
        except User.DoesNotExist:
            e = sys.exc_info()[1]
            return None