added a login method
authorerickson <erickson@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Sun, 16 Sep 2007 17:43:09 +0000 (17:43 +0000)
committererickson <erickson@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Sun, 16 Sep 2007 17:43:09 +0000 (17:43 +0000)
git-svn-id: svn://svn.open-ils.org/ILS/trunk@7792 dcc99617-32d9-48b4-a31d-7c20da2025e4

Open-ILS/src/python/oils/utils/utils.py

index 47df3f7..42d6e89 100644 (file)
 # -----------------------------------------------------------------------
 
 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)
@@ -54,3 +49,26 @@ def unique(arr):
         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
+        }
+    )
+