2 Grab-bag of general utility functions
5 # -----------------------------------------------------------------------
6 # Copyright (C) 2007 Georgia Public Library Service
7 # Bill Erickson <billserickson@gmail.com>
9 # This program is free software; you can redistribute it and/or
10 # modify it under the terms of the GNU General Public License
11 # as published by the Free Software Foundation; either version 2
12 # of the License, or (at your option) any later version.
14 # This program is distributed in the hope that it will be useful,
15 # but WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 # GNU General Public License for more details.
18 # -----------------------------------------------------------------------
21 import osrf.log, osrf.ses
25 Return an MD5 message digest for a given input string
30 return md5.hexdigest()
34 Unique-ify a list. only works if list items are hashable
44 Returns PostgreSQL's definition of "truth" for the supplied data, roughly.
47 if not data or data == 'f' or str(data) == '0':
51 def login(username, password, login_type=None, workstation=None):
53 Login to the server and get back an authentication token
55 @param username: user name
56 @param password: password
57 @param login_type: one of 'opac', 'temp', or 'staff' (default: 'staff')
58 @param workstation: name of the workstation to associate with this login
61 @return: a string containing an authentication token to pass as
62 a required parameter of many OpenSRF service calls
65 osrf.log.log_info("attempting login with user " + username)
67 seed = osrf.ses.ClientSession.atomic_request(
69 'open-ils.auth.authenticate.init', username)
71 # generate the hashed password
72 password = md5sum(seed + md5sum(password))
74 return osrf.ses.ClientSession.atomic_request(
76 'open-ils.auth.authenticate.complete',
77 { 'workstation' : workstation,
78 'username' : username,
79 'password' : password,