From: drizea Date: Tue, 5 Jun 2012 21:06:37 +0000 (+0300) Subject: OPAC my account summary retrieve function added X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=590acc8574823fd1deababd13798aa35f009d76c;p=working%2FEvergreen.git OPAC my account summary retrieve function added --- diff --git a/Open-ILS/src/Android/src/org/evergreen/android/accountAccess/AccountAccess.java b/Open-ILS/src/Android/src/org/evergreen/android/accountAccess/AccountAccess.java new file mode 100644 index 0000000000..ba0ca39e9f --- /dev/null +++ b/Open-ILS/src/Android/src/org/evergreen/android/accountAccess/AccountAccess.java @@ -0,0 +1,221 @@ + +package org.evergreen.android.accountAccess; + +import java.security.MessageDigest; +import java.security.NoSuchAlgorithmException; +import java.util.HashMap; +import java.util.Map; + +import org.opensrf.Method; +import org.opensrf.net.http.GatewayRequest; +import org.opensrf.net.http.HttpConnection; +import org.opensrf.net.http.HttpRequest; + +/** + * The Class AuthenticateUser. + */ +public class AccountAccess { + + /** The SERVICE. */ + public static String SERVICE = "open-ils.auth"; + + /** The METHOD Auth init */ + public static String METHOD_AUTH_INIT = "open-ils.auth.authenticate.init"; + + /** The METHOD Auth complete */ + public static String METHOD_AUTH_COMPLETE = "open-ils.auth.authenticate.complete"; + + /** The METHOD Auth session retrieve */ + public static String METHOD_AUTH_SESSION_RETRV = "open-ils.auth.session.retrieve"; + + /** The conn. */ + public HttpConnection conn; + + /** The http address. */ + public String httpAddress = "http://ulysses.calvin.edu"; + + /** The TAG. */ + public String TAG = "AuthenticareUser"; + + /** The auth token. + * Sent with every request that needs authentication + * */ + private String authToken = null; + + private Integer authTime = null; + + //for demo purpose + /** The user name. */ + private String userName = "staff"; + + /** The password. */ + private String password = "demo123"; + + /** + * Instantiates a new authenticate user. + * + * @param httpAddress the http address + */ + public AccountAccess(String httpAddress) { + + this.httpAddress = httpAddress; + + try { + // configure the connection + + System.out.println("Connection with " + httpAddress); + conn = new HttpConnection(httpAddress + "/osrf-gateway-v1"); + + } catch (Exception e) { + System.err.println("Exception in establishing connection " + + e.getMessage()); + } + + } + + /** + * Md5. + * + * @param s the s + * @return the string + */ + private String md5(String s) { + try { + // Create MD5 Hash + MessageDigest digest = java.security.MessageDigest.getInstance("MD5"); + digest.update(s.getBytes()); + byte messageDigest[] = digest.digest(); + + // Create Hex String + StringBuffer hexString = new StringBuffer(); + for (int i=0; i complexParam = new HashMap(); + + + complexParam.put("username", userName); + complexParam.put("password", hash); + + + method.addParam(complexParam); + System.out.println("Compelx param " + complexParam); + + // sync test + HttpRequest req = new GatewayRequest(conn, SERVICE, method).send(); + Object resp; + + + while ((resp = req.recv()) != null) { + System.out.println("Sync Response: " + resp); + + String queryResult = ((Map) resp).get("textcode"); + + System.out.println("Result " + queryResult); + + if(queryResult.equals("SUCCESS")){ + Object payload = ((Map) resp).get("payload"); + authToken = ((Map)payload).get("authtoken"); + try{ + System.out.println(((Map)payload).get("authtoken")); + authTime = ((Map)payload).get("authtime"); + + }catch(Exception e){ + System.err.println("Error in parsing authtime " + e.getMessage()); + } + System.out.println(); + } + } + + + } + + + +}