# -----------------------------------------------------------------------
import re, md5
+from osrf.ses import osrfAtomicRequest
+from osrf.log import *
-# -----------------------------------------------------------------------
-# Grab-bag of general utility functions
-# -----------------------------------------------------------------------
-
# -----------------------------------------------------------------------
-# more succinct search/replace call
+# Grab-bag of general utility functions
# -----------------------------------------------------------------------
-def replace(str, pattern, replace):
- return re.compile(pattern).sub(replace, str)
-
def isEvent(evt):
return (evt and isinstance(evt, dict) and evt.get('ilsevent') != None)
o[x] = 1
return o.keys()
+
+def login(username, password, type=None, workstation=None):
+ ''' Login to the server and get back an authtoken'''
+
+ osrfLogInfo("attempting login with user " + username)
+
+ seed = osrfAtomicRequest(
+ 'open-ils.auth',
+ 'open-ils.auth.authenticate.init', username)
+
+ # generate the hashed password
+ password = md5sum(seed + md5sum(password))
+
+ return osrfAtomicRequest(
+ 'open-ils.auth',
+ 'open-ils.auth.authenticate.complete',
+ { 'workstation' : workstation,
+ 'username' : username,
+ 'password' : password,
+ 'type' : type
+ }
+ )
+