This repository has been archived by the owner on Feb 24, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
waauth.py
108 lines (96 loc) · 3.72 KB
/
waauth.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
### waauth.py --- User authentication
## Copyright (C) 2005, 2006 Brailcom, o.p.s.
##
## Author: Milan Zamazal <pdm@brailcom.org>
##
## COPYRIGHT NOTICE
##
## This program is free software; you can redistribute it and/or modify it
## under the terms of the GNU General Public License as published by the Free
## Software Foundation; either version 2 of the License, or (at your option)
## any later version.
##
## This program 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
## this program; if not, write to the Free Software Foundation, Inc.,
## 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
import roundup.instance
if False:
import os
def _global_user_name (tracker_home):
tracker = roundup.instance.open (tracker_home)
client = tracker.Client (tracker, None, os.environ)
client.determine_user ()
return client.user
def _validate_login (project, login, password, tracker_home):
tracker = roundup.instance.open (tracker_home)
db = tracker.open ()
try:
project_id = db.project.lookup (project)
except KeyError:
return False
for login_id in db.login.find (project=project_id):
if db.login.get (login_id, 'login') == login:
user_id = db.login.get (login_id, 'user')
db_password = db.user.get (user_id, 'password')
if password == db_password or password == str (db_password):
return True
else:
return False
return False
def authenticate (project, requested_user_name, password, tracker_home):
if requested_user_name == 'anonymous':
return True
return _validate_login (project, requested_user_name, password, tracker_home)
def _modify_user (project, login, user, tracker_home, action):
tracker = roundup.instance.open (tracker_home)
db = tracker.open ()
try:
project_id = db.project.lookup (project)
except KeyError:
return "No such project: %s" % (project,)
try:
user_id = db.user.lookup (user)
except KeyError:
return "No user `%s'" % (user,)
db.setCurrentUser ('admin')
action (db, project_id, user_id, login)
db.commit ()
return None
def add_user (project, login, user, tracker_home):
def action (db, project_id, user_id, login):
db.login.create (project=project_id, user=user_id, login=login)
return _modify_user (project, login, user, tracker_home, action)
def _user_id (user, tracker_home):
tracker = roundup.instance.open (tracker_home)
db = tracker.open ()
try:
user_id = db.user.lookup (user)
except KeyError:
return None, None
return user_id, db
def check_user (user, tracker_home):
return _user_id (user, tracker_home)[0] and True or False
def user_data (user, tracker_home):
id, db = _user_id (user, tracker_home)
data = {}
user = db.user
if id:
for property in 'address', 'realname', 'phone', 'organisation', 'alternate_addresses',:
value = user.get (id, property)
if value:
data[property] = value
return data
def remove_user (project, login, user, tracker_home):
def action (db, project_id, user_id, login):
for id in db.login.find (user=user_id, project=project_id):
if db.login.get (id, 'login') == login:
db.login.retire (id)
break
else:
return "No corresponding login entry found"
return _modify_user (project, login, user, tracker_home, action)